about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2022-04-05 20:50:51 -0700
committerKartik K. Agaram <vc@akkartik.com>2022-04-05 20:50:51 -0700
commit5b64c4b3bc41215ff02ba3db1540ab152f737639 (patch)
tree4bf40c293a7cf83cb6b45f72d2d348369c7a4fe5
parentb5aca9a57132d8703a6f0809de91da66fa1bf3cc (diff)
downloadteliva-5b64c4b3bc41215ff02ba3db1540ab152f737639.tar.gz
show common suggestions when editing permissions
Computer owners shouldn't get in the habit of trusting app authors
regarding permissions. But they have to trust somebody, and they already
trust the Teliva platform if they are running it.
-rw-r--r--src/kilo.c7
-rw-r--r--src/teliva.c11
2 files changed, 17 insertions, 1 deletions
diff --git a/src/kilo.c b/src/kilo.c
index 1ed700f..fe4b9bf 100644
--- a/src/kilo.c
+++ b/src/kilo.c
@@ -1338,6 +1338,7 @@ void editNonCode(char* filename) {
 
 #define MIN(x, y) ((x) < (y) ? (x) : (y))
 
+void print_file_permission_suggestions(int row);
 void editFilePermissions(char* filename) {
     Quit = 0;
     Back_to_big_picture = 0;
@@ -1354,7 +1355,11 @@ void editFilePermissions(char* filename) {
         int y, x;
         getyx(stdscr, y, x);
         mvaddstr(0, 0, "function file_operation_permitted(filename, is_write)");
-        mvaddstr(MIN(E.startrow + E.numrows, E.endrow), 0, "end");
+        int past_end_row = MIN(E.startrow + E.numrows, E.endrow);
+        mvaddstr(past_end_row, 0, "end");
+        attrset(COLOR_PAIR(COLOR_PAIR_LUA_COMMENT));
+        print_file_permission_suggestions(past_end_row+2);
+        attrset(A_NORMAL);
         mvaddstr(y, x, "");
         int c = getch();
         editorProcessKeypress2(c);
diff --git a/src/teliva.c b/src/teliva.c
index 4ad530e..35c9964 100644
--- a/src/teliva.c
+++ b/src/teliva.c
@@ -1563,6 +1563,17 @@ static void edit_file_operations_predicate_body() {
   }
 }
 
+void print_file_permission_suggestions(int row) {
+  mvaddstr(row++, 0, "-- Some ideas:");
+  mvaddstr(row++, 0, "--  * restrict access to a single file: return filename == 'foo'");
+  mvaddstr(row++, 0, "--  * restrict to reading only: return is_write == false");
+  mvaddstr(row++, 0, "--  * restrict to files with a fixed prefix: return string.find(filename, 'foo') == 1");
+  mvaddstr(row++, 0, "--  * restrict to files with a fixed extension: return filename:sub(-4) == '.txt'");
+  mvaddstr(row++, 0, "--  * restrict to files under some directory: return string.find(filename, 'foo/') == 1");
+  mvaddstr(row++, 0, "--");
+  mvaddstr(row++, 0, "-- Each of these has benefits and drawbacks.");
+}
+
 static void permissions_view() {
   while (true) {
     render_permissions_screen();