distinguish between window global and arg

This commit is contained in:
Kartik K. Agaram 2022-03-02 22:15:01 -08:00
parent afb3f46db7
commit 68d956e31a
12 changed files with 110 additions and 110 deletions

View File

@ -80,7 +80,7 @@
check_eq:
>function check_eq(x, expected, msg)
> if eq(x, expected) then
> window:addch('.')
> Window:addch('.')
> else
> print('F - '..msg)
> print(' expected '..str(expected)..' but got '..str(x))
@ -207,8 +207,8 @@
> end
>end
- __teliva_timestamp: original
window:
>window = curses.stdscr()
Window:
>Window = curses.stdscr()
- __teliva_timestamp: original
doc:blurb:
>Show all anagrams of a given word
@ -229,8 +229,8 @@
main:
>function main()
> while true do
> render(window)
> update(window)
> render(Window)
> update(Window)
> end
>end
- __teliva_timestamp: original

View File

@ -17,11 +17,11 @@
# If these constraints are violated, Teliva may unceremoniously crash. Please
# report bugs at http://akkartik.name/contact
- __teliva_timestamp: original
window:
>window = curses.stdscr()
Window:
>Window = curses.stdscr()
>-- animation-based app
>window:nodelay(true)
>lines, cols = window:getmaxyx()
>Window:nodelay(true)
>lines, cols = Window:getmaxyx()
- __teliva_timestamp: original
current_game:
>current_game = {}
@ -62,9 +62,9 @@
- __teliva_timestamp: original
render_player:
>function render_player(y, x, player)
> window:mvaddstr(y, x, player.user.name)
> window:addstr(" · ")
> window:addstr(tostring(player.rating))
> Window:mvaddstr(y, x, player.user.name)
> Window:addstr(" · ")
> Window:addstr(tostring(player.rating))
>end
- __teliva_timestamp: original
render_square:
@ -77,15 +77,15 @@
> end
> if (rank+file)%2 == 1 then
> -- light square
> window:attrset(curses.color_pair(1+hl))
> Window:attrset(curses.color_pair(1+hl))
> else
> -- dark square
> window:attrset(curses.color_pair(3+hl))
> Window:attrset(curses.color_pair(3+hl))
> end
> window:mvaddstr((8 - rank + 1)*3, file*5, " ")
> window:mvaddstr((8 - rank + 1)*3+1, file*5, " ")
> window:mvaddstr((8 - rank + 1)*3+2, file*5, " ")
> window:attrset(curses.A_NORMAL)
> Window:mvaddstr((8 - rank + 1)*3, file*5, " ")
> Window:mvaddstr((8 - rank + 1)*3+1, file*5, " ")
> Window:mvaddstr((8 - rank + 1)*3+2, file*5, " ")
> Window:attrset(curses.A_NORMAL)
>end
- __teliva_timestamp: original
render_fen_rank:
@ -104,22 +104,22 @@
> if (rank+file)%2 == 1 then
> if x < 'Z' then
> -- white piece on light square
> window:attrset(curses.color_pair(1+hl))
> Window:attrset(curses.color_pair(1+hl))
> else
> -- black piece on light square
> window:attrset(curses.color_pair(2+hl))
> Window:attrset(curses.color_pair(2+hl))
> end
> else
> if x < 'Z' then
> -- white piece on dark square
> window:attrset(curses.color_pair(3+hl))
> Window:attrset(curses.color_pair(3+hl))
> else
> -- black piece on dark square
> window:attrset(curses.color_pair(4+hl))
> Window:attrset(curses.color_pair(4+hl))
> end
> end
> window:mvaddstr((8 - rank + 1)*3+1, file*5+2, utf8(piece_glyph[x]))
> window:attrset(curses.A_NORMAL)
> Window:mvaddstr((8 - rank + 1)*3+1, file*5+2, utf8(piece_glyph[x]))
> Window:attrset(curses.A_NORMAL)
> file = file + 1
> end
> end
@ -128,14 +128,14 @@
render_time:
>function render_time(y, x, seconds)
> if seconds == nil then return end
> window:mvaddstr(y, x, tostring(math.floor(seconds/60)))
> window:addstr(string.format(":%02d", seconds%60))
> Window:mvaddstr(y, x, tostring(math.floor(seconds/60)))
> Window:addstr(string.format(":%02d", seconds%60))
>end
- __teliva_timestamp: original
render_board:
>function render_board(current_game)
>--? window:mvaddstr(1, 50, dump(current_game.fen))
>--? window:mvaddstr(6, 50, dump(current_game.previously_moved_squares))
>--? Window:mvaddstr(1, 50, dump(current_game.fen))
>--? Window:mvaddstr(6, 50, dump(current_game.previously_moved_squares))
> render_player(2, 5, top_player(current_game))
> render_time(2, 35, current_game.bc)
> for rank=8,1,-1 do
@ -150,12 +150,12 @@
- __teliva_timestamp: original
parse_lm:
>function parse_lm(move)
>--? window:mvaddstr(4, 50, move)
>--? Window:mvaddstr(4, 50, move)
> local file1 = string.byte(move:sub(1, 1)) - 96 -- 'a'-1
> local rank1 = string.byte(move:sub(2, 2)) - 48 -- '0'
> local file2 = string.byte(move:sub(3, 3)) - 96 -- 'a'-1
> local rank2 = string.byte(move:sub(4, 4)) - 48 -- '0'
>--? window:mvaddstr(5, 50, dump({{rank1, file1}, {rank2, file2}}))
>--? Window:mvaddstr(5, 50, dump({{rank1, file1}, {rank2, file2}}))
> return {from={rank=rank1, file=file1}, to={rank=rank2, file=file2}}
>end
- __teliva_timestamp: original
@ -172,12 +172,12 @@
> current_game.bc = o.d.bc
>--? current_game.lm = o.d.lm
> current_game.previously_moved_squares = parse_lm(o.d.lm)
>--? window:nodelay(false)
>--? window:mvaddstr(3, 50, "paused")
>--? Window:nodelay(false)
>--? Window:mvaddstr(3, 50, "paused")
> end
> current_game.fen_rank = split(current_game.fen, "%w+")
> render_board(current_game)
> window:refresh()
> Window:refresh()
>end
- __teliva_timestamp: original
init_colors:
@ -207,9 +207,9 @@
> url = "https://lichess.org/api/tv/feed",
> sink = function(chunk, err)
> if chunk then
> window:clear()
> Window:clear()
> render(chunk)
> window:getch()
> Window:getch()
> end
> return 1
> end,
@ -271,17 +271,17 @@
> url = "https://lichess.org/api/tv/feed",
> sink = function(chunk, err)
> if chunk then
> window:clear()
> Window:clear()
> -- main event loop is here
> render(chunk)
> window:getch()
> Window:getch()
> end
> return 1
> end,
> }
> http.request(request)
> -- degenerate event loop just to show errors in sandboxing, etc.
> while true do window:getch(); end
> while true do Window:getch(); end
>end
- __teliva_timestamp:
>Thu Feb 17 20:00:23 2022

