aboutsummaryrefslogtreecommitdiffstats
path: root/test/test.lua
blob: c8514adddabd7b0f3bde7196dc148714aa4c5be8 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
require "curses"
require "signal"

local function cleanup(sig)
    curses.clear()
    curses.endwin()
    if sig then
        signal.signal(sig, "default")
        signal.raise(sig)
    end
end
curses.initscr()
signal.signal("INT", cleanup)
signal.signal("TERM", cleanup)
curses.start_color()
curses.setup_term{nl = false, cbreak = true, echo = false, keypad = true}
local colors = {"black", "green", "red", "cyan", "white", "magenta", "blue", "yellow"}
for _, color in ipairs(colors) do
    curses.init_pair(color, color)
end

local x, y = 0, 0
local maxy, maxx = curses.getmaxyx()
while true do
    local c = curses.getch()
    if c == "left" and x > 0 then
        x = x - 1
    elseif c == "right" and x < maxx - 1 then
        x = x + 1
    elseif c == "up" and y > 0 then
        y = y - 1
    elseif c == "down" and y < maxy - 1 then
        y = y + 1
    elseif #c == 1 then
        curses.addch(c, {color = colors[math.random(#colors)]})
    end
    curses.move(y, x)
end