Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local monitor = peripheral.find("monitor")
- if monitor then
- monitor.setTextScale(1)
- term.redirect(monitor)
- end
- local maxX,maxY = term.getSize()
- local scroll = 0
- shell.openTab("sh")
- local function refresh_log()
- local file = fs.open("disk/latest.log","r")
- if not file then return end
- for i=1,scroll do
- file.readLine()
- end
- term.clear()
- term.setCursorPos(1,1)
- local color = colors.green
- for i=1,maxY do
- local str = file.readLine()
- term.setTextColor(color)
- if str then print(str) end
- if color == colors.green then color = colors.yellow else color = colors.green end
- end
- if file.readLine() then
- term.setTextColor(colors.white)
- term.setCursorPos(maxX,maxY)
- term.write("v")
- end
- if scroll > 0 then
- term.setTextColor(colors.white)
- term.setCursorPos(maxX,1)
- term.write("^")
- end
- file.close()
- end
- local function countLines()
- local file = fs.open("disk/latest.log","r")
- if not file then return end
- local str = file.readAll() or ""
- local _,count = str:gsub("\n","")
- return count
- end
- local function ui_refresh()
- os.startTimer(5)
- while true do
- local e,a,b,c = os.pullEvent()
- if e == "timer" then
- refresh_log()
- os.startTimer(5)
- elseif e == "monitor_touch" then
- if c > maxY/2 then
- scroll = scroll + 1
- else
- scroll = scroll - 1
- end
- if b == maxX and c == 1 then
- scroll = 0
- elseif b == maxX and c == maxY then
- scroll = scroll + maxY
- end
- scroll = math.max(math.min(scroll,scroll),0)
- elseif e == "mouse_click" then
- if b > maxY/2 then
- scroll = scroll + 1
- else
- scroll = scroll - 1
- end
- if a == maxX and b == 1 then
- scroll = 0
- elseif a == maxX and b == maxY then
- scroll = scroll + maxY
- end
- scroll = math.max(math.min(scroll,scroll),0)
- elseif e == "monitor_resize" then
- maxX,maxY = term.getSize()
- end
- end
- end
- ui_refresh()
Advertisement
Add Comment
Please, Sign In to add comment