Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- local color1 = colors.lightGray
- local color2 = colors.cyan
- local _, height = term.getSize()
- local y = 1
- local path_name = "lc/".."input.txt"
- local temp_lines = {}
- local lines = {}
- local file = io.open(path_name)
- if file == nil then error("file is nil",0) end
- local function reverse()
- local x = 1
- for i = #temp_lines, 1, -1 do
- lines[x] = temp_lines[i]
- x = x + 1
- end
- end
- local function make_lines()
- local x = 1
- for line in file:lines() do
- temp_lines[x] = line
- x = x + 1
- end
- file:close()
- reverse()
- end
- local function render()
- term.clear()
- local x = height
- local xx = y % 2
- for i = y, (y + height - 1) do
- if lines[i] ~= nil then
- term.setCursorPos(1,x)
- if xx == 1 then
- term.setTextColor(color1)
- xx = 0
- elseif xx == 0 then
- term.setTextColor(color2)
- xx = 1
- end
- term.write(lines[i])
- x = x - 1
- end
- end
- end
- local function scroll(key)
- if keys.getName(key) == "up" or keys.getName(key) == "w" then
- y = y + 1
- elseif keys.getName(key) == "down" or keys.getName(key) == "s" then
- y = y - 1
- end
- if y < 1 then
- y = 1
- elseif y > #lines - height + 1 then
- y = #lines - height + 1
- end
- end
- make_lines()
- while true do
- sleep(0)
- render()
- local event, key, is_held = os.pullEvent("key")
- scroll(key)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement