Advertisement
guitarplayer616

editor

Jun 2nd, 2022
906
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.27 KB | None | 0 0
  1. local tArgs = {...}
  2.  
  3. function load_file(filename)
  4.     local h = io.open(filename, "r")
  5.  
  6.     local lines = {}
  7.     for line in h:lines() do
  8.         table.insert(lines, line)
  9.     end
  10.  
  11.     h:close()
  12.     return lines
  13. end
  14.  
  15. function blit(lines, n, m)
  16.     local l = 1
  17.     for i=n,m do
  18.         term.setCursorPos(1,l)
  19.         term.clearLine()
  20.         term.write(lines[i])
  21.         l = l + 1
  22.     end
  23. end
  24.  
  25. function handle_events(filename)
  26.     local w,h = term.getSize()
  27.     local y1,y2 = 1, h
  28.     local x,y = 1,1
  29.     local lines = load_file(filename)
  30.     blit(lines, y1, y2)
  31.     term.setCursorPos(x,y)    
  32.     term.setCursorBlink(true)
  33.     while true do
  34.         local events = {os.pullEvent("key")}
  35.         if events[2] == keys.down then
  36.             y1 = y1 + 1
  37.             y2 = y2 + 1
  38.             blit(lines, y1, y2)
  39.             term.setCursorPos(x,y)
  40.         elseif events[2] == keys.up then
  41.             y1 = y1 - 1
  42.             y2 = y2 - 1
  43.             blit(lines, y1, y2)
  44.             term.setCursorPos(x,y)
  45.         elseif events[2] == keys.left then
  46.             x = x - 1
  47.             term.setCursorPos(x,y)
  48.         elseif events[2] == keys.right then
  49.             x = x + 1
  50.             term.setCursorPos(x,y)
  51.         end
  52.     end
  53. end
  54.  
  55. handle_events(tArgs[1])
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement