shithub: femtolisp

Download patch

ref: fc7d6470a2c308ac8265515703be2b657aac67e0
parent: 738a6ef63e019cfd6262b4418f5aa9d8c7c3a1d9
author: Sigrid Solveig Haflínudóttir <sigrid@ftrv.se>
date: Sun Nov 3 17:21:54 EST 2024

terminal: reset back to non-raw mode in atexit

--- a/terminal_posix.c
+++ b/terminal_posix.c
@@ -4,11 +4,18 @@
 #include <termios.h>
 
 static bool inraw = false;
+static bool atexitset = false;
 static struct termios tios;
 
+static void termresetraw(void);
+
 static int
 termsetraw(bool raw)
 {
+	if(!atexitset){
+		atexit(termresetraw);
+		atexitset = true;
+	}
 	if(raw && !inraw){
 		if(tcgetattr(STDIN_FILENO, &tios) < 0)
 			return -1;
@@ -27,6 +34,12 @@
 		inraw = false;
 	}
 	return 0;
+}
+
+static void
+termresetraw(void)
+{
+	termsetraw(false);
 }
 
 BUILTIN("terminal-enter-raw-mode", terminal_enter_raw_mode)