Skip to content

Commit

Permalink
更新调试shell
Browse files Browse the repository at this point in the history
  • Loading branch information
copi143 committed Dec 9, 2024
1 parent 193e0bc commit f6d3492
Show file tree
Hide file tree
Showing 4 changed files with 41 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/boot/run.sh
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,4 @@ qemu-system-i386 \
-boot a \
$*

echo -n -e "\033[T\033[2K\033[999D"
echo -n -e "\033[m\033[2K\033[A\033[2K\033[999D"
6 changes: 6 additions & 0 deletions src/kernel/drivers/storage/ide.c
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,12 @@ void ide_initialize(u32 BAR0, u32 BAR1, u32 BAR2, u32 BAR3, u32 BAR4) {
ide_devices[count].Model[k + 1] = ide_buf[ATA_IDENT_MODEL + k];
}
ide_devices[count].Model[40] = 0; // Terminate String.
for (k = 0; k < 40; k++) {
if (ide_devices[count].Model[k] == ' ') {
ide_devices[count].Model[k] = 0;
break;
}
}

count++;
}
Expand Down
35 changes: 26 additions & 9 deletions src/kernel/io/logging.c
Original file line number Diff line number Diff line change
Expand Up @@ -259,9 +259,12 @@ bool debug_enabled = false;
extern struct event debug_shell_event;
extern char debug_shell_path[1024];

char debug_shell_message[256];

static int input_nlines = 1;

static void clear_input_view() {
_puts(CEND);
for (int i = 0; i < input_nlines; i++) {
_puts("\033[2K\033[A");
}
Expand All @@ -271,8 +274,24 @@ static void clear_input_view() {
static void print_input_buffer() {
_puts(CRGB(153, 255, 231) CBRGB(95, 95, 240) "\033[2K at " CRGB(255, 192, 224));
_puts(debug_shell_path);
_puts(CRGB(153, 255, 231) " " CEND "\n");
_puts(CRGB(183, 183, 255) ">" CEND " " CRGB(255, 224, 183));
_puts(CRGB(153, 255, 231) "\033[999C");
if (debug_shell_message[0] == '\0') strcpy(debug_shell_message, "Hello debug shell!");
int n = strlen(debug_shell_message);
for (int i = 0; i < n; i++) {
_puts("\033[D");
}
for (int i = 0; i < n; i++) {
const int k = i * 256 / (n - 1);
static char buffer[32];
sprintf(buffer, "\033[38;2;%d;%d;%dm", //
(253 * k + 246 * (256 - k)) / 256, //
(133 * k + 211 * (256 - k)) / 256, //
(172 * k + 101 * (256 - k)) / 256); //
_puts(buffer);
_putb(debug_shell_message[i]);
}
_puts(CEND "\n");
_puts(CRGB(255, 224, 183) "\033[2K" CRGB(183, 183, 255) ">" CEND " " CRGB(255, 224, 183));
buf[bufp] = '\0';
_puts(buf);
}
Expand All @@ -281,7 +300,7 @@ static void print_input_buffer() {
finline void log_outs(cstr s) {
if (s == null) return;
clear_input_view();
if (!lastline_ended) _puts("\033[A\033[999C" CEND);
if (!lastline_ended) _puts("\033[A\033[999C");
for (size_t i = 0; s[i] != '\0'; i++) {
lastline_ended = s[i] == '\n';
_putb(s[i]);
Expand Down Expand Up @@ -384,12 +403,10 @@ void debugger() {
}
}
if (c < 0) break;
if (bufp > 0) {
buf[bufp] = '\0';
event_push(&debug_shell_event, strdup(buf));
bufp = 0;
_puts("\033[2K\033[999D" CRGB(183, 183, 255) ">" CEND " " CRGB(255, 224, 183));
}
buf[bufp] = '\0';
event_push(&debug_shell_event, strdup(buf));
bufp = 0;
_puts("\033[2K\033[999D" CRGB(183, 183, 255) ">" CEND " " CRGB(255, 224, 183));
}
}

Expand Down
9 changes: 8 additions & 1 deletion src/kernel/task/shell.c
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,8 @@ char debug_shell_path[1024];

extern void log_update();

extern char debug_shell_message[256];

void debug_shell() {
sprintf(debug_shell_path, "/");
log_update();
Expand All @@ -310,7 +312,12 @@ void debug_shell() {
task_next();
continue;
}
shell_exec(debug_shell_path, line);
if (line[0] == '\0') {
strcpy(debug_shell_message, "Empty command");
} else {
debug_shell_message[0] = '\0';
shell_exec(debug_shell_path, line);
}
log_update();
free(line);
}
Expand Down

0 comments on commit f6d3492

Please sign in to comment.