diff options
author | Kartik K. Agaram <vc@akkartik.com> | 2021-11-30 15:01:31 -0800 |
---|---|---|
committer | Kartik K. Agaram <vc@akkartik.com> | 2021-11-30 15:02:09 -0800 |
commit | 51ba37665cbfd72e6fc4df4c62c969e75d9c2fd1 (patch) | |
tree | 7e73fab83a825ce805e5686dadd14b72a985350c | |
parent | f5a6f434c58262d45d193f4a361013f12a7ac0c8 (diff) | |
download | teliva-51ba37665cbfd72e6fc4df4c62c969e75d9c2fd1.tar.gz |
some little shortcuts for Advent of Code
https://archive.org/details/akkartik-teliva-2021-11-30
-rw-r--r-- | advent.tlv | 159 |
1 files changed, 159 insertions, 0 deletions
diff --git a/advent.tlv b/advent.tlv new file mode 100644 index 0000000..08834f4 --- /dev/null +++ b/advent.tlv @@ -0,0 +1,159 @@ +teliva_program = { + { + __teliva_timestamp = [==[ +original]==], + norm = [==[ +function norm() + window:attrset(curses.A_NORMAL) +end]==], + }, + { + __teliva_timestamp = [==[ +original]==], + bold = [==[ +function bold() + window:attron(curses.A_BOLD) +end]==], + }, + { + __teliva_timestamp = [==[ +original]==], + rv = [==[ +function rv() + window:attron(curses.A_REVERSE) +end]==], + }, + { + __teliva_timestamp = [==[ +original]==], + color = [==[ +function color(i) + window:attron(curses.color_pair(i)) +end]==], + }, + { + __teliva_timestamp = [==[ +original]==], + abbreviations = [==[ +clear = curses.clear +refresh = curses.refresh +getch = curses.getch +addch = curses.addch +mvaddch = curses.mvaddch +pr = curses.addstr +mpr = curses.mvaddstr +str = tostring +num = tonumber +]==], + }, + { + __teliva_timestamp = [==[ +original]==], + str_helpers = [==[ +-- some string helpers from http://lua-users.org/wiki/StringIndexing + +-- index characters using [] +getmetatable('').__index = function(str,i) + if type(i) == 'number' then + return string.sub(str,i,i) + else + return string[i] + end +end + +-- ranges using (), selected bytes using {} +getmetatable('').__call = function(str,i,j) + if type(i)~='table' then + return string.sub(str,i,j) + else + local t={} + for k,v in ipairs(i) do + t[k]=string.sub(str,v,v) + end + return table.concat(t) + end +end + +-- iterate over an ordered sequence +function q(x) + if type(x) == 'string' then + return x:gmatch('.') + else + return ipairs(x) + end +end + +-- TODO: backport utf-8 support from Lua 5.3 +]==], + }, + { + __teliva_timestamp = [==[ +original]==], + window = [==[ +window = curses.stdscr()]==], + }, + { + __teliva_timestamp = [==[ +original]==], + render = [==[ +function render(window) + clear() + -- draw stuff to screen here + bold() + mvaddstr(1, 5, "example app") + norm() + for i=0,15 do + color(i) + mvaddstr(3+i, 5, "========================") + end + refresh() +end]==], + }, + { + __teliva_timestamp = [==[ +original]==], + menu = [==[ +menu = {}]==], + }, + { + __teliva_timestamp = [==[ +original]==], + update = [==[ +function update(window) + local key = curses.getch() + -- process key here +end]==], + }, + { + __teliva_timestamp = [==[ +original]==], + init_colors = [==[ +function init_colors() + for i=0,7 do + curses.init_pair(i, i, -1) + end + curses.init_pair(8, 7, 0) + curses.init_pair(9, 7, 1) + curses.init_pair(10, 7, 2) + curses.init_pair(11, 7, 3) + curses.init_pair(12, 7, 4) + curses.init_pair(13, 7, 5) + curses.init_pair(14, 7, 6) + curses.init_pair(15, -1, 15) +end]==], + }, + { + main = [==[ +function main() + init_colors() + + while true do + render(window) + update(window) + end +end +]==], + __teliva_timestamp = [==[ +original]==], + }, +} |