refactor: improve on scrolling experience in lunaix console
[lunaix-os.git] / lunaix-os / kernel / demos / simple_sh.c
index 036550a4fe0ab6ccb7363e83bbdde3cc6c79f3f8..8243ae1d85352141c36274a0462942a1b1354c0d 100644 (file)
@@ -67,9 +67,11 @@ sh_main()
     char buf[512];
     char *cmd, *argpart;
 
     char buf[512];
     char *cmd, *argpart;
 
+    printf("\n Simple shell. Use <PG_UP> or <PG_DOWN> to scroll.\n\n");
+
     while (1) {
         getcwd(pwd, 512);
     while (1) {
         getcwd(pwd, 512);
-        printf("%s> ", pwd);
+        printf("%s$ ", pwd);
         size_t sz = read(stdin, buf, 512);
         if (sz < 0) {
             printf("fail to read user input (%d)\n", geterrno());
         size_t sz = read(stdin, buf, 512);
         if (sz < 0) {
             printf("fail to read user input (%d)\n", geterrno());
@@ -77,6 +79,9 @@ sh_main()
         }
         buf[sz - 1] = '\0';
         parse_cmdline(buf, &cmd, &argpart);
         }
         buf[sz - 1] = '\0';
         parse_cmdline(buf, &cmd, &argpart);
+        if (cmd[0] == 0) {
+            goto cont;
+        }
         if (streq(cmd, "cd")) {
             if (chdir(argpart) < 0) {
                 sh_printerr();
         if (streq(cmd, "cd")) {
             if (chdir(argpart) < 0) {
                 sh_printerr();
@@ -100,6 +105,7 @@ sh_main()
         } else {
             printf("unknow command");
         }
         } else {
             printf("unknow command");
         }
+    cont:
         printf("\n");
     }
 }
\ No newline at end of file
         printf("\n");
     }
 }
\ No newline at end of file