From 29b56ef4e4113bcd091b19d6926f18814162ca53 Mon Sep 17 00:00:00 2001 From: Nicholas Noll Date: Tue, 26 Oct 2021 21:01:41 -0700 Subject: Feat(libunicode): Added an explicit unicode library Refactored code to pull out utf8 functions from base into a standalone library. Also left the required function inside arg.c so that code that calls ARG_BEGIN doesn't have to link to libunicode. --- sys/cmd/rc/exec.c | 2 +- sys/cmd/rc/input.c | 6 +++--- sys/cmd/rc/lex.c | 1 + sys/cmd/rc/prompt.c | 19 ++++++++++++++----- sys/cmd/rc/rc.h | 4 ++-- 5 files changed, 21 insertions(+), 11 deletions(-) (limited to 'sys/cmd/rc') diff --git a/sys/cmd/rc/exec.c b/sys/cmd/rc/exec.c index 1b311ec..5baaf1a 100644 --- a/sys/cmd/rc/exec.c +++ b/sys/cmd/rc/exec.c @@ -914,7 +914,7 @@ Xreadcmd(void) flush(shell.err); root = runner; - shell.prompt = "> "; + resetprompt(); if(yyparse()){ // resource cleanup? diff --git a/sys/cmd/rc/input.c b/sys/cmd/rc/input.c index a89dbda..56f1780 100644 --- a/sys/cmd/rc/input.c +++ b/sys/cmd/rc/input.c @@ -309,11 +309,11 @@ refreshsingleline(struct TerminalState *term) char esc[64]; struct Buffer ab; - intptr plen = term->plen; + intptr plen = term->plen; int fd = term->ofd; char *buf = term->buf; - intptr len = term->len; - intptr pos = term->pos; + intptr len = term->len; + intptr pos = term->pos; while((plen+pos) >= term->cols) { buf++; diff --git a/sys/cmd/rc/lex.c b/sys/cmd/rc/lex.c index 596021b..9a58f21 100644 --- a/sys/cmd/rc/lex.c +++ b/sys/cmd/rc/lex.c @@ -52,6 +52,7 @@ readc(void) peek = EOF; return c; } + if(runner->flag.eof) return EOF; diff --git a/sys/cmd/rc/prompt.c b/sys/cmd/rc/prompt.c index d6846e6..6a32d59 100644 --- a/sys/cmd/rc/prompt.c +++ b/sys/cmd/rc/prompt.c @@ -1,21 +1,30 @@ #include "rc.h" +static char promptbuf[7] = {'>', ' ', 0, ' ' , ' ', ' ', 0}; + +void +resetprompt(void) +{ + promptbuf[2] = 0; +} int prompt(ushort *flag) { - int fd, f = *flag; + int f = *flag; + if(f){ - if(!readline(shell.prompt)){ + if(!readline(promptbuf)){ runner->flag.eof = 1; return 0; } - fd = mapfd(0); - write(fd, "\n\r", 2); - shell.prompt = "> "; // NOTE: can't use tab here: we have a hacky prompt length computation + write(mapfd(0), "\n\r", 2); + + promptbuf[2] = ' '; runner->line++; *flag = 0; } + return 1; } diff --git a/sys/cmd/rc/rc.h b/sys/cmd/rc/rc.h index 5a9aac5..eaf668a 100644 --- a/sys/cmd/rc/rc.h +++ b/sys/cmd/rc/rc.h @@ -152,7 +152,6 @@ struct Shell Io *err; int status; int interactive; - char *prompt; Thread *jobs; }; @@ -178,7 +177,8 @@ int readline(char *); void enablevi(void); /* prompt.c */ -int prompt(ushort *); +void resetprompt(void); +int prompt(ushort *); /* io.c */ Io *openfd(int fd); -- cgit v1.2.1