-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpanel.lua
More file actions
60 lines (56 loc) · 1.29 KB
/
panel.lua
File metadata and controls
60 lines (56 loc) · 1.29 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
-- http://pastebin.com/aibwRhj1
local mainTerm = term.current()
function setTerm(t)
mainTerm = t
end
function redirect()
term.redirect(mainTerm)
end
function new(x, y, w, h, textColor, backgroundColor, blink)
-- get term size for relative positioning
local width, height = term.getSize()
if type(x) == "table" then
-- named parameters passed in
local o = x
x = o.x or 1
y = o.y or 1
w = o.w or width
h = o.h or height
textColor = o.textColor or colors.white
backgroundColor = o.backgroundColor or colors.black
blink = o.blink ~= nil and o.blink or true
end
-- translate negative values to distance from end
if x < 0 then
x = width + x + 1
end
if y < 0 then
y = height + y + 1
end
if w < 0 then
w = width + w + 1
end
if h < 0 then
h = height + h + 1
end
if textColor == nil then
textColor = colors.white
end
if backgroundColor == nil then
backgroundColor = colors.black
end
if blink == nil then
blink = true
end
local win = window.create(mainTerm, x, y, w, h)
win.setTextColor(textColor)
win.setBackgroundColor(backgroundColor)
win.setCursorBlink(blink)
win.redirect = function()
term.redirect(win)
end
local prevTerm = term.redirect(win)
term.clear()
term.redirect(prevTerm)
return win
end