indent
This commit is contained in:
parent
32517f428c
commit
acb5e88b3c
34
chesstv.tlv
34
chesstv.tlv
|
@ -1,11 +1,11 @@
|
|||
teliva_program = {
|
||||
window = [==[
|
||||
window = [==[
|
||||
window = curses.stdscr()
|
||||
-- animation-based app
|
||||
window:nodelay(true)
|
||||
lines, cols = window:getmaxyx()]==],
|
||||
current_game = [==[current_game = {}]==],
|
||||
piece_glyph = [==[
|
||||
current_game = [==[current_game = {}]==],
|
||||
piece_glyph = [==[
|
||||
piece_glyph = {
|
||||
-- for legibility, white pieces also use unicode glyphs for black pieces
|
||||
-- we rely on colors to distinguish them
|
||||
|
@ -22,27 +22,27 @@ piece_glyph = {
|
|||
n = 0x265e,
|
||||
p = 0x265f,
|
||||
}]==],
|
||||
top_player = [==[
|
||||
top_player = [==[
|
||||
function top_player(current_game)
|
||||
if current_game.players[1].color == "black" then
|
||||
return current_game.players[1]
|
||||
end
|
||||
return current_game.players[2]
|
||||
end]==],
|
||||
bottom_player = [==[
|
||||
bottom_player = [==[
|
||||
function bottom_player(current_game)
|
||||
if current_game.players[1].color == "white" then
|
||||
return current_game.players[1]
|
||||
end
|
||||
return current_game.players[2]
|
||||
end]==],
|
||||
render_player = [==[
|
||||
render_player = [==[
|
||||
function render_player(y, x, player)
|
||||
curses.mvaddstr(y, x, player.user.name)
|
||||
curses.addstr(" · ")
|
||||
curses.addstr(tostring(player.rating))
|
||||
end]==],
|
||||
render_square = [==[
|
||||
render_square = [==[
|
||||
function render_square(current_game, rank, file, highlighted_squares)
|
||||
-- decide whether to highlight
|
||||
local hl = 0
|
||||
|
@ -62,7 +62,7 @@ function render_square(current_game, rank, file, highlighted_squares)
|
|||
curses.mvaddstr((8 - rank + 1)*3+2, file*5, " ")
|
||||
curses.attrset(curses.A_NORMAL)
|
||||
end]==],
|
||||
render_fen_rank = [==[
|
||||
render_fen_rank = [==[
|
||||
function render_fen_rank(rank, fen_rank, highlighted_squares)
|
||||
local file = 1
|
||||
for x in fen_rank:gmatch(".") do
|
||||
|
@ -98,13 +98,13 @@ function render_fen_rank(rank, fen_rank, highlighted_squares)
|
|||
end
|
||||
end
|
||||
end]==],
|
||||
render_time = [==[
|
||||
render_time = [==[
|
||||
function render_time(y, x, seconds)
|
||||
if seconds == nil then return end
|
||||
curses.mvaddstr(y, x, tostring(math.floor(seconds/60)))
|
||||
curses.addstr(string.format(":%02d", seconds%60))
|
||||
end]==],
|
||||
render_board = [==[
|
||||
render_board = [==[
|
||||
function render_board(current_game)
|
||||
--? curses.mvaddstr(1, 50, dump(current_game.fen))
|
||||
--? curses.mvaddstr(6, 50, dump(current_game.previously_moved_squares))
|
||||
|
@ -119,7 +119,7 @@ function render_board(current_game)
|
|||
render_player(27, 5, bottom_player(current_game))
|
||||
render_time(27, 35, current_game.wc)
|
||||
end]==],
|
||||
parse_lm = [==[
|
||||
parse_lm = [==[
|
||||
function parse_lm(move)
|
||||
--? curses.mvaddstr(4, 50, move)
|
||||
local file1 = string.byte(move:sub(1, 1)) - 96 -- 'a'-1
|
||||
|
@ -129,7 +129,7 @@ function parse_lm(move)
|
|||
--? curses.mvaddstr(5, 50, dump({{rank1, file1}, {rank2, file2}}))
|
||||
return {from={rank=rank1, file=file1}, to={rank=rank2, file=file2}}
|
||||
end]==],
|
||||
render = [==[
|
||||
render = [==[
|
||||
function render(chunk)
|
||||
local o = json.decode(chunk)
|
||||
if o.t == "featured" then
|
||||
|
@ -149,7 +149,7 @@ function render(chunk)
|
|||
render_board(current_game)
|
||||
curses.refresh()
|
||||
end]==],
|
||||
init_colors = [==[
|
||||
init_colors = [==[
|
||||
function init_colors()
|
||||
-- colors
|
||||
local light_piece = 1
|
||||
|
@ -168,7 +168,7 @@ function init_colors()
|
|||
curses.init_pair(7, light_piece, dark_last_moved_square)
|
||||
curses.init_pair(8, dark_piece, dark_last_moved_square)
|
||||
end]==],
|
||||
main = [==[
|
||||
main = [==[
|
||||
function main()
|
||||
init_colors()
|
||||
local request = {
|
||||
|
@ -184,7 +184,7 @@ function main()
|
|||
}
|
||||
http.request(request)
|
||||
end]==],
|
||||
utf8 = [==[
|
||||
utf8 = [==[
|
||||
-- https://stackoverflow.com/questions/7983574/how-to-write-a-unicode-symbol-in-lua
|
||||
function utf8(decimal)
|
||||
local bytemarkers = { {0x7FF,192}, {0xFFFF,224}, {0x1FFFFF,240} }
|
||||
|
@ -203,7 +203,7 @@ function utf8(decimal)
|
|||
end
|
||||
return table.concat(charbytes)
|
||||
end]==],
|
||||
split = [==[
|
||||
split = [==[
|
||||
function split(s, pat)
|
||||
result = {}
|
||||
for x in s:gmatch(pat) do
|
||||
|
@ -211,7 +211,7 @@ function split(s, pat)
|
|||
end
|
||||
return result
|
||||
end]==],
|
||||
dump = [==[
|
||||
dump = [==[
|
||||
-- https://stackoverflow.com/questions/9168058/how-to-dump-a-table-to-console
|
||||
function dump(o)
|
||||
if type(o) == 'table' then
|
||||
|
|
12
counter.tlv
12
counter.tlv
|
@ -1,7 +1,7 @@
|
|||
teliva_program = {
|
||||
window = [==[window = curses.stdscr()]==],
|
||||
n = [==[n = 0]==],
|
||||
render = [==[
|
||||
window = [==[window = curses.stdscr()]==],
|
||||
n = [==[n = 0]==],
|
||||
render = [==[
|
||||
function render(window)
|
||||
window:clear()
|
||||
window:attron(curses.A_BOLD)
|
||||
|
@ -12,15 +12,15 @@ function render(window)
|
|||
window:attroff(curses.A_BOLD)
|
||||
curses.refresh()
|
||||
end]==],
|
||||
menu = [==[menu = {Enter="increment"}]==],
|
||||
update = [==[
|
||||
menu = [==[menu = {Enter="increment"}]==],
|
||||
update = [==[
|
||||
function update(window)
|
||||
local key = curses.getch()
|
||||
if key == 10 then
|
||||
n = n+1
|
||||
end
|
||||
end]==],
|
||||
main = [==[
|
||||
main = [==[
|
||||
function main()
|
||||
for i=1,7 do
|
||||
curses.init_pair(i, 0, i)
|
||||
|
|
24
hanoi.tlv
24
hanoi.tlv
|
@ -1,5 +1,5 @@
|
|||
teliva_program = {
|
||||
render = [==[
|
||||
render = [==[
|
||||
function render(window)
|
||||
window:clear()
|
||||
local lines, cols = window:getmaxyx()
|
||||
|
@ -10,17 +10,17 @@ function render(window)
|
|||
end
|
||||
curses.refresh()
|
||||
end]==],
|
||||
lines = [==[
|
||||
lines = [==[
|
||||
function lines(window)
|
||||
local lines, cols = window:getmaxyx()
|
||||
return lines
|
||||
end]==],
|
||||
pop = [==[
|
||||
pop = [==[
|
||||
function pop(array)
|
||||
return table.remove(array)
|
||||
end]==],
|
||||
window = [==[window = curses.stdscr()]==],
|
||||
render_tower = [==[
|
||||
window = [==[window = curses.stdscr()]==],
|
||||
render_tower = [==[
|
||||
function render_tower(window, line, col, tower_index, tower)
|
||||
window:attron(curses.A_BOLD)
|
||||
window:mvaddch(line+2, col, string.char(96+tower_index))
|
||||
|
@ -39,8 +39,8 @@ function render_tower(window, line, col, tower_index, tower)
|
|||
line = line - 1
|
||||
end
|
||||
end]==],
|
||||
tower = [==[tower = {{6, 5, 4, 3, 2}, {}, {}}]==],
|
||||
render_disk = [==[
|
||||
tower = [==[tower = {{6, 5, 4, 3, 2}, {}, {}}]==],
|
||||
render_disk = [==[
|
||||
function render_disk(window, line, col, size)
|
||||
col = col-size+1
|
||||
for i=1,size do
|
||||
|
@ -50,7 +50,7 @@ function render_disk(window, line, col, size)
|
|||
col = col+2
|
||||
end
|
||||
end]==],
|
||||
main = [==[
|
||||
main = [==[
|
||||
function main()
|
||||
for i=1,7 do
|
||||
curses.init_pair(i, 0, i)
|
||||
|
@ -62,7 +62,7 @@ function main()
|
|||
end
|
||||
end
|
||||
]==],
|
||||
len = [==[
|
||||
len = [==[
|
||||
function len(array)
|
||||
local result = 0
|
||||
for k in pairs(array) do
|
||||
|
@ -70,7 +70,7 @@ function len(array)
|
|||
end
|
||||
return result
|
||||
end]==],
|
||||
update = [==[
|
||||
update = [==[
|
||||
function update(window)
|
||||
window:mvaddstr(lines(window)-2, 5, "tower to remove top disk from? ")
|
||||
local from = curses.getch() - 96
|
||||
|
@ -78,12 +78,12 @@ function update(window)
|
|||
local to = curses.getch() - 96
|
||||
make_move(from, to)
|
||||
end]==],
|
||||
make_move = [==[
|
||||
make_move = [==[
|
||||
function make_move(from, to)
|
||||
local disk = pop(tower[from])
|
||||
table.insert(tower[to], disk)
|
||||
end]==],
|
||||
cols = [==[
|
||||
cols = [==[
|
||||
function cols(window)
|
||||
local lines, cols = window:getmaxyx()
|
||||
return cols
|
||||
|
|
32
life.tlv
32
life.tlv
|
@ -1,10 +1,10 @@
|
|||
teliva_program = {
|
||||
window = [==[
|
||||
window = [==[
|
||||
window = curses.stdscr()
|
||||
-- animation-based app
|
||||
window:nodelay(true)
|
||||
lines, cols = window:getmaxyx()]==],
|
||||
grid = [==[
|
||||
grid = [==[
|
||||
-- main data structure
|
||||
grid = {}
|
||||
for i=1,lines*4 do
|
||||
|
@ -14,7 +14,7 @@ for i=1,lines*4 do
|
|||
end
|
||||
end
|
||||
]==],
|
||||
grid_char = [==[
|
||||
grid_char = [==[
|
||||
-- grab a 4x2 chunk of grid
|
||||
function grid_char(line, col)
|
||||
result = {}
|
||||
|
@ -23,7 +23,7 @@ function grid_char(line, col)
|
|||
end
|
||||
return result
|
||||
end]==],
|
||||
print_grid_char = [==[
|
||||
print_grid_char = [==[
|
||||
function print_grid_char(window, x)
|
||||
result = {}
|
||||
for l, row in ipairs(x) do
|
||||
|
@ -33,7 +33,7 @@ function print_grid_char(window, x)
|
|||
end
|
||||
return result
|
||||
end]==],
|
||||
glyph = [==[
|
||||
glyph = [==[
|
||||
-- look up the braille pattern corresponding to a 4x2 chunk of grid
|
||||
-- https://en.wikipedia.org/wiki/Braille_Patterns
|
||||
-- not obviously programmatic because Unicode added 4x2 after 3x2
|
||||
|
@ -56,7 +56,7 @@ glyph = {
|
|||
0x28b0, 0x28b1, 0x28b2, 0x28b3, 0x28b4, 0x28b5, 0x28b6, 0x28b7, 0x28f0, 0x28f1, 0x28f2, 0x28f3, 0x28f4, 0x28f5, 0x28f6, 0x28f7,
|
||||
0x28b8, 0x28b9, 0x28ba, 0x28bb, 0x28bc, 0x28bd, 0x28be, 0x28bf, 0x28f8, 0x28f9, 0x28fa, 0x28fb, 0x28fc, 0x28fd, 0x28fe, 0x28ff,
|
||||
}]==],
|
||||
utf8 = [==[
|
||||
utf8 = [==[
|
||||
-- https://stackoverflow.com/questions/7983574/how-to-write-a-unicode-symbol-in-lua
|
||||
function utf8(decimal)
|
||||
local bytemarkers = { {0x7FF,192}, {0xFFFF,224}, {0x1FFFFF,240} }
|
||||
|
@ -75,14 +75,14 @@ function utf8(decimal)
|
|||
end
|
||||
return table.concat(charbytes)
|
||||
end]==],
|
||||
grid_char_to_glyph_index = [==[
|
||||
grid_char_to_glyph_index = [==[
|
||||
-- convert a chunk of grid into a number
|
||||
function grid_char_to_glyph_index(g)
|
||||
return g[1][1] + g[2][1]*2 + g[3][1]*4 + g[4][1]*8 +
|
||||
g[1][2]*16 + g[2][2]*32 + g[3][2]*64 + g[4][2]*128 +
|
||||
1 -- 1-indexing
|
||||
end]==],
|
||||
render = [==[
|
||||
render = [==[
|
||||
function render(window)
|
||||
window:clear()
|
||||
for line=1,lines do
|
||||
|
@ -93,20 +93,20 @@ function render(window)
|
|||
curses.refresh()
|
||||
end
|
||||
]==],
|
||||
state = [==[
|
||||
state = [==[
|
||||
function state(line, col)
|
||||
if line < 1 or line > table.getn(grid) or col < 1 or col > table.getn(grid[1]) then
|
||||
return 0
|
||||
end
|
||||
return grid[line][col]
|
||||
end]==],
|
||||
num_live_neighbors = [==[
|
||||
num_live_neighbors = [==[
|
||||
function num_live_neighbors(line, col)
|
||||
return state(line-1, col-1) + state(line-1, col) + state(line-1, col+1) +
|
||||
state(line, col-1) + state(line, col+1) +
|
||||
state(line+1, col-1) + state(line+1, col) + state(line+1, col+1)
|
||||
end]==],
|
||||
step = [==[
|
||||
step = [==[
|
||||
function step()
|
||||
local new_grid = {}
|
||||
for line=1,table.getn(grid) do
|
||||
|
@ -124,13 +124,13 @@ function step()
|
|||
end
|
||||
grid = new_grid
|
||||
end]==],
|
||||
sleep = [==[
|
||||
sleep = [==[
|
||||
function sleep(a)
|
||||
local sec = tonumber(os.clock() + a);
|
||||
while (os.clock() < sec) do
|
||||
end
|
||||
end]==],
|
||||
file_exists = [==[
|
||||
file_exists = [==[
|
||||
function file_exists(filename)
|
||||
local f = io.open(filename, "r")
|
||||
if f ~= nil then
|
||||
|
@ -140,7 +140,7 @@ function file_exists(filename)
|
|||
return false
|
||||
end
|
||||
end]==],
|
||||
load_file = [==[
|
||||
load_file = [==[
|
||||
function load_file(window, filename)
|
||||
io.input(filename)
|
||||
local line_index = lines
|
||||
|
@ -160,7 +160,7 @@ function load_file(window, filename)
|
|||
end
|
||||
end
|
||||
end]==],
|
||||
update = [==[
|
||||
update = [==[
|
||||
menu = {arrow="pan"}
|
||||
|
||||
function update(window, c)
|
||||
|
@ -198,7 +198,7 @@ function update(window, c)
|
|||
end
|
||||
end
|
||||
end]==],
|
||||
main = [==[
|
||||
main = [==[
|
||||
function main()
|
||||
for i=1,7 do
|
||||
curses.init_pair(i, i, -1)
|
||||
|
|
Loading…
Reference in New Issue