about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2022-04-07 09:19:55 -0700
committerKartik K. Agaram <vc@akkartik.com>2022-04-07 09:19:55 -0700
commit98e657d6e21c7261099ed027ba6e5ebe5a5e677e (patch)
treedfff1eb9b48d5cab5d7971aca23accbebdc87dbe
parentdad78ac424b3d3b6136c6988cf692563b456a6e7 (diff)
downloadteliva-98e657d6e21c7261099ed027ba6e5ebe5a5e677e.tar.gz
actually _use_ the ask permission
-rw-r--r--src/teliva.c30
1 files changed, 29 insertions, 1 deletions
diff --git a/src/teliva.c b/src/teliva.c
index c5cdac3..51f66e2 100644
--- a/src/teliva.c
+++ b/src/teliva.c
@@ -1367,7 +1367,28 @@ static const char* user_configuration_filename() {
   return config_filename;
 }
 
-int file_operation_permitted(const char* filename, const char* mode) {
+static int file_operation_permitted_manually(const char* filename, const char* mode) {
+  int old_y, old_x;
+  getyx(stdscr, old_y, old_x);
+  attr_t old_attrs;
+  short old_pair;
+  attr_get(&old_attrs, &old_pair, NULL);
+  attrset(A_NORMAL);
+  mvaddstr(LINES-1, 0, "");
+  clrtoeol();
+  attrset(A_REVERSE);
+  if (strncmp(mode, "r", /*strlen("r") + 1 for NULL*/ 2) == 0)
+    mvprintw(LINES-1, 0, "open file \"%s\" for reading? ", filename);
+  else
+    mvprintw(LINES-1, 0, "open file \"%s\" for reading and writing? ", filename);
+  attrset(A_NORMAL);
+  int response = getch();
+  attr_set(old_attrs, old_pair, NULL);
+  mvaddstr(old_y, old_x, "");
+  return response == 'y';
+}
+
+static int file_operation_permitted_automatically(const char* filename, const char* mode) {
   int oldtop = lua_gettop(trustedL);
   lua_getglobal(trustedL, "file_operation_permitted");
   lua_pushstring(trustedL, filename);
@@ -1386,6 +1407,13 @@ int file_operation_permitted(const char* filename, const char* mode) {
   return should_allow;
 }
 
+int file_operation_permitted(const char* filename, const char* mode) {
+  if (ask_for_permission_on_every_file_operation)
+    return file_operation_permitted_manually(filename, mode);
+  else
+    return file_operation_permitted_automatically(filename, mode);
+}
+
 static void permissions_menu() {
   attrset(A_REVERSE);
   for (int x = 0; x < COLS; ++x)