View File

@ -80,7 +80,7 @@
check_eq:
>function check_eq(x, expected, msg)
> if x == expected then
> window:addch('.')
> Window:addch('.')
> else
> print('F - '..msg)
> print(' expected '..tostring(expected)..' but got '..x)
@ -147,8 +147,8 @@
> return result
>end
- __teliva_timestamp: original
window:
>window = curses.stdscr()
Window:
>Window = curses.stdscr()
- __teliva_timestamp: original
render:
>function render(window)
@ -193,7 +193,7 @@
> init_colors()
>
> while true do
> render(window)
> update(window)
> render(Window)
> update(Window)
> end
>end

View File

@ -17,8 +17,8 @@
# If these constraints are violated, Teliva may unceremoniously crash. Please
# report bugs at http://akkartik.name/contact
- __teliva_timestamp: original
window:
>window = curses.stdscr()
Window:
>Window = curses.stdscr()
- __teliva_timestamp: original
n:
>n = 0
@ -55,8 +55,8 @@
> end
>
> while true do
> render(window)
> update(window)
> render(Window)
> update(Window)
> end
>end
- __teliva_timestamp:

View File

@ -80,7 +80,7 @@
check_eq:
>function check_eq(x, expected, msg)
> if x == expected then
> window:addch('.')
> Window:addch('.')
> else
> print('F - '..msg)
> print(' expected '..tostring(expected)..' but got '..x)
@ -167,8 +167,8 @@
> append(target, src)
>end
- __teliva_timestamp: original
window:
>window = curses.stdscr()
Window:
>Window = curses.stdscr()
- __teliva_timestamp: original
render_line:
>function render_line(window, y, line)
@ -377,8 +377,8 @@
> lines = gemini_get(state.url)
> end
> while true do
> render(window, lines)
> update(window, lines)
> render(Window, lines)
> update(Window, lines)
> end
>end
- __teliva_timestamp: original

