aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKartik K. Agaram <vc@akkartik.com>2021-12-22 00:24:59 -0800
committerKartik K. Agaram <vc@akkartik.com>2021-12-22 00:27:50 -0800
commit343316dcfa7cb1872d3082d88d3811896f6ee2c1 (patch)
treee07bc4816b96d82c9d9f9c9c55a42ee7fd2636dc
parentc537e7bc2d55fbc46a77f3e8e4f207acd522ea82 (diff)
downloadteliva-343316dcfa7cb1872d3082d88d3811896f6ee2c1.tar.gz
more precise control over menu order
I can't believe I didn't notice this until now.
-rw-r--r--counter.tlv4
-rw-r--r--gemini.tlv11
-rw-r--r--life.tlv2
-rw-r--r--src/menu.c12
-rw-r--r--template.tlv2
-rw-r--r--toot-toot.tlv7
6 files changed, 26 insertions, 12 deletions
diff --git a/counter.tlv b/counter.tlv
index b709ccc..abecaea 100644
--- a/counter.tlv
+++ b/counter.tlv
@@ -37,7 +37,9 @@
__teliva_note: foo
- __teliva_timestamp: original
menu:
- >menu = {Enter="increment"}
+ >menu = {
+ > {"Enter", "increment"}
+ >}
- __teliva_timestamp: original
update:
>function update(window)
diff --git a/gemini.tlv b/gemini.tlv
index 79099a1..441824a 100644
--- a/gemini.tlv
+++ b/gemini.tlv
@@ -234,11 +234,12 @@
>end
- __teliva_timestamp: original
menu:
- >menu = {}
- >menu['enter'] = 'go to highlight'
- >menu['←'] = 'back'
- >menu['^g'] = 'enter url'
- >menu['^u'] = 'view source'
+ >menu = {
+ > {'Enter', 'go to highlight'},
+ > {'<-', 'back'},
+ > {'^g', 'enter url'},
+ > {'^u', 'view source'},
+ >}
- __teliva_timestamp: original
edit_line:
>function edit_line(window)
diff --git a/life.tlv b/life.tlv
index 143de31..a98c84b 100644
--- a/life.tlv
+++ b/life.tlv
@@ -194,7 +194,7 @@
>end
- __teliva_timestamp: original
update:
- >menu = {arrow="pan"}
+ >menu = {{"arrow", "pan"}}
>
>function update(window, c)
> if c == curses.KEY_LEFT then
diff --git a/src/menu.c b/src/menu.c
index b02c522..72f95ba 100644
--- a/src/menu.c
+++ b/src/menu.c
@@ -2,6 +2,7 @@
#include <string.h>
#include "lua.h"
+#include "lauxlib.h"
#include "teliva.h"
@@ -32,9 +33,16 @@ void draw_menu (lua_State *L) {
/* render any app-specific items */
lua_getglobal(L, "menu");
int table = lua_gettop(L);
- if (lua_istable(L, -1))
- for (lua_pushnil(L); lua_next(L, table) != 0; lua_pop(L, 1))
+ if (lua_istable(L, -1)) {
+ for (int i = 1; i <= luaL_getn(L, table); ++i) {
+ lua_rawgeti(L, table, i);
+ int menu_item = lua_gettop(L);
+ lua_rawgeti(L, menu_item, 1); /* key */
+ lua_rawgeti(L, menu_item, 2); /* value */
draw_menu_item(lua_tostring(L, -2), lua_tostring(L, -1));
+ lua_pop(L, 3);
+ }
+ }
lua_pop(L, 1);
attrset(A_NORMAL);
diff --git a/template.tlv b/template.tlv
index 1275906..1160bcc 100644
--- a/template.tlv
+++ b/template.tlv
@@ -165,6 +165,8 @@
>end
- __teliva_timestamp: original
menu:
+ >-- To show app-specific hotkeys in the menu bar, add hotkey/command
+ >-- arrays of strings to the menu array.
>menu = {}
- __teliva_timestamp: original
update:
diff --git a/toot-toot.tlv b/toot-toot.tlv
index 5c4d897..c371ba3 100644
--- a/toot-toot.tlv
+++ b/toot-toot.tlv
@@ -165,9 +165,10 @@
>end
- __teliva_timestamp: original
menu:
- >menu = {}
- >menu['^u'] = 'clear'
- >menu['^w'] = "write prose to file 'toot' (edit does NOT save)"
+ >menu = {
+ > {'^u', 'clear'},
+ > {'^w', 'write prose to file "toot" (edit hotkey does NOT save)'},
+ >}
- __teliva_timestamp: original
update:
>function update(window)