escape
This commit is contained in:
parent
01d4457763
commit
8618d3daf0
20
msh.c
20
msh.c
@ -12,6 +12,8 @@
|
||||
#include "fstr.h"
|
||||
#include "err.h"
|
||||
|
||||
#define S_ESCAPE 0x1
|
||||
|
||||
fstr_t PS1 = {0};
|
||||
unsigned int histsize = DEF_HISTSIZE;
|
||||
|
||||
@ -44,7 +46,8 @@ int main(int argc, char **argv)
|
||||
(void)argc;
|
||||
(void)argv;
|
||||
char i;
|
||||
|
||||
unsigned int state = 0;
|
||||
|
||||
sh_setup_terminal();
|
||||
for (;;) {
|
||||
sh_update_uinfo();
|
||||
@ -52,12 +55,23 @@ int main(int argc, char **argv)
|
||||
sh_update_ps1();
|
||||
sh_print_ps1();
|
||||
fflush(stdout);
|
||||
while (1) {
|
||||
for (int line = 1; line;) {
|
||||
|
||||
read(STDIN_FILENO, &i, 1); // This blocks
|
||||
fputc(i, stdout);
|
||||
fflush(stdout);
|
||||
if (i == '\n')
|
||||
|
||||
switch (i) {
|
||||
case '\n':
|
||||
line = state & S_ESCAPE;
|
||||
break;
|
||||
case '\\':
|
||||
state ^= ~S_ESCAPE;
|
||||
break;
|
||||
default:
|
||||
state &= ~S_ESCAPE;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user