X-Git-Url: https://git.armaanb.net/?p=gen-shell.git;a=blobdiff_plain;f=src%2Fmain.cpp;h=3d0e2c65d6d3c9e5fed8eadc22a129743b3f9328;hp=1e8f1d2496742a2a8b2bc9919d4a8d40e0e58b7c;hb=23462855da29a6a5cde4110e7dc339d96fa36e45;hpb=79e7db5ed279548bc4b862cd402807ff0e7d8209 diff --git a/src/main.cpp b/src/main.cpp index 1e8f1d2..3d0e2c6 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -26,6 +26,8 @@ #include #include +#include +#include #include <../Sarge/src/sarge.h> #include @@ -39,19 +41,49 @@ using namespace std; std::string promptCompose(); +static std::vector contexts; +std::string composeContexts (bool pretty = false); + +int promptClear () +{ + contexts.clear (); + return 0; +} + +int promptRemove () +{ + if (contexts.size ()) + contexts.pop_back (); + + return 0; +} + +int promptAdd (const std::string& context) +{ + contexts.push_back (context); + return 0; +} + +std::string promptCompose () +{ + return "% "; +} + +//////////////////////////////////////////////////////////////////////////////// + const std::string getResponse(const std::string & prompt) { std::string response { "" }; - // Display prompt, get input. + // Display prompt, get input #ifdef HAVE_READLINE char * line_read = readline(prompt.c_str()); if (!line_read) { std::cout << "\n"; response = ""; } else { - // Save history. + // Save history if ( * line_read) add_history(line_read); @@ -99,15 +131,15 @@ int main(int argc, char** argv) // Main program while (true) { - // Compose the prompt. + // Compose the prompt auto prompt = promptCompose(); - // Display prompt, get input. + // Display prompt, get input auto command = getResponse(prompt); if (command != "") { - // Dispatch command. + // Dispatch command if (command == "") { return 0;