forked from MrmaderatorYT/FlowyOS
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnotmain.c
84 lines (80 loc) · 2.08 KB
/
notmain.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
#include "uart.h"
#include "file_system.h"
#include "strings.h"
#define COMMAND_HISTORY_SiZE 10
void notmain(void){
char c;
char command[100];
int index = 0;
int debug_mode = 0;//0 - debug off, 1 - on
char command_history[COMMAND_HISTORY_SiZE][100];
int command_history_count = 0;
int command_history_pos = -1;
uart_puts("UART test OS is ready!\n");
init_fs();
while(1){
c = uart_getc();
if(c == '\r'){
command[index] = '\0';
if(command[0] != '\0'){
if(command_history_count < COMMAND_HISTORY_SiZE){
my_strcpy(command_history[command_history_count++], command);
}else{
for (int i = 0; i < COMMAND_HISTORY_SiZE; i++){
my_strcpy(command_history[i-1], command_history[i]);
}
my_strcpy(command_history[COMMAND_HISTORY_SiZE - 1], command);
}
}
command_history_pos = command_history_count;
print_command(command, debug_mode);
process_command(command, &debug_mode);
index = 0;
} else if (c == '\b' || c == 127){
if(index > 0){
index--;
uart_puts("\b \b");
}
} else if(c == 27){
char seq[2];
seq[0] = uart_getc();
seq[1] = uart_getc();
if(seq[0] == '['){
if(seq[1]=='A'){
if(command_history_pos > 0){
command_history_pos--;
while(index > 0){
uart_puts("\b \b");
index--;
}
my_strcpy(command, command_history[command_history_pos]);
index = my_strlen(command);
uart_puts(command);
}
}else if(seq[1] == 'B'){
if(command_history_pos < command_history_count - 1){
command_history_pos++;
while(index > 0){
uart_puts("\b \b");
index--;
}
my_strcpy(command, command_history[command_history_pos]);
index = my_strlen(command);
uart_puts(command);
}else if(command_history_pos == command_history_count - 1){
while(index > 0){
uart_puts("\b \b");
index--;
}
command[0] = '\0';
}
}
}
}else{
if(index < sizeof(command)-1){
command[index++] = c;
uart_putc(c);
}
}
}
}