Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local logFile = "debug.log"
- -- Read log into a table
- local lines = {}
- local file = fs.open(logFile, "r")
- if file then
- local line = file.readLine()
- while line do
- table.insert(lines, line)
- line = file.readLine()
- end
- file.close()
- else
- print("No log file found.")
- return
- end
- local pageSize = 10 -- Number of lines per page
- local currentPage = 1
- local function displayPage()
- term.clear()
- term.setCursorPos(1,1)
- local startLine = (currentPage - 1) * pageSize + 1
- local endLine = math.min(#lines, startLine + pageSize - 1)
- for i = startLine, endLine do
- print(lines[i])
- end
- print("\n[Page "..currentPage.."/"..math.ceil(#lines/pageSize).."] Press UP/DOWN to scroll, Q to exit")
- end
- displayPage()
- while true do
- local event, key = os.pullEvent("key")
- if key == keys.up then
- if currentPage > 1 then
- currentPage = currentPage - 1
- displayPage()
- end
- elseif key == keys.down then
- if currentPage < math.ceil(#lines / pageSize) then
- currentPage = currentPage + 1
- displayPage()
- end
- elseif key == keys.q then
- break
- end
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement