fix resizing scrolling terminals

This commit is contained in:
kepler155c@gmail.com 2020-05-10 14:04:20 -06:00
parent cfc18e10cd
commit a3a819256f
6 changed files with 60 additions and 25 deletions

View File

@ -666,6 +666,7 @@ local function shellRead(history)
end
elseif event == "term_resize" then
terminal.reposition(1, 1, oldTerm.getSize())
entry.width = term.getSize() - 3
entry:updateScroll()
redraw()
@ -680,7 +681,7 @@ end
local history = History.load('usr/.shell_history', 25)
term.setBackgroundColor(_colors.backgroundColor)
term.clear()
--term.clear()
if settings.get("motd.enabled") then
shell.run("motd")

View File

@ -4,22 +4,11 @@
local kernel = _G.kernel
local keyboard = _G.device.keyboard
local multishell = _ENV.multishell
local os = _G.os
local term = _G.term
local function systemLog()
local routine = kernel.getCurrent()
if multishell and multishell.openTab then
local w, h = kernel.window.getSize()
kernel.window.reposition(1, 2, w, h - 1)
routine.terminal = kernel.window
routine.window = kernel.window
term.redirect(kernel.window)
end
kernel.hook('mouse_scroll', function(_, eventData)
local dir, y = eventData[1], eventData[3]

View File

@ -20,7 +20,7 @@ local multishell = { }
shell.setEnv('multishell', multishell)
multishell.term = parentTerm --deprecated use device.terminal
kernel.window.reposition(1, 2, w, h - 1)
local config = {
standard = {

View File

@ -109,7 +109,6 @@ function Routine:resume(event, ...)
end
-- override if any post processing is required
-- routine:cleanup must be called explicitly if overridden
function Routine:onExit(status, message) -- self, status, message
if not status and message ~= 'Terminated' then
_G.printError(message)
@ -177,13 +176,17 @@ function kernel.launch(routine)
pcall(routine.onExit, routine, result, err)
routine:cleanup()
if not result then
error(err)
end
end)
table.insert(kernel.routines, routine)
local s, m = routine:resume()
return not s and s or routine.uid, m
return s and routine.uid, m
end
function kernel.run(args)
@ -278,7 +281,7 @@ end
function kernel.start()
local s, m
pcall(function()
local s2, m2 = pcall(function()
repeat
local eventData = { os.pullEventRaw() }
local event = table.remove(eventData, 1)
@ -290,11 +293,11 @@ function kernel.start()
until event == 'kernel_halt'
end)
if not s and m then
if (not s and m) or (not s2 and m2) then
kernel.window.setVisible(true)
term.redirect(kernel.window)
print('\nCrash detected\n')
_G.printError(m)
_G.printError(m or m2)
end
term.redirect(kernel.terminal)
end

View File

@ -189,11 +189,22 @@ function input:translate(event, code, p1, p2)
end
end
function input:test()
if not ({ ...})[1] then
local colors = _G.colors
local term = _G.term
while true do
local ch = self:translate(os.pullEvent())
local e = { os.pullEvent() }
local ch = input:translate(table.unpack(e))
if ch then
Util.print(ch)
term.setTextColor(colors.white)
print(table.unpack(e))
term.setTextColor(colors.lime)
local t = { }
for k,v in pairs(ch) do
table.insert(t, k .. ':' .. v)
end
print('--> ' .. table.concat(t, ' ') .. '\n')
end
end
end

View File

@ -33,7 +33,7 @@ function Terminal.window(parent, sx, sy, w, h, isVisible)
end
local win = { }
local maxScroll = 100
local maxScroll
local cx, cy = 1, 1
local blink = false
local _bg, _fg = colors.black, colors.white
@ -164,7 +164,7 @@ function Terminal.window(parent, sx, sy, w, h, isVisible)
win.canvas.lines[lines + i] = { }
win.canvas:clearLine(lines + i)
end
while #win.canvas.lines > maxScroll do
while #win.canvas.lines > (maxScroll or win.canvas.height) do
table.remove(win.canvas.lines, 1)
end
scrollTo(#win.canvas.lines)
@ -213,8 +213,39 @@ function Terminal.window(parent, sx, sy, w, h, isVisible)
end
function win.reposition(x, y, width, height)
win.canvas.x, win.canvas.y = x, y
win.canvas:resize(width or win.canvas.width, height or win.canvas.height)
if not maxScroll then
win.canvas:move(x, y)
win.canvas:resize(width or win.canvas.width, height or win.canvas.height)
return
end
-- special processing for scrolling terminal like windows
local delta = height - win.canvas.height
if delta > 0 then -- grow
for _ = 1, delta do
win.canvas.lines[#win.canvas.lines + 1] = { }
win.canvas:clearLine(#win.canvas.lines)
end
elseif delta < 0 then -- shrink
for _ = delta + 1, 0 do
if cy < win.canvas.height then
win.canvas.lines[#win.canvas.lines] = nil
else
cy = cy - 1
win.canvas.offy = win.canvas.offy + 1
end
end
end
win.canvas:resizeBuffer(width, #win.canvas.lines)
win.canvas.height = height
win.canvas.width = width
win.canvas:move(x, y)
update()
end
--[[ Additional methods ]]--