-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexample02.lua
52 lines (41 loc) · 1.19 KB
/
example02.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
local nocurses = require("nocurses")
local function printf(...)
io.write(string.format(...))
io.flush()
end
local width, height = nocurses.gettermsize()
local redisplay = true
local counter = 0
while true do
if redisplay then
nocurses.clrscr();
counter = counter + 1
local message = string.format("Hello World! (%d)", counter)
local x = math.floor((width - #message) / 2)
local y = math.floor(height / 2)
nocurses.gotoxy(x, y)
nocurses.setfontbold(true)
nocurses.setunderline(true)
printf(message)
nocurses.gotoxy(1, height - 1)
nocurses.resetcolors()
nocurses.setinvert(true)
nocurses.clrline()
printf("Press q to Quit")
nocurses.resetcolors()
redisplay = false
end
local c = nocurses.getch() -- might be nil if terminal size changes
c = c and string.char(c)
local w, h = nocurses.gettermsize()
if w ~= width or h ~= height then
width, height = w, h
redisplay = true
end
if c == "Q" or c == "q" then
break
end
end
nocurses.gotoxy(1, height - 2)
nocurses.clrline()
printf("Finished.\n")