View File

@ -40,8 +40,8 @@
> return table.remove(array)
>end
- __teliva_timestamp: original
window:
>window = curses.stdscr()
Window:
>Window = curses.stdscr()
- __teliva_timestamp: original
render_tower:
>function render_tower(window, line, col, tower_index, tower)
@ -86,8 +86,8 @@
> curses.init_pair(15, 0, 250) -- tower frames
>
> while true do
> render(window)
> update(window)
> render(Window)
> update(Window)
> end
>end
- __teliva_timestamp: original

View File

@ -27,12 +27,12 @@
> end
>end
- __teliva_timestamp: original
window:
>window = curses.stdscr()
Window:
>Window = curses.stdscr()
>-- animation-based app
>window:nodelay(true)
>Window:nodelay(true)
>curses.curs_set(0)
>lines, cols = window:getmaxyx()
>lines, cols = Window:getmaxyx()
- __teliva_timestamp: original
grid_char:
>-- grab a 4x2 chunk of grid
@ -285,14 +285,14 @@
> --
> -- For example, check out the list of Important Patterns at
> -- https://www.conwaylife.com/wiki/Category:Patterns_with_Catagolue_frequency_class_0
> load_file(window, arg[1])
> load_file(Window, arg[1])
> end
>
> -- main loop
> while true do
> render(window)
> c = window:getch()
> update(window, c)
> render(Window)
> c = Window:getch()
> update(Window, c)
> step()
> end
>end

View File

@ -80,7 +80,7 @@
check_eq:
>function check_eq(x, expected, msg)
> if x == expected then
> window:addch('.')
> Window:addch('.')
> else
> print('F - '..msg)
> print(' expected '..tostring(expected)..' but got '..x)
@ -147,8 +147,8 @@
> return result
>end
- __teliva_timestamp: original
window:
>window = curses.stdscr()
Window:
>Window = curses.stdscr()
- __teliva_timestamp: original
render:
>function render(window)
@ -195,8 +195,8 @@
> init_colors()
>
> while true do
> render(window)
> update(window)
> render(Window)
> update(Window)
> end
>end
- __teliva_timestamp: original

View File

@ -80,7 +80,7 @@
check_eq:
>function check_eq(x, expected, msg)
> if eq(x, expected) then
> window:addch('.')
> Window:addch('.')
> else
> print('F - '..msg)
> print(' expected '..str(expected)..' but got '..str(x))
@ -207,8 +207,8 @@
> end
>end
- __teliva_timestamp: original
window:
>window = curses.stdscr()
Window:
>Window = curses.stdscr()
- __teliva_timestamp: original
render:
>function render(window)
@ -255,8 +255,8 @@
> init_colors()
>
> while true do
> render(window)
> update(window)
> render(Window)
> update(Window)
> end
>end
- __teliva_timestamp: original
@ -271,7 +271,7 @@
> task.spawn(main_task)
> task.scheduler()
> print('out of scheduler')
> window:getch()
> Window:getch()
>end
- __teliva_timestamp:
>Sat Feb 26 21:50:11 2022
@ -362,13 +362,13 @@
>infinite primes
main:
>function main()
> window:nodelay(true)
> window:clear()
> task.spawn(main_task, window)
> Window:nodelay(true)
> Window:clear()
> task.spawn(main_task, Window)
> task.scheduler()
> print('key pressed; done')
> window:nodelay(false)
> window:getch()
> Window:nodelay(false)
> Window:getch()
>end
- __teliva_timestamp:
>Sat Feb 26 22:09:47 2022

View File

@ -80,7 +80,7 @@
check_eq:
>function check_eq(x, expected, msg)
> if eq(x, expected) then
> window:addch('.')
> Window:addch('.')
> else
> print('F - '..msg)
> print(' expected '..str(expected)..' but got '..str(x))
@ -207,8 +207,8 @@
> end
>end
- __teliva_timestamp: original
window:
>window = curses.stdscr()
Window:
>Window = curses.stdscr()
- __teliva_timestamp: original
render:
>function render(window)
@ -255,8 +255,8 @@
> init_colors()
>
> while true do
> render(window)
> update(window)
> render(Window)
> update(Window)
> end
>end
- __teliva_timestamp: original

