ESH

Executive Shell
git clone http://git.omkov.net/ESH
Log | Tree | Refs | README | Download

AuthorJamozed <[email protected]>
Date2021-04-01 07:19:32
Commitd0caacdd3e6a39d32c007d41fb9afc2f23275d24
Parentf83cfdddd3ea35c0d545eae1373c889fb85d21ac

Fix SIGINT handling at prompt

Diffstat

M src/lineread.c | 10 +++++++++-
M src/main.c | 6 +++---

2 files changed, 12 insertions, 4 deletions

diff --git a/src/lineread.c b/src/lineread.c
index ef4a59d..cf2f415 100644
--- a/src/lineread.c
+++ b/src/lineread.c
@@ -61,6 +61,7 @@ static size_t getcols(void);
 static void clearscreen(struct line *l);
 
 static void lineRefresh(struct line *l);
+static void lineReset(struct line *l);
 static void lineMoveLeft(struct line *l);
 static void lineMoveRight(struct line *l);
 static void lineMoveWordHome(struct line *l);
@@ -101,6 +102,7 @@ static char *lineedit(void) {
 		switch (c) {
 		case '\x01': { lineMoveHome(&l); continue; }       // CTRL + A
 		case '\x02': { lineMoveLeft(&l); continue; }       // CTRL + B
+		case '\x03': { lineReset(&l); continue; }          // CTRL + C
 		case '\x04': { r = NULL; goto ret; }               // CTRL + D
 		case '\x05': { lineMoveEnd(&l); continue; }        // CTRL + E
 		case '\x06': { lineMoveRight(&l); continue; }      // CTRL + F
@@ -148,7 +150,7 @@ static char *lineedit(void) {
 end:;
 	r = strndup(l.s, l.sl);
 ret:;
-	free(l.s); tcrestore(); return r;
+	free(l.s); tcrestore(); fputc('\n', stdout); return r;
 }
 
 /* Handle an extended ^[ sequence */
@@ -205,6 +207,12 @@ static void lineRefresh(struct line *l) {
 	return;
 }
 
+/* Reset line */
+static void lineReset(struct line *l) {
+	l->s[0] = 0; l->sp = 0; l->sl = 0;
+	fputs("^C\n", stdout); lineRefresh(l); return;
+}
+
 /* Move cursor left */
 static void lineMoveLeft(struct line *l) {
 	if (l->sp) { --l->sp; fputs("\x1B[D", stdout); } return;
diff --git a/src/main.c b/src/main.c
index 364fa63..7f17086 100644
--- a/src/main.c
+++ b/src/main.c
@@ -52,15 +52,15 @@ static sig_atomic_t jmpflag = false;
 
 static void reset(int signo);
 
-int main(int ac, char *av[]) { (void)(ac);
+int main(int ac, char *av[]) { (void)(ac); A0 = av[0];
 	signal(SIGINT, &reset); signal(SIGTSTP, SIG_IGN); signal(SIGQUIT, SIG_IGN);
 	if (errno) { warn("%s", serr()); }
 
 	do {
 		if (sigsetjmp(jmp, 1)) { fputc('\n', stdout); } jmpflag = true;
 
-		char *line = lineread(); fputc('\n', stdout);
-		if (!line) { if (errno) { warn("%s", serr()); } break; }
+		char *line = lineread();
+		if (!line) { if (errno) { warn("%s, %d", serr(), errno); } break; }
 
 		for (char *e = line; *e;) {
 			char **args = parse(e, &e);