diff options
author | Kartik K. Agaram <vc@akkartik.com> | 2021-11-06 14:41:11 -0700 |
---|---|---|
committer | Kartik K. Agaram <vc@akkartik.com> | 2021-11-06 14:41:11 -0700 |
commit | 62ecf178707fd009653061a47bbb42dc1336b5b7 (patch) | |
tree | d2476d30e97648f3cc62c21f53cc3edefdcdfe9c | |
parent | 369eaeeaf10912977a9afb37e4148dcb6567e3d5 (diff) | |
download | teliva-62ecf178707fd009653061a47bbb42dc1336b5b7.tar.gz |
escape hatch to quit with a pending error
-rw-r--r-- | src/kilo.c | 12 | ||||
-rw-r--r-- | src/lua.c | 7 |
2 files changed, 14 insertions, 5 deletions
diff --git a/src/kilo.c b/src/kilo.c index dfcf530..4016d75 100644 --- a/src/kilo.c +++ b/src/kilo.c @@ -848,6 +848,8 @@ void abFree(struct abuf *ab) { free(ab->b); } +extern char *Previous_error; + /* This function writes the whole screen using VT100 escape characters * starting from the logical state of the editor in the global state 'E'. */ void editorRefreshScreen(void) { @@ -925,6 +927,10 @@ void editorRefreshScreen(void) { abAppend(&ab,"\x1b[0K",4); abAppend(&ab," \x1b[7m ^e \x1b[0m run ",19); int len = 2 + 4 + 5; + if (Previous_error != NULL) { + abAppend(&ab,"\x1b[7m ^c \x1b[0m\x1b[1m abort \x1b[0m",27); + len += 4 + 7; + } abAppend(&ab,"\x1b[7m ^s \x1b[0m search ",20); len += 4 + 8; char rstatus[80]; @@ -1163,8 +1169,10 @@ void editorProcessKeypress(int fd) { editorInsertNewline(); break; case CTRL_C: - /* We ignore ctrl-c, it can't be so simple to lose the changes - * to the edited file. */ + /* Mostly ignore ctrl-c. */ + if (c == 3) /* ctrl-c */ + if (Previous_error != NULL) + exit(1); break; case CTRL_E: /* Save and quit. */ diff --git a/src/lua.c b/src/lua.c index 34fcd13..b92204f 100644 --- a/src/lua.c +++ b/src/lua.c @@ -86,11 +86,12 @@ void switch_to_editor(const char *message) { } +const char *Previous_error = NULL; static int show_error_in_editor (lua_State *L, int status) { if (status && !lua_isnil(L, -1)) { - const char *msg = lua_tostring(L, -1); - if (msg == NULL) msg = "(error object is not a string)"; - switch_to_editor(msg); + Previous_error = lua_tostring(L, -1); + if (Previous_error == NULL) Previous_error = "(error object is not a string)"; + switch_to_editor(Previous_error); } return status; } |