Fixed keyboard bug where keypresses were not being registered, working on libreadline
[tpg/acess2.git] / Usermode / Applications / CLIShell_src / main.c
index 836c6f5..579df88 100644 (file)
@@ -1,12 +1,17 @@
 /*\r
  * AcessOS Shell Version 3\r
  */\r
+#define USE_READLINE   0\r
 #include <acess/sys.h>\r
 #include <stdlib.h>\r
 #include <stdio.h>\r
 #include <string.h>\r
 #include "header.h"\r
 \r
+#if USE_READLINE\r
+# include "readline.h"\r
+#endif\r
+\r
 #define _stdin 0\r
 #define _stdout        1\r
 #define _stderr        2\r
@@ -51,7 +56,15 @@ int main(int argc, char *argv[], char *envp[])
         int    length = 0;\r
         int    i;\r
         int    iArgCount = 0;\r
+       #if !USE_READLINE\r
         int    bCached = 1;\r
+       #else\r
+       tReadline       readline_state = {0};\r
+       #endif\r
+       \r
+       #if USE_READLINE\r
+       readline_state.UseHistory = 1;\r
+       #endif\r
        \r
        gasEnvironment = envp;\r
        \r
@@ -74,13 +87,19 @@ int main(int argc, char *argv[], char *envp[])
        {\r
                // Free last command & arguments\r
                if(saArgs[0])   free(saArgs);\r
+               #if !USE_READLINE\r
                if(!bCached)    free(sCommandStr);\r
                bCached = 0;\r
+               #endif\r
                \r
                write(_stdout, strlen(gsCurrentDirectory), gsCurrentDirectory);\r
                write(_stdout, 2, "$ ");\r
                \r
                // Read Command line\r
+               #if USE_READLINE\r
+               sCommandStr = Readline( &readline_state );\r
+               length = strlen(sCommandStr);\r
+               #else\r
                sCommandStr = ReadCommandLine( &length );\r
                \r
                if(!sCommandStr) {\r
@@ -99,6 +118,7 @@ int main(int argc, char *argv[], char *envp[])
                        gasCommandHistory[ giLastCommand ] = sCommandStr;\r
                        bCached = 1;\r
                }\r
+               #endif\r
                \r
                // Parse Command Line into arguments\r
                Parse_Args(sCommandStr, saArgs);\r
@@ -123,6 +143,10 @@ int main(int argc, char *argv[], char *envp[])
                \r
                // Shall we?\r
                CallCommand( &saArgs[1] );\r
+               \r
+               #if USE_READLINE\r
+               free( sCommandStr );\r
+               #endif\r
        }\r
 }\r
 \r
@@ -135,7 +159,7 @@ char *ReadCommandLine(int *Length)
        char    *ret;\r
         int    len, pos, space = 1023;\r
        char    ch;\r
-       #if 1\r
+       #if 0\r
         int    scrollbackPos = giLastCommand;\r
        #endif\r
         \r

UCC git Repository :: git.ucc.asn.au