From 68d956e31af9f4230b6a6ecfa9a53b5513d408aa Mon Sep 17 00:00:00 2001 From: "Kartik K. Agaram" Date: Wed, 2 Mar 2022 22:15:01 -0800 Subject: [PATCH] distinguish between window global and arg --- anagrams.tlv | 10 ++++---- chesstv.tlv | 66 +++++++++++++++++++++++++-------------------------- commander.tlv | 10 ++++---- counter.tlv | 8 +++---- gemini.tlv | 10 ++++---- hanoi.tlv | 8 +++---- life.tlv | 16 ++++++------- lisp.tlv | 10 ++++---- sieve.tlv | 22 ++++++++--------- template.tlv | 10 ++++---- toot-toot.tlv | 10 ++++---- zet.tlv | 40 +++++++++++++++---------------- 12 files changed, 110 insertions(+), 110 deletions(-) diff --git a/anagrams.tlv b/anagrams.tlv index 3dc1734..9a20f26 100644 --- a/anagrams.tlv +++ b/anagrams.tlv @@ -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 diff --git a/chesstv.tlv b/chesstv.tlv index 861b1fb..74acefd 100644 --- a/chesstv.tlv +++ b/chesstv.tlv @@ -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 diff --git a/commander.tlv b/commander.tlv index 73709a2..5416f64 100644 --- a/commander.tlv +++ b/commander.tlv @@ -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 diff --git a/counter.tlv b/counter.tlv index ccdcb0f..f8a34f8 100644 --- a/counter.tlv +++ b/counter.tlv @@ -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: diff --git a/gemini.tlv b/gemini.tlv index 55b8a02..ed0cad7 100644 --- a/gemini.tlv +++ b/gemini.tlv @@ -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 diff --git a/hanoi.tlv b/hanoi.tlv index ffb092d..6794558 100644 --- a/hanoi.tlv +++ b/hanoi.tlv @@ -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 diff --git a/life.tlv b/life.tlv index e592669..12b44d2 100644 --- a/life.tlv +++ b/life.tlv @@ -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 diff --git a/lisp.tlv b/lisp.tlv index 0bfd93c..92d23f8 100644 --- a/lisp.tlv +++ b/lisp.tlv @@ -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 diff --git a/sieve.tlv b/sieve.tlv index ae70bfe..ef2c661 100644 --- a/sieve.tlv +++ b/sieve.tlv @@ -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 diff --git a/template.tlv b/template.tlv index 1d5dd05..a0aa31a 100644 --- a/template.tlv +++ b/template.tlv @@ -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 diff --git a/toot-toot.tlv b/toot-toot.tlv index 6c99a21..8d03654 100644 --- a/toot-toot.tlv +++ b/toot-toot.tlv @@ -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 diff --git a/zet.tlv b/zet.tlv index 73c0893..7a718aa 100644 --- a/zet.tlv +++ b/zet.tlv @@ -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'},