X-Git-Url: https://git.ucc.asn.au/?a=blobdiff_plain;f=Usermode%2FApplications%2FCLIShell_src%2Fmain.c;h=d6c40d65a4db47e3ffb24e7c8a680bf73839d4ac;hb=a8067bafb36f98612767060db856cd6bf36ef940;hp=ec83ac963c13316c12682dfce6c223becc05d6e2;hpb=ab47641a5334988563520c66f5097dd6d687ea48;p=tpg%2Facess2.git diff --git a/Usermode/Applications/CLIShell_src/main.c b/Usermode/Applications/CLIShell_src/main.c index ec83ac96..d6c40d65 100644 --- a/Usermode/Applications/CLIShell_src/main.c +++ b/Usermode/Applications/CLIShell_src/main.c @@ -17,18 +17,17 @@ void Parse_Args(char *str, char **dest); void CallCommand(char **Args); void Command_Logout(int argc, char **argv); void Command_Clear(int argc, char **argv); -void Command_Colour(int argc, char **argv); +void Command_Help(int argc, char **argv); void Command_Cd(int argc, char **argv); void Command_Dir(int argc, char **argv); // ==== CONSTANT GLOBALS ==== -char *cCOLOUR_NAMES[8] = {"black", "red", "green", "yellow", "blue", "magenta", "cyan", "white"}; struct { char *name; void (*fcn)(int argc, char **argv); } cBUILTINS[] = { {"exit", Command_Logout}, {"logout", Command_Logout}, - {"colour", Command_Colour}, {"clear", Command_Clear}, + {"help", Command_Help}, {"clear", Command_Clear}, {"cd", Command_Cd}, {"dir", Command_Dir} }; static char *cDEFAULT_PATH[] = {"/Acess/Bin"}; @@ -48,7 +47,7 @@ char **gasCommandHistory; int main(int argc, char *argv[], char *envp[]) { char *sCommandStr; - char *saArgs[32]; + char *saArgs[32] = {0}; int length = 0; int i; int iArgCount = 0; @@ -77,8 +76,9 @@ int main(int argc, char *argv[], char *envp[]) if(saArgs[0]) free(saArgs); if(!bCached) free(sCommandStr); bCached = 0; + write(_stdout, strlen(gsCurrentDirectory), gsCurrentDirectory); - write(_stdout, 3, "$ "); + write(_stdout, 2, "$ "); // Read Command line sCommandStr = ReadCommandLine( &length ); @@ -135,6 +135,7 @@ char *ReadCommandLine(int *Length) char *ret; int len, pos, space = 1023; char ch; + // int scrollbackPos = giLastCommand; // Preset Variables ret = malloc( space+1 ); @@ -144,19 +145,48 @@ char *ReadCommandLine(int *Length) // Read In Command Line do { read(_stdin, 1, &ch); // Read Character from stdin (read is a blocking call) - // Ignore control characters + // Control characters if(ch == '\x1B') { read(_stdin, 1, &ch); // Read control character switch(ch) { - case 'D': if(pos) pos--; break; - case 'C': if(pos 0 ) break; + + free(ret); + ret = strdup( gasCommandHistory[--scrollbackPos] ); + + len = strlen(ret); + while(pos--) write(_stdout, 3, "\x1B[D"); + while(pos++ < len) write(_stdout, 3, "\x1B[C"); + break; + case 'B': // Down + if( scrollbackPos < giLastCommand-1 ) break; + free(ret); + ret = strdup( gasCommandHistory[++scrollbackPos] ); + + len = strlen(ret); + while(pos--) write(_stdout, 3, "\x1B[D"); + while(pos++ < len) write(_stdout, 3, "\x1B[C"); + break; + #endif + case 'D': // Left + if(pos == 0) break; + pos --; + write(_stdout, 3, "\x1B[D"); + break; + case 'C': // Right + if(pos == len-1) break; + pos++; + write(_stdout, 3, "\x1B[C"); + break; } } continue; @@ -174,6 +204,13 @@ char *ReadCommandLine(int *Length) write(_stdout, 1, &ch); continue; } + // Tab + if(ch == '\t') { + //TODO: Implement Tab-Completion + //Currently just ignore tabs + continue; + } + // Expand Buffer if(len > space) { space += 256; @@ -324,76 +361,32 @@ void Command_Logout(int argc, char **argv) } /** - * \fn void Command_Clear(int argc, char **argv) - * \brief Clear the screen + * \fn void Command_Colour(int argc, char **argv) + * \brief Displays the help screen */ -void Command_Clear(int argc, char **argv) +void Command_Help(int argc, char **argv) { - write(_stdout, 4, "\x1B[2J"); //Clear Screen + Print("Acess 2 Command Line Interface\n"); + Print(" By John Hodge (thePowersGang / [TPG])\n"); + Print("\n"); + Print("Builtin Commands:\n"); + Print(" logout: Return to the login prompt\n"); + Print(" exit: Same\n"); + Print(" help: Display this message\n"); + Print(" clear: Clear the screen\n"); + Print(" cd: Change the current directory\n"); + Print(" dir: Print the contents of the current directory\n"); + //Print("\n"); + return; } /** - * \fn void Command_Colour(int argc, char **argv) - * \brief Set the colour of the shell prompt - * \note Conflicts with coloured `dir` display + * \fn void Command_Clear(int argc, char **argv) + * \brief Clear the screen */ -void Command_Colour(int argc, char **argv) +void Command_Clear(int argc, char **argv) { - int fg, bg; - char clrStr[6] = "\x1B[37m"; - - // Verify Arg Count - if(argc < 2) - { - goto usage; - } - - // Check Colour - for(fg=0;fg<8;fg++) - if(strcmp(cCOLOUR_NAMES[fg], argv[1]) == 0) - break; - - // Foreground a valid colour - if(fg == 8) { - Print("Unknown Colour '");Print(argv[1]);Print("'\n"); - goto usage; - } - // Set Foreground - clrStr[3] = '0' + fg; - write(_stdout, 6, clrStr); - - // Need to Set Background? - if(argc > 2) - { - for(bg=0;bg<8;bg++) - if(strcmp(cCOLOUR_NAMES[bg], argv[2]) == 0) - break; - - // Valid colour - if(bg == 8) - { - Print("Unknown Colour '");Print(argv[2]);Print("'\n"); - goto usage; - } - - clrStr[2] = '4'; - clrStr[3] = '0' + bg; - write(_stdout, 6, clrStr); - } - // Return - return; - - // Function Usage (Requested via a Goto (I know it's ugly)) -usage: - Print("Usage: colour []\n"); - Print("Valid Colours are "); - for(fg=0;fg<8;fg++) - { - Print(cCOLOUR_NAMES[fg]); - write(_stdout, 3, ", "); - } - write(_stdout, 4, "\b\b\n"); - return; + write(_stdout, 4, "\x1B[2J"); //Clear Screen } /** @@ -462,10 +455,7 @@ void Command_Dir(int argc, char **argv) // Check if file opened if(dp == -1) { - //printf("Unable to open directory `%s', File cannot be found\n", tmpPath); - write(_stdout, 27, "Unable to open directory `"); - write(_stdout, strlen(tmpPath)+1, tmpPath); - write(_stdout, 25, "', File cannot be found\n"); + printf("Unable to open directory `%s', File cannot be found\n", tmpPath); return; } // Get File Stats