Advertisement
Loneranger419

readLog

Feb 1st, 2025
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.22 KB | Source Code | 0 0
  1. local logFile = "debug.log"
  2.  
  3. -- Read log into a table
  4. local lines = {}
  5. local file = fs.open(logFile, "r")
  6. if file then
  7.     local line = file.readLine()
  8.     while line do
  9.         table.insert(lines, line)
  10.         line = file.readLine()
  11.     end
  12.     file.close()
  13. else
  14.     print("No log file found.")
  15.     return
  16. end
  17.  
  18. local pageSize = 10 -- Number of lines per page
  19. local currentPage = 1
  20.  
  21. local function displayPage()
  22.     term.clear()
  23.     term.setCursorPos(1,1)
  24.     local startLine = (currentPage - 1) * pageSize + 1
  25.     local endLine = math.min(#lines, startLine + pageSize - 1)
  26.    
  27.     for i = startLine, endLine do
  28.         print(lines[i])
  29.     end
  30.  
  31.     print("\n[Page "..currentPage.."/"..math.ceil(#lines/pageSize).."] Press UP/DOWN to scroll, Q to exit")
  32. end
  33.  
  34. displayPage()
  35.  
  36. while true do
  37.     local event, key = os.pullEvent("key")
  38.     if key == keys.up then
  39.         if currentPage > 1 then
  40.             currentPage = currentPage - 1
  41.             displayPage()
  42.         end
  43.     elseif key == keys.down then
  44.         if currentPage < math.ceil(#lines / pageSize) then
  45.             currentPage = currentPage + 1
  46.             displayPage()
  47.         end
  48.     elseif key == keys.q then
  49.         break
  50.     end
  51. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement