about summary refs log tree commit diff
diff options
context:
space:
mode:
authorYour Name <you@example.com>2020-06-25 04:05:45 +0200
committerYour Name <you@example.com>2020-06-25 04:05:45 +0200
commit11bd3794cf7aeabb64bf94e72b4a3e673bd74a93 (patch)
treebb14ec8623773014a7d57d65f46717b8d3bccded
parentstdlib: fixed memset implementation bug (diff)
downloadpOS-11bd3794cf7aeabb64bf94e72b4a3e673bd74a93.tar.gz
pOS-11bd3794cf7aeabb64bf94e72b4a3e673bd74a93.tar.bz2
pOS-11bd3794cf7aeabb64bf94e72b4a3e673bd74a93.zip
Shell: better signal handling
The shell now copes better with left and right arrow signals
-rw-r--r--src/pOS/arch/x86/kernel/shell/shell.cpp22
1 files changed, 17 insertions, 5 deletions
diff --git a/src/pOS/arch/x86/kernel/shell/shell.cpp b/src/pOS/arch/x86/kernel/shell/shell.cpp
index 16ca129..5e8d896 100644
--- a/src/pOS/arch/x86/kernel/shell/shell.cpp
+++ b/src/pOS/arch/x86/kernel/shell/shell.cpp
@@ -1,6 +1,8 @@
 #include <kernel/shell/shell.h>
 
 char Shell::prefix[10];
+static int indx = 0;
+static char cmd[20];        /* Mem management */
 
 void signal_handler(Signal_Type signal)
 {
@@ -9,10 +11,17 @@ void signal_handler(Signal_Type signal)
         case ESC_SIG:
             break;
         case LEFT_ARROW_SIG:
-            TTY::tty_cursor_move(-1, 0);
+            if(indx - 1 >= 0)
+            {
+                TTY::tty_cursor_move(-1, 0);
+                indx--;
+            }
             break;
         case RIGHT_ARROW_SIG:
             TTY::tty_cursor_move(+1, 0);
+            if(cmd[indx] == 0)
+                cmd[indx] = ' ';
+            indx++;
             break;
         case UP_ARROW_SIG:
             /* TODO: implement history */
@@ -35,18 +44,17 @@ int Shell::run(void)
 {
     char c;
     int return_code = 0;
-    int indx = 0;
-    char cmd[20];        /* Mem management */
     printf("%s ", Shell::prefix);
     while((c = getc()) && c != EOF)
     {
         putc(c);
 
         if(c == '\b')
-            indx--;
+        {
+            cmd[indx] = c;
+        }
         else if(c == '\n')
         {
-            cmd[indx] = '\0';
             indx = 0;
 
             return_code = CMD_MANAGER::execute(cmd);
@@ -55,10 +63,14 @@ int Shell::run(void)
             sprintf(retstr, "(%d)", return_code);
             if(!return_code)
                 retstr[0] = '\0';
+
             printf("%s%s ", retstr, Shell::prefix);
+            memset(cmd, 0, 20);
         }
         else
+        {
             cmd[indx++] = c;
+        }
     }
 
     ASSERT(c == EOF);