more precise control over menu order

I can't believe I didn't notice this until now.
This commit is contained in:
Kartik K. Agaram 2021-12-22 00:24:59 -08:00
parent c537e7bc2d
commit 343316dcfa
6 changed files with 26 additions and 12 deletions

View File

@ -37,7 +37,9 @@
__teliva_note: foo
- __teliva_timestamp: original
menu:
>menu = {Enter="increment"}
>menu = {
> {"Enter", "increment"}
>}
- __teliva_timestamp: original
update:
>function update(window)

View File

@ -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)

View File

@ -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

View File

@ -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);

View File

@ -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:

View File

@ -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)