-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhistory.lua
77 lines (63 loc) · 1.46 KB
/
history.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
67
68
69
70
71
72
73
74
75
76
77
local history = {}
local texts = {}
local w, h = term.getSize()
local vh = h - 1
local outputMin = 2
local outputMax = vh
local yOff = #history - vh
local oldYOff = yOff
function print_input(input)
term.setTextColor(colors.purple)
term.setCursorPos(1, h)
term.clearLine()
term.write("> " .. input)
end
function history_print(v)
table.insert(history, v)
yOff = #history - vh
draw()
end
function draw_header()
local avail = get_available_slots()
local max = get_max_slots()
local refresh_char=""
if is_refreshing then
refresh_char = "R"
end
local num = string.format("%s %s / %s", refresh_char, avail, max)
term.setTextColor(colors.purple)
term.setCursorPos(1, 1)
term.clearLine()
term.write("Storage")
term.setCursorPos(w - string.len(num), 1)
term.write(num)
end
function draw()
term.setTextColor(colors.white)
for i = outputMin, outputMax, 1 do
term.setCursorPos(1, i)
term.clearLine()
if history[yOff + i] then
term.write(history[yOff + i])
end
end
-- for i = yOff, vh + yOff, 1 do
-- term.setCursorPos(1, i)
-- term.clearLine()
-- if history[i] then
-- term.write(history[i])
-- end
-- end
end
function scroll(amount)
yOff = yOff + amount
if yOff < 0 then
yOff = 0
elseif yOff + vh > #history then
yOff = #history - vh
end
if oldYOff ~= yOff then
draw()
end
oldYOff = yOff
end