1 #include "Headers/opsys.h"
3 bool is_verbose
= false;
4 bool cwd_changed
= false;
6 CLIInputs::CLIInputs(int argc
, char **argv
)
10 for(short unsigned int i
= 1; i
< argc
; i
++)
12 string s_argv
= argv
[i
];
13 if (!s_argv
.compare("-h") || !s_argv
.compare("--help"))
15 printf("%-20s\tObtain help.\n", "-h, --help");
16 printf("%-20s\tShows additional execution data.\n", "-v, --verbose");
19 if (!s_argv
.compare("-v") || !s_argv
.compare("--verbose"))
21 printf("Executing in verbose mode.\n");
28 void Prompt::get_last_dir()
30 string last_dir
= OS
.cwd
;
31 string home_dir
= getenv("HOME");
32 last_dir
= std::regex_replace(last_dir
, std::regex(home_dir
), "~"); // Change HOME to ~ on the prompt line.
33 this->last_dir
= last_dir
;
34 cout
<< "PROMPT " << last_dir
<< '\n';
49 cout
<< BLUE_ANSI
<< OS
.username
<< "@" << OS
.hostname
<< ":" << RED_ANSI
<< last_dir
<< BLUE_ANSI
<< "$ " << RESET_ANSI
;
52 void Prompt::parse(string input
)
56 istringstream
iss (input
);
57 copy(istream_iterator
<string
>(iss
), istream_iterator
<string
>(), back_inserter(tokens
));
58 for(unsigned short int i
= 0; i
< tokens
.size(); i
++)
59 cout
<< tokens
[i
] << ' ';
63 short int Prompt::run()
65 if(!tokens
[0].compare("cd"))
67 OS
.change_dir(tokens
);
69 } else if (!tokens
[0].compare("pwd"))
71 cout
<< OS
.cwd
<< '\n';
73 } else if (!tokens
[0].compare("help"))
75 cout
<< "Insert help text here.\n";