-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathui.lua
More file actions
75 lines (64 loc) · 1.96 KB
/
ui.lua
File metadata and controls
75 lines (64 loc) · 1.96 KB
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
67
68
69
70
71
72
73
74
75
-- ui.lua
-- Provides various user interface helpers for terminal output.
local UI = {}
----------------------------------------
-- Clear screen and reset cursor
----------------------------------------
function UI.clearScreen()
term.clear()
term.setCursorPos(1, 1)
end
----------------------------------------
-- Blink three lines of text simultaneously
-- at positions (y), (y+1), (y+2).
-- Accepts a "blinkFlagRef" table whose [1]
-- can be set to false to stop blinking.
----------------------------------------
function UI.blinkTextSimultaneous(text1, text2, text3, y, blinkFlagRef, showTime, hideTime)
while blinkFlagRef[1] do
-- Show lines
for i, t in ipairs({text1, text2, text3}) do
term.setCursorPos(1, y + (i - 1))
term.clearLine()
term.write(t)
end
sleep(showTime)
-- Hide lines
for i = 0, 2 do
term.setCursorPos(1, y + i)
term.clearLine()
end
sleep(hideTime)
end
end
----------------------------------------
-- Countdown function with optional color changes
----------------------------------------
function UI.startCountdown(startValue, x, y)
local isColor = term.isColor and term.isColor()
for i = startValue, 0, -1 do
term.setCursorPos(x, y)
term.clearLine()
-- If advanced terminal, color for final 3 seconds
if isColor and i <= 3 then
term.setTextColor(colors.red)
end
term.write("Countdown: " .. i .. " seconds remaining")
if isColor then
term.setTextColor(colors.white)
end
sleep(1)
end
term.setCursorPos(x, y)
term.clearLine()
term.write("Countdown complete!")
end
----------------------------------------
-- Prompt user with a question and read input
----------------------------------------
function UI.prompt(promptText)
term.clearLine()
term.write(promptText)
return read()
end
return UI