summaryrefslogtreecommitdiff
path: root/src/user/sh.cc
diff options
context:
space:
mode:
authorRichard Qin <richard.qin.x@gmail.com>2026-01-04 14:05:49 +0800
committerRichard Qin <richard.qin.x@gmail.com>2026-01-04 14:05:49 +0800
commitd3cf3f08d1343d6b265516d5a79ce2d197b59d26 (patch)
treea4bbae6cff94fa69eea30db865267b211eb4c86b /src/user/sh.cc
parent210025560c80b48af4875af199f183ad709e3bf0 (diff)
downloadlume-d3cf3f08d1343d6b265516d5a79ce2d197b59d26.tar.gz
lume-d3cf3f08d1343d6b265516d5a79ce2d197b59d26.tar.xz
feat(file-system): implement read and write FAT32 File System and basic shell
Diffstat (limited to 'src/user/sh.cc')
-rw-r--r--src/user/sh.cc53
1 files changed, 24 insertions, 29 deletions
diff --git a/src/user/sh.cc b/src/user/sh.cc
index 1f2e950..b4122f7 100644
--- a/src/user/sh.cc
+++ b/src/user/sh.cc
@@ -3,6 +3,7 @@
#include "ulib/string.h"
#include "user/user.h"
#include "common/fcntl.h"
+#include "drivers/uart_color.h"
constexpr int MAX_ARGS = 10;
const char *WHITESPACE = " \t\r\n\v";
@@ -334,35 +335,13 @@ int getcmd(char *buf, int nbuf)
write(1, "$ ", 2);
memset(buf, 0, nbuf);
- int i = 0;
- while (i < nbuf - 1)
- {
- char c;
- int n = read(0, &c, 1);
- if (n <= 0)
- return -1;
+ int n = read(0, buf, nbuf - 1);
- if (c == '\b' || c == 127)
- {
- if (i > 0)
- {
- write(1, "\b \b", 3);
- i--;
- }
- }
- else if (c == '\n' || c == '\r')
- {
- write(1, "\n", 1);
- buf[i] = 0;
- return 0;
- }
- else
- {
- write(1, &c, 1);
- buf[i++] = c;
- }
- }
- return -1;
+ if (n < 0)
+ return -1;
+
+ buf[n] = 0;
+ return 0;
}
int main()
@@ -379,10 +358,18 @@ int main()
// }
// }
- printf("\n[Lume Shell] Initialized! \n");
+ printf(ANSI_GREEN"\n[Lume Shell] Welcome! \n"ANSI_RESET);
+ printf(ANSI_YELLOW "[Lume Shell] Start your journey of exploration!"ANSI_RESET);
+ printf("\n");
while (getcmd(buf, sizeof(buf)) >= 0)
{
+ int len = strlen(buf);
+ if (len > 0 && buf[len - 1] == '\n')
+ {
+ buf[len - 1] = 0;
+ }
+
if (buf[0] == 'c' && buf[1] == 'd' && (buf[2] == ' ' || buf[2] == '\n' || buf[2] == 0))
{
if (buf[strlen(buf) - 1] == '\n')
@@ -401,6 +388,14 @@ int main()
}
continue;
}
+ if (strcmp(buf, "shutdown") == 0 || strcmp(buf, "poweroff") == 0)
+ {
+ printf(ANSI_BLUE"System shutting down..."ANSI_RESET);
+ printf("\n");
+ shutdown();
+
+ continue;
+ }
if (fork_or_panic() == 0)
{