Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[
- Instructions:
- > label set [Displayer Name]
- > pastebin get J6Ss7FZd [Program Name]
- > [Program Name]
- --]]
- local display_data = {}
- function split(inputstr, sep)
- if sep == nil then
- sep = "%s"
- end
- local t={}
- for str in string.gmatch(inputstr, "([^"..sep.."]+)") do
- table.insert(t, str)
- end
- return t
- end
- function updateData(msg)
- local category = msg
- local lines = split(msg, "\n")
- if #lines > 1 then
- display_data[lines[1]] = {unpack(lines, 2, #lines)}
- else
- display_data[lines[1]] = {}
- end
- end
- function getAbsolutePosition(screen_width, screen_height, pane_width, line_number)
- local x = 1
- screen_height = screen_height - 1
- while line_number > screen_height do
- line_number = line_number - screen_height
- x = x + pane_width
- end
- if x + pane_width * 2 > screen_width + 1 then
- return x, line_number + 1, screen_width - x + 1
- else
- return x, line_number + 1, pane_width
- end
- end
- function displayTitle(m, screen_width, str)
- m.setCursorPos(1, 1)
- m.setBackgroundColor(colors.yellow)
- m.setTextColor(colors.black)
- m.write(str..string.rep(" ", screen_width - string.len(str)))
- end
- function displayLabel(m, x, y, length, str)
- length = length - 1
- m.setCursorPos(x, y)
- m.setBackgroundColor(colors.purple)
- m.setTextColor(colors.white)
- m.write(str..string.rep(" ", length - string.len(str)))
- end
- function displayItem(m, x, y, length, leftstr, rightstr, percent)
- leftstr = split(leftstr, ":")[2]
- length = length - 1
- local hlcolor = colors.lime
- if percent < 0.2 then
- hlcolor = colors.red
- elseif percent < 0.5 then
- hlcolor = colors.orange
- end
- hl_len = math.floor(length * percent)
- remain_len = length - string.len(leftstr) - string.len(rightstr)
- local str
- if remain_len > 0 then
- str = leftstr..string.rep(" ", remain_len)..rightstr
- else
- str = string.sub(leftstr, 1, string.len(leftstr) + remain_len - 3)..".. "..rightstr
- end
- m.setCursorPos(x, y)
- m.setBackgroundColor(hlcolor)
- m.setTextColor(colors.white)
- m.write(string.sub(str, 1, hl_len))
- m.setCursorPos(x + hl_len, y)
- m.setBackgroundColor(colors.gray)
- m.setTextColor(colors.white)
- m.write(string.sub(str, hl_len + 1, string.len(str)))
- end
- function displayAll(m, title)
- m.setTextScale(1)
- m.setBackgroundColor(colors.gray)
- m.clear()
- local screen_width, screen_height = m.getSize()
- local pane_width = screen_width / math.floor(screen_width / 30)
- local item_width = pane_width / 2
- local line_number = 1
- displayTitle(m, screen_width, title)
- for category, items in pairs(display_data) do
- local x, y, width = getAbsolutePosition(screen_width, screen_height, pane_width, line_number)
- displayLabel(m, x, y, width, category)
- for i, item in pairs(items) do
- content = split(item, " ")
- if content[3] ~= 0 then
- if (i % 2 == 1) then
- line_number = line_number + 1
- x, y, width = getAbsolutePosition(screen_width, screen_height, pane_width, line_number)
- item_width = math.floor(width / 2)
- displayItem(m, x, y, item_width, content[1], content[2], content[2] / content[3])
- end
- if (i % 2 == 0) then
- item_width = math.floor(width / 2)
- displayItem(m, x + item_width, y, width - item_width, content[1], content[2], content[2] / content[3])
- end
- end
- end
- line_number = line_number + 1
- end
- end
- function main()
- local monitor = peripheral.find("monitor")
- monitor.setTextScale(0.5)
- peripheral.find("modem", rednet.open)
- local id, msg
- while true do
- while not rednet.isOpen() do
- os.sleep(10)
- peripheral.find("modem", rednet.open)
- end
- id, msg = rednet.receive("ITEM_UPDATE")
- updateData(msg)
- displayAll(monitor, os.getComputerLabel())
- end
- end
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement