scrolling term

This commit is contained in:
kepler155c@gmail.com 2019-02-11 20:25:12 -05:00
parent d769b35672
commit 2d411df7d1
3 changed files with 33 additions and 11 deletions

View File

@ -63,15 +63,15 @@ function Terminal.window(parent, sx, sy, w, h, isVisible)
function win.clear()
canvas.offy = 0
canvas:clear(bg, fg)
for i = #canvas.lines, canvas.height + 1, -1 do
canvas.lines[i] = nil
end
canvas:clear(bg, fg)
update()
end
function win.clearLine()
canvas:clearLine(cy, bg, fg)
canvas:clearLine(cy + canvas.offy, bg, fg)
win.setCursorPos(cx, cy)
update()
end
@ -127,15 +127,15 @@ function Terminal.window(parent, sx, sy, w, h, isVisible)
function win.scroll(n)
n = n or 1
if n > 0 then
for _ = 1, n do
canvas.lines[#canvas.lines + 1] = { }
canvas:clearLine(#canvas.lines, bg, fg)
local lines = #canvas.lines
for i = 1, n do
canvas.lines[lines + i] = { }
canvas:clearLine(lines + i, bg, fg)
end
while #canvas.lines > maxScroll do
table.remove(canvas.lines, 1)
end
scrollTo(#canvas.lines - canvas.height)
canvas.offy = #canvas.lines - canvas.height
scrollTo(#canvas.lines)
canvas:dirty()
update()
end

View File

@ -371,10 +371,10 @@ local oldTerm
local terminal = term.current()
if not terminal.scrollUp then
-- local Terminal = require('terminal')
-- terminal = Terminal.window(term.current())
-- terminal.setMaxScroll(200)
-- oldTerm = term.redirect(terminal)
local Terminal = require('terminal')
terminal = Terminal.window(term.current())
terminal.setMaxScroll(200)
oldTerm = term.redirect(terminal)
end
local config = {

22
sys/autorun/complete.lua Normal file
View File

@ -0,0 +1,22 @@
local function completeMultipleChoice(sText, tOptions, bAddSpaces)
local tResults = { }
for n = 1,#tOptions do
local sOption = tOptions[n]
if #sOption + (bAddSpaces and 1 or 0) > #sText and string.sub(sOption, 1, #sText) == sText then
local sResult = string.sub(sOption, #sText + 1)
if bAddSpaces then
table.insert(tResults, sResult .. " ")
else
table.insert(tResults, sResult)
end
end
end
return tResults
end
_ENV.shell.setCompletionFunction("sys/apps/package.lua",
function(_, index, text)
if index == 1 then
return completeMultipleChoice(text, { "install ", "update ", "uninstall " })
end
end)