Z1maV1

zimavi's print utils

Aug 18th, 2024
140
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.03 KB | None | 0 0
  1. local utils = {}
  2.  
  3. function utils.scrollText(text, pageSize)
  4.     pageSize = pageSize or 10
  5.     local lines = {}
  6.    
  7.     for line in text:gmatch("([^\n]+)") do
  8.         table.insert(lines, line)
  9.     end
  10.  
  11.     local totalLines = #lines
  12.     local currentLine = 1
  13.  
  14.     while currentLine <= totalLines do
  15.         term.clear()
  16.         term.setCursorPos(1, 1)
  17.  
  18.         for i = 0, pageSize - 1 do
  19.             if lines[currentLine + i] then
  20.                 print(lines[currentLine + i])
  21.             end
  22.         end
  23.  
  24.         currentLine = currentLine + pageSize
  25.  
  26.         if currentLine <= totalLines then
  27.             print("\nPress Enter to continue...")
  28.             while true do
  29.                 local eventData = {os.pullEvent()}
  30.                 local event = eventData[1]
  31.                
  32.                 if event == "key" then
  33.                     if eventData[2] == 257 or eventData[2] == 335 then
  34.                         break
  35.                     end
  36.                 end
  37.             end
  38.         end
  39.     end
  40. end
  41.  
  42. return utils
Advertisement
Add Comment
Please, Sign In to add comment