This repository was archived by the owner on May 30, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
68 lines (51 loc) · 1.5 KB
/
Copy pathmain.cpp
File metadata and controls
68 lines (51 loc) · 1.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#include <iostream>
#include <string>
#include "colormod.h" // ANSI terminal colors hellper class
#include "shell.h" // actuall shell implementation
/**
@brief Global variables:
*/
std::string whoami = shell::exec("whoami");
std::string hostname = shell::exec("hostname");
/**
@brief Main loop: get input, parse, execute.
*/
void main_loop(){
//clean whoami and hostname strings
if (!whoami.empty() && whoami[whoami.length()-1] == '\n') {
whoami.erase(whoami.length()-1);
}
if (!hostname.empty() && hostname[hostname.length()-1] == '\n') {
hostname.erase(hostname.length()-1);
}
std::string line;
std::string args;
int status;
do {
std::string pwd = shell::exec("pwd");
//clean pwd string
if (!pwd.empty() && pwd[pwd.length()-1] == '\n') {
pwd.erase(pwd.length()-1);
}
std::cout << Color::FG_RED << whoami << "@" << hostname << ":" << Color::FG_DEFAULT
<< Color::FG_BLUE << pwd << Color::FG_DEFAULT << "$ ";
std::getline(std::cin, line);
status = shell::parse(line);
line.clear();
args.clear();
} while (status);
}
/**
@brief Main entry point.
@param argc Argument count.
@param argv Argument vector.
@return status code
*/
int main(int argc, char **argv)
{
/// \todo Handle sh scripts as cmd arg
/// \todo setup/config
main_loop();
/// \todo shutdown/cleanup.
return EXIT_SUCCESS;
}