From ea2bb080beec76622d1de18c3975199fd1319db9 Mon Sep 17 00:00:00 2001 From: ChenZhengHao Date: Fri, 3 Nov 2023 18:11:05 +0800 Subject: [PATCH 1/2] Clear screen after pressing CTRL-Q --- kilo.c | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/kilo.c b/kilo.c index 406eb7be..76bc2ee4 100644 --- a/kilo.c +++ b/kilo.c @@ -997,6 +997,13 @@ void editorRefreshScreen(void) { abFree(&ab); } +/* This function clear the whole screen using VT100 escape characters */ +void editorClearScreen(void) { + struct abuf ab = ABUF_INIT; + abAppend(&ab,"\x1b[J", E.numrows); + write(STDOUT_FILENO,ab.b,ab.len); +} + /* Set an editor status message for the second line of the status, at the * end of the screen. */ void editorSetStatusMessage(const char *fmt, ...) { @@ -1207,6 +1214,7 @@ void editorProcessKeypress(int fd) { quit_times--; return; } + editorClearScreen(); exit(0); break; case CTRL_S: /* Ctrl-s */ From aaeb70ffb20798dd04e3cc59ac6fb2eea4bd361d Mon Sep 17 00:00:00 2001 From: ChenZhengHao Date: Mon, 6 Nov 2023 09:52:44 +0800 Subject: [PATCH 2/2] Free ab --- kilo.c | 1 + 1 file changed, 1 insertion(+) diff --git a/kilo.c b/kilo.c index 76bc2ee4..dfc948b0 100644 --- a/kilo.c +++ b/kilo.c @@ -1002,6 +1002,7 @@ void editorClearScreen(void) { struct abuf ab = ABUF_INIT; abAppend(&ab,"\x1b[J", E.numrows); write(STDOUT_FILENO,ab.b,ab.len); + abFree(&ab); } /* Set an editor status message for the second line of the status, at the