View File

@ -80,7 +80,7 @@
check_eq:
>function check_eq(x, expected, msg)
> if x == expected then
> window:addch('.')
> Window:addch('.')
> else
> print('F - '..msg)
> print(' expected '..tostring(expected)..' but got '..x)
@ -147,8 +147,8 @@
> return result
>end
- __teliva_timestamp: original
window:
>window = curses.stdscr()
Window:
>Window = curses.stdscr()
>curses.curs_set(0) -- we'll simulate our own cursor
- __teliva_timestamp: original
menu:
@ -162,8 +162,8 @@
> init_colors()
>
> while true do
> render(window)
> update(window)
> render(Window)
> update(Window)
> end
>end
- __teliva_timestamp: original

40
zet.tlv
View File

@ -80,7 +80,7 @@
check_eq:
>function check_eq(x, expected, msg)
> if x == expected then
> window:addch('.')
> Window:addch('.')
> else
> print('F - '..msg)
> print(' expected '..tostring(expected)..' but got '..x)
@ -150,12 +150,12 @@
spaces:
>function spaces(n)
> for i=1,n do
> window:addch(' ')
> Window:addch(' ')
> end
>end
- __teliva_timestamp: original
window:
>window = curses.stdscr()
Window:
>Window = curses.stdscr()
- __teliva_timestamp: original
menu:
>-- To show app-specific hotkeys in the menu bar, add hotkey/command
@ -182,8 +182,8 @@
> current_zettel_id = zettels.root
>
> while true do
> render(window)
> update(window)
> render(Window)
> update(Window)
> end
>end
- __teliva_timestamp: original
@ -389,7 +389,7 @@
>}
- __teliva_timestamp: original
editz:
>function editz()
>function editz(window)
> menu = { {'^e', 'back to browsing'},}
> local top = (render_state.curr_h - 1) * (view_settings.height + view_settings.vmargin)
> local bottom = top + view_settings.height
@ -752,8 +752,8 @@
>
> curses.curs_set(0)
> while true do
> render(window)
> update(window)
> render(Window)
> update(Window)
> end
>end
- __teliva_timestamp:
@ -763,7 +763,7 @@
>
>There's a reason vim hides it. Confusing to have two cursors on screen.
editz:
>function editz()
>function editz(window)
> menu = { {'^e', 'back to browsing'},}
> local top = (render_state.curr_h - 1) * (view_settings.height + view_settings.vmargin)
> local bottom = top + view_settings.height
@ -824,7 +824,7 @@
- __teliva_timestamp:
>Wed Feb 9 08:25:05 2022
editz:
>function editz()
>function editz(window)
> local old_menu = menu
> menu = { {'^e', 'back to browsing'},}
> local top = (render_state.curr_h - 1) * (view_settings.height + view_settings.vmargin)
@ -1378,8 +1378,8 @@
> current_zettel_id = zettels.root
>
> while true do
> render(window)
> update(window)
> render(Window)
> update(Window)
>
> -- save zettels, but hold on to previous state on disk
> -- until last possible second
@ -1407,8 +1407,8 @@
> current_zettel_id = zettels.root
>
> while true do
> render(window)
> update(window)
> render(Window)
> update(Window)
>
> -- save zettels, but hold on to previous state on disk
> -- until last possible second
@ -1938,8 +1938,8 @@
> view_settings.first_zettel = zettels.root -- start rendering here
>
> while true do
> render(window)
> update(window)
> render(Window)
> update(Window)
>
> -- save zettels, but hold on to previous state on disk
> -- until last possible second
@ -2353,8 +2353,8 @@
> view_settings.first_zettel = zettels.root -- start rendering here
>
> while true do
> render(window)
> update(window)
> render(Window)
> update(Window)
>
> -- save zettels, but hold on to previous state on disk
> -- until last possible second
@ -2554,7 +2554,7 @@
- __teliva_timestamp:
>Sat Feb 12 15:11:33 2022
editz:
>function editz()
>function editz(window)
> local old_menu = menu
> menu = {
> {'^e', 'finish edit'},