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