-
-
Notifications
You must be signed in to change notification settings - Fork 28
/
EXAMPLE.lua
executable file
·66 lines (60 loc) · 1.55 KB
/
EXAMPLE.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 monitorSide = "left"
if peripheral.isPresent(monitorSide) and peripheral.getType(monitorSide) == "monitor" then
term.redirect(peripheral.wrap(monitorSide))
else
print("No monitor found")
return
end
function explode(inSplitPattern, str)
local outResults = { }
local theStart = 1
local theSplitStart, theSplitEnd = string.find( str, inSplitPattern, theStart )
while theSplitStart do
local sub = string.sub( str, theStart, theSplitStart-1 )
table.insert( outResults, sub)
theStart = theSplitEnd + 1
theSplitStart, theSplitEnd = string.find( str, inSplitPattern, theStart )
end
table.insert( outResults, string.sub( str, theStart ) )
return outResults
end
function printColouredBars(str, first)
parts = explode("|", str)
local l = #parts
for k = 1, l do
if first then
term.setTextColor(colors.blue)
end
io.write(parts[k])
if first then
term.setTextColor(colors.white)
end
if k ~= l then
term.setTextColor(colors.red)
io.write("|")
term.setTextColor(colors.white)
end
end
end
function profile()
local file = fs.open("profile.txt", "r")
local text = file.readAll()
file.close()
local tables = explode("\n\n", text)
term.clear()
local i, j
for i = 1, #tables do
lines = explode("\n", tables[i] .. "")
for j = 1, #lines do
printColouredBars(lines[j] .. "\n", j == 1)
end
if i ~= #tables then
io.write("\n")
end
end
end
while true do
sleep(60)
profile()
end
term.restore()