-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexample05.lua
66 lines (52 loc) · 1.61 KB
/
example05.lua
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
local nocurses = require("nocurses")
local function printf(...)
io.write(string.format(...))
io.flush()
end
local screenWidth, screenHeight = nocurses.gettermsize()
local redisplay = true
local value = 0
local function printCentered(y, ...)
local message = string.format(...)
local x = math.floor((screenWidth - #message) / 2)
if x < 1 then x = 1 end
nocurses.gotoxy(x, y)
printf(message)
end
nocurses.hidecursor()
while true do
if redisplay then
nocurses.clrscr();
local y = math.floor(screenHeight / 2)
printCentered(y, "Value = %d", value)
printCentered(y+1, "(use arrow keys to increase/decrease value, press q to Quit)")
nocurses.gotoxy(1, screenHeight - 1)
redisplay = false
end
local key = nocurses.getkey() -- might be nil if terminal size changes
local w, h = nocurses.gettermsize()
if w ~= screenWidth or h ~= screenHeight then
screenWidth, screenHeight = w, h
redisplay = true
end
if key then
if key == "Q" or key == "q" then
break
elseif key == "Up" then
value = value + 10
elseif key == "Down" then
value = value - 10
elseif key == "Right" then
value = value + 1
elseif key == "Left" then
value = value - 1
else
print(inp)
end
redisplay = true
end
end
nocurses.showcursor()
nocurses.gotoxy(1, screenHeight - 2)
nocurses.clrline()
printf("Finished.\n")