about summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2021-11-14 07:52:47 -0800
committerKartik K. Agaram <vc@akkartik.com>2021-11-14 07:53:20 -0800
commitb50e393770e7623b725209e1ec3a31586414341b (patch)
treef2e9072115821a2d3692629bb6c2b2634d7695cf
parent12d738d5ce5d73d2cd7b56a22cc0874ec746894e (diff)
downloadteliva-b50e393770e7623b725209e1ec3a31586414341b.tar.gz
draw the browse dialog the same way
-rw-r--r--src/kilo.c2
-rw-r--r--src/lua.c54
2 files changed, 46 insertions, 10 deletions
diff --git a/src/kilo.c b/src/kilo.c
index f3c1437..acbd3dd 100644
--- a/src/kilo.c
+++ b/src/kilo.c
@@ -101,7 +101,7 @@ struct editorConfig {
 
 static struct editorConfig E;
 
-enum KEY_ACTION{
+enum KEY_ACTION {
         KEY_NULL = 0,
         CTRL_C = 3,
         CTRL_D = 4,
diff --git a/src/lua.c b/src/lua.c
index 764c5fa..34c18aa 100644
--- a/src/lua.c
+++ b/src/lua.c
@@ -6,6 +6,7 @@
 
 
 #include <assert.h>
+#include <ctype.h>
 #include <fcntl.h>
 #include <locale.h>
 #include <ncurses.h>
@@ -387,6 +388,20 @@ void editImage (lua_State *L, const char *definition) {
 }
 
 
+extern void draw_menu_item (const char* key, const char* name);
+static void browserMenu (void) {
+  attrset(A_REVERSE);
+  for (int x = 0; x < COLS; ++x)
+    mvaddch(LINES-1, x, ' ');
+  attrset(A_NORMAL);
+  extern int menu_column;
+  menu_column = 2;
+  draw_menu_item("Esc", "go back");
+  draw_menu_item("Enter", "submit");
+  attrset(A_NORMAL);
+}
+
+
 #define BG(i) (COLOR_PAIR((i)+8))
 #define FG(i) (COLOR_PAIR(i))
 void browseDefinition (const char *definition_name) {
@@ -478,15 +493,36 @@ int browseImage (lua_State *L) {
   }
 
   lua_settop(L, 0);
-  attron(A_REVERSE);
-  mvaddstr(LINES-1, 0, " edit what? (hit just Enter to go back) ");
-  attroff(A_REVERSE);
-  addch(' ');
-  char definition[64] = {0};
-  getnstr(definition, 60);
-  if (*definition != '\0')
-    editImage(L, definition);
-  return *definition != '\0';
+
+  enum {
+    ENTER = 10,
+    CTRL_U = 21,
+    ESC = 27,
+  };
+  char query[CURRENT_DEFINITION_LEN+1] = {0};
+  int qlen = 0;
+  while (1) {
+    browserMenu();
+    mvprintw(LINES-2, 0, "Edit: %s", query);
+    int c = getch();
+    if (c == KEY_BACKSPACE) {
+      if (qlen != 0) query[--qlen] = '\0';
+    } else if (c == ESC) {
+      return 0;
+    } else if (c == ENTER) {
+      editImage(L, query);
+      return 1;
+    } else if (c == CTRL_U) {
+      query[0] = '\0';
+      qlen = 0;
+    } else if (isprint(c)) {
+      if (qlen < CURRENT_DEFINITION_LEN) {
+          query[qlen++] = c;
+          query[qlen] = '\0';
+      }
+    }
+  }
+  /* never gets here */
 }
 
 
b126108a25ce92885682bc2'>^
3d566884 ^
e30d16cb ^
3d566884 ^
621a1a39 ^
9bc5d95c ^
c44b726e ^
465bff73 ^




f027adc0 ^
f8e96a97 ^

0b5c4cbe ^
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55