diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/teliva.c | 30 |
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) |