Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- --[[
- pastebin get uKMMLFYX artie
- std PB uKMMLFYX artie
- --]]
- local tArg = {...}
- local filename = tArg[1]
- if not fs.exists(filename) then
- return printError("That doesn't exist")
- elseif fs.isDir(filename) then
- return printError("That's a folder, smartass")
- end
- local scrollX = 1
- local scrollY = 1
- local scr_x, scr_y = term.getSize()
- local fileToTable = function(name)
- if not fs.exists(name) then
- return false, {}
- end
- local output = {}
- local file = fs.open(name,"r")
- local line = ""
- repeat
- line = file.readLine()
- if line then
- output[#output+1] = line
- end
- until not line
- file.close()
- return true, output
- end
- local zom = function(num)
- return num > 0 and num or 0
- end
- local t = term.current().setVisible
- local render = function(scrollX,scrollY,tbl)
- if t then t(false) end
- for y = 1, scr_y do
- term.setCursorPos(1,y)
- term.clearLine()
- if tbl[y+scrollY] then
- term.write((" "):rep(zom(-(scrollX-1))) ..tbl[y+scrollY]:sub(zom(scrollX)))
- end
- end
- if t then t(true) end
- end
- local _,contbl
- local doIt = function()
- while true do
- _,contbl = fileToTable(filename)
- render(scrollX,scrollY,contbl)
- sleep(0)
- end
- end
- local scrolling = function()
- while true do
- local evt, key = os.pullEvent("key")
- if key == keys.left then
- scrollX = scrollX - 1
- elseif key == keys.right then
- scrollX = scrollX + 1
- elseif key == keys.up then
- scrollY = scrollY - 1
- elseif key == keys.down then
- scrollY = scrollY + 1
- elseif key == keys.q then
- return
- end
- end
- end
- parallel.waitForAny(scrolling,doIt)
- term.setCursorPos(1,scr_y)
- print("")
- sleep(0)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement