about summary refs log tree commit diff stats
path: root/src
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2022-03-03 18:34:15 -0800
committerKartik K. Agaram <vc@akkartik.com>2022-03-03 18:34:15 -0800
commitdd5bc9e3acc9a42e4c6c921ae4d8a90d9cc39600 (patch)
treeba2553ac089b8d03abef9afaa9c07beb43702327 /src
parent101c59d8cbca9dda53fef3c15bb8f590eb1188b8 (diff)
downloadteliva-dd5bc9e3acc9a42e4c6c921ae4d8a90d9cc39600.tar.gz
ask for confirmation on _any_ teliva shortcut
This feels more intrusive. Let's see how we like it. Will I start having
ctrl-x ctrl-x in my muscle memory?
Diffstat (limited to 'src')
-rw-r--r--src/lcurses/window.c55
1 files changed, 33 insertions, 22 deletions
diff --git a/src/lcurses/window.c b/src/lcurses/window.c
index 53abcc1..1f910f2 100644
--- a/src/lcurses/window.c
+++ b/src/lcurses/window.c
@@ -1285,20 +1285,6 @@ 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.
 @function getch
@@ -1320,6 +1306,8 @@ Wgetch(lua_State *L)
 	if (x > COLS-2) x = COLS-2; if (y > LINES-1) y = LINES-1; /* http://gnats.netbsd.org/56664 */
 	mvaddstr(y, x, "");
 	int c = wgetch(w);
+
+	/* audit log */
 	static char buffer[1024] = {0};
 	memset(buffer, '\0', 1024);
 	if (isspace(c))
@@ -1330,18 +1318,41 @@ Wgetch(lua_State *L)
 
 	if (c == ERR)
 		return 0;
-	if (c == CTRL_X) {
-		if (confirm_exit(w)) {
+
+	/* standard menu hotkeys */
+	if (c == CTRL_X || c == CTRL_U || c == CTRL_P) {
+		/* always confirm; we're going to throw away data past this point */
+
+		/* 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;
+		if (c == CTRL_X)
+			draw_menu_item("^x", "exit");
+		else if (c == CTRL_U)
+			draw_menu_item("^u", "edit app code");
+		else if (c == CTRL_P)
+			draw_menu_item("^p", "modify app permissions");
+		draw_menu_item("anything else", "cancel");
+		color_set(COLOR_PAIR_ERROR, NULL);
+		mvaddstr(LINES-1, menu_column+1, " Are you sure? ");
+		color_set(COLOR_PAIR_NORMAL, NULL);
+		attroff(A_BOLD|A_REVERSE);
+
+		if (wgetch(w) != c)
+			return pushintresult(0);
+
+		if (c == CTRL_X) {
 			unlink("teliva_editor_state");
 			exit(0);
 		}
-		else return pushintresult(0);
+		if (c == CTRL_U)
+			developer_mode(L);
+		if (c == CTRL_P)
+			permissions_mode(L);
 	}
-	if (c == CTRL_U)
-		developer_mode(L);
-	if (c == CTRL_P)
-		permissions_mode(L);
-	/* handle other standard menu hotkeys here */
 
 	return pushintresult(c);
 }