Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- os.loadAPI('apis.lua')
- Peripheral.wrap('wireless_modem')
- local ids = { }
- Logger.disable()
- local terminal = UI.term
- if Peripheral.isPresent('openperipheral_glassesbridge') then
- terminal = UI.Glasses({
- height = 40,
- width = 64,
- textScale = .5,
- backgroundOpacity = .75
- })
- terminal:clear()
- elseif Peripheral.isPresent('monitor') then
- terminal = UI.Device({
- deviceType = 'monitor',
- textScale = .5
- })
- end
- terminal:clear()
- local window = UI.Window({ parent = terminal })
- function getClient(id)
- if not ids[id] then
- ids[id] = {
- titleBar = UI.TitleBar({ title = 'ID: ' .. id, parent = window }),
- scrollingText = UI.ScrollingText({ parent = window })
- }
- local clientCount = Util.size(ids)
- local clientHeight = math.floor((terminal.height - clientCount) / clientCount)
- window:clear()
- local y = 1
- for k,v in pairs(ids) do
- v.titleBar.y = y
- y = y + 1
- v.scrollingText.height = clientHeight
- v.scrollingText.y = y
- y = y + clientHeight
- v.scrollingText:clear()
- v.titleBar:draw()
- v.scrollingText:draw()
- end
- end
- return ids[id]
- end
- Message.addHandler('log', function(h, id, msg)
- local client = getClient(id)
- client.scrollingText:write(string.format('%d %s', os.time()*1000, msg.contents))
- end)
- Event.addHandler('monitor_touch', function()
- terminal:clear()
- ids = { }
- end)
- Event.addHandler('char', function()
- Event.exitPullEvents()
- end)
- Message.addHandler('logClient', function(h, id)
- Message.send(id, 'logServer')
- end)
- Event.pullEvents()
- UI.term:reset()
Add Comment
Please, Sign In to add comment