From 91bb40ebed3548a3051e97358e15cc4057ee82f9 Mon Sep 17 00:00:00 2001 From: Aaron Fischer Date: Thu, 25 Oct 2018 14:03:31 +0200 Subject: [PATCH] Restore the terminal after exit (fix #14) --- src/terminal.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/terminal.c b/src/terminal.c index b92cdab..861a21e 100644 --- a/src/terminal.c +++ b/src/terminal.c @@ -18,9 +18,15 @@ void die(const char *s) { void disableRawMode() { if (tcsetattr(STDIN_FILENO, TCSAFLUSH, &E.orig_termios) == -1) die("tcsetattr"); + + // Remove the alternate screen and restore the origin one + write(STDOUT_FILENO, "\x1b[?1049l", 8); } void enableRawMode() { + // Use the alternate screen + write(STDOUT_FILENO, "\x1b[?1049h", 8); + if (tcgetattr(STDIN_FILENO, &E.orig_termios) == -1) die("tcgetattr"); atexit(disableRawMode);