consistent style

This commit is contained in:
Kartik K. Agaram 2021-11-23 22:02:22 -08:00
parent c28174bdf5
commit 32517f428c
2 changed files with 23 additions and 16 deletions

View File

@ -11,8 +11,7 @@ function render(window)
window:attroff(curses.color_pair(6)) window:attroff(curses.color_pair(6))
window:attroff(curses.A_BOLD) window:attroff(curses.A_BOLD)
curses.refresh() curses.refresh()
end end]==],
]==],
menu = [==[menu = {Enter="increment"}]==], menu = [==[menu = {Enter="increment"}]==],
update = [==[ update = [==[
function update(window) function update(window)
@ -20,8 +19,7 @@ function update(window)
if key == 10 then if key == 10 then
n = n+1 n = n+1
end end
end end]==],
]==],
main = [==[ main = [==[
function main() function main()
for i=1,7 do for i=1,7 do
@ -32,6 +30,5 @@ function main()
render(window) render(window)
update(window) update(window)
end end
end end]==],
]==],
} }

View File

@ -1,5 +1,6 @@
teliva_program = { teliva_program = {
render = [==[function render(window) render = [==[
function render(window)
window:clear() window:clear()
local lines, cols = window:getmaxyx() local lines, cols = window:getmaxyx()
local line = math.floor(lines/2) local line = math.floor(lines/2)
@ -9,15 +10,18 @@ teliva_program = {
end end
curses.refresh() curses.refresh()
end]==], end]==],
lines = [==[function lines(window) lines = [==[
function lines(window)
local lines, cols = window:getmaxyx() local lines, cols = window:getmaxyx()
return lines return lines
end]==], end]==],
pop = [==[function pop(array) pop = [==[
function pop(array)
return table.remove(array) return table.remove(array)
end]==], end]==],
window = [==[window = curses.stdscr()]==], window = [==[window = curses.stdscr()]==],
render_tower = [==[function render_tower(window, line, col, tower_index, tower) render_tower = [==[
function render_tower(window, line, col, tower_index, tower)
window:attron(curses.A_BOLD) window:attron(curses.A_BOLD)
window:mvaddch(line+2, col, string.char(96+tower_index)) window:mvaddch(line+2, col, string.char(96+tower_index))
window:attroff(curses.A_BOLD) window:attroff(curses.A_BOLD)
@ -36,7 +40,8 @@ end]==],
end end
end]==], end]==],
tower = [==[tower = {{6, 5, 4, 3, 2}, {}, {}}]==], tower = [==[tower = {{6, 5, 4, 3, 2}, {}, {}}]==],
render_disk = [==[function render_disk(window, line, col, size) render_disk = [==[
function render_disk(window, line, col, size)
col = col-size+1 col = col-size+1
for i=1,size do for i=1,size do
window:attron(curses.color_pair(size)) window:attron(curses.color_pair(size))
@ -45,7 +50,8 @@ end]==],
col = col+2 col = col+2
end end
end]==], end]==],
main = [==[function main() main = [==[
function main()
for i=1,7 do for i=1,7 do
curses.init_pair(i, 0, i) curses.init_pair(i, 0, i)
end end
@ -56,25 +62,29 @@ end]==],
end end
end end
]==], ]==],
len = [==[function len(array) len = [==[
function len(array)
local result = 0 local result = 0
for k in pairs(array) do for k in pairs(array) do
result = result+1 result = result+1
end end
return result return result
end]==], end]==],
update = [==[function update(window) update = [==[
function update(window)
window:mvaddstr(lines(window)-2, 5, "tower to remove top disk from? ") window:mvaddstr(lines(window)-2, 5, "tower to remove top disk from? ")
local from = curses.getch() - 96 local from = curses.getch() - 96
window:mvaddstr(lines(window)-1, 5, "tower to stack it on? ") window:mvaddstr(lines(window)-1, 5, "tower to stack it on? ")
local to = curses.getch() - 96 local to = curses.getch() - 96
make_move(from, to) make_move(from, to)
end]==], end]==],
make_move = [==[function make_move(from, to) make_move = [==[
function make_move(from, to)
local disk = pop(tower[from]) local disk = pop(tower[from])
table.insert(tower[to], disk) table.insert(tower[to], disk)
end]==], end]==],
cols = [==[function cols(window) cols = [==[
function cols(window)
local lines, cols = window:getmaxyx() local lines, cols = window:getmaxyx()
return cols return cols
end]==], end]==],