mirror of
https://github.com/MightyPirates/OpenComputers.git
synced 2025-09-17 11:15:12 -04:00
Minor cleanup to more.lua, fixed single line advance to not exit when at end of file.
This commit is contained in:
parent
4f0665f2b6
commit
00e4f55026
@ -1,32 +1,11 @@
|
|||||||
local component = require("component")
|
local component = require("component")
|
||||||
|
local event = require("event")
|
||||||
local keyboard = require("keyboard")
|
local keyboard = require("keyboard")
|
||||||
local shell = require("shell")
|
local shell = require("shell")
|
||||||
local term = require("term")
|
local term = require("term")
|
||||||
local text = require("text")
|
local text = require("text")
|
||||||
local unicode = require("unicode")
|
local unicode = require("unicode")
|
||||||
|
|
||||||
local function nextLine(file, line, num)
|
|
||||||
local w, h = component.gpu.getResolution()
|
|
||||||
term.setCursorBlink(false)
|
|
||||||
local i = 1
|
|
||||||
while i < num do
|
|
||||||
if not line then
|
|
||||||
line = file:read("*l")
|
|
||||||
if not line then -- eof
|
|
||||||
return true
|
|
||||||
end
|
|
||||||
end
|
|
||||||
local wrapped
|
|
||||||
wrapped, line = text.wrap(text.detab(line), w, w)
|
|
||||||
io.write(wrapped .. "\n")
|
|
||||||
i = i + 1
|
|
||||||
end
|
|
||||||
term.setCursor(1, h)
|
|
||||||
term.write(":")
|
|
||||||
term.setCursorBlink(true)
|
|
||||||
return false
|
|
||||||
end
|
|
||||||
|
|
||||||
local args = shell.parse(...)
|
local args = shell.parse(...)
|
||||||
if #args == 0 then
|
if #args == 0 then
|
||||||
io.write("Usage: more <filename1>")
|
io.write("Usage: more <filename1>")
|
||||||
@ -39,17 +18,35 @@ if not file then
|
|||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local function readlines(file, line, num)
|
||||||
|
local w, h = component.gpu.getResolution()
|
||||||
|
num = num or (h - 1)
|
||||||
|
term.setCursorBlink(false)
|
||||||
|
for _ = 1, num do
|
||||||
|
if not line then
|
||||||
|
line = file:read("*l")
|
||||||
|
if not line then -- eof
|
||||||
|
return nil
|
||||||
|
end
|
||||||
|
end
|
||||||
|
local wrapped
|
||||||
|
wrapped, line = text.wrap(text.detab(line), w, w)
|
||||||
|
io.write(wrapped .. "\n")
|
||||||
|
end
|
||||||
|
term.setCursor(1, h)
|
||||||
|
term.write(":")
|
||||||
|
term.setCursorBlink(true)
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
|
||||||
local line = nil
|
local line = nil
|
||||||
while true do
|
while true do
|
||||||
local w, h = component.gpu.getResolution()
|
|
||||||
term.clear()
|
term.clear()
|
||||||
local num = h
|
if not readlines(file, line) then
|
||||||
local r = nextLine(file, line, num)
|
|
||||||
if r then
|
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
while true do
|
while true do
|
||||||
local event, address, char, code = coroutine.yield("key_down")
|
local event, address, char, code = event.pull("key_down")
|
||||||
if component.isPrimary(address) then
|
if component.isPrimary(address) then
|
||||||
if code == keyboard.keys.q then
|
if code == keyboard.keys.q then
|
||||||
term.setCursorBlink(false)
|
term.setCursorBlink(false)
|
||||||
@ -59,7 +56,9 @@ while true do
|
|||||||
break
|
break
|
||||||
elseif code == keyboard.keys.enter or code == keyboard.keys.down then
|
elseif code == keyboard.keys.enter or code == keyboard.keys.down then
|
||||||
term.clearLine()
|
term.clearLine()
|
||||||
nextLine(file, line, 2)
|
if not readlines(file, line, 1) then
|
||||||
|
return
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user