about summary refs log tree commit diff stats
path: root/src/lcurses
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2022-03-01 23:10:46 -0800
committerKartik K. Agaram <vc@akkartik.com>2022-03-01 23:10:46 -0800
commitafb3f46db70b1ae1cfdab50908923ea77e508264 (patch)
tree44523b2bb646405d86c856e6ac1adf384f2eed4a /src/lcurses
parent46ef1adb08d7d7cc65e28b61b2fe8ce53015270f (diff)
downloadteliva-afb3f46db70b1ae1cfdab50908923ea77e508264.tar.gz
always ask for confirmation on exit
Let's see if we can live with this rather than some way to let apps
indicate if they want confirmation or not..
Diffstat (limited to 'src/lcurses')
-rw-r--r--src/lcurses/window.c20
1 files changed, 18 insertions, 2 deletions
diff --git a/src/lcurses/window.c b/src/lcurses/window.c
index 3de25aa..53abcc1 100644
--- a/src/lcurses/window.c
+++ b/src/lcurses/window.c
@@ -1285,6 +1285,19 @@ Wwinsdelln(lua_State *L)
 	return pushokresult(winsdelln(w, n));
 }
 
+static int confirm_exit(WINDOW *w) {
+	/* draw a special menu just for this situation */
+	attron(A_BOLD|A_REVERSE);
+	color_set(COLOR_PAIR_MENU, NULL);
+	for (int x = 0; x < COLS; ++x)
+		mvaddch(LINES-1, x, ' ');
+	menu_column = 2;
+	draw_menu_item("^x", "exit");
+	draw_menu_item("anything else", "cancel");
+	attroff(A_BOLD|A_REVERSE);
+	int c = wgetch(w);
+	return (c == CTRL_X);
+}
 
 /***
 Read a character from the window input.
@@ -1318,8 +1331,11 @@ Wgetch(lua_State *L)
 	if (c == ERR)
 		return 0;
 	if (c == CTRL_X) {
-		unlink("teliva_editor_state");
-		exit(0);
+		if (confirm_exit(w)) {
+			unlink("teliva_editor_state");
+			exit(0);
+		}
+		else return pushintresult(0);
 	}
 	if (c == CTRL_U)
 		developer_mode(L);