From dd5bc9e3acc9a42e4c6c921ae4d8a90d9cc39600 Mon Sep 17 00:00:00 2001 From: "Kartik K. Agaram" Date: Thu, 3 Mar 2022 18:34:15 -0800 Subject: 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? --- src/lcurses/window.c | 55 +++++++++++++++++++++++++++++++--------------------- 1 file changed, 33 insertions(+), 22 deletions(-) (limited to 'src') 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); } -- cgit 1.4.1-2-gfad0