mirror of
https://github.com/kepler155c/opus
synced 2024-09-20 19:29:38 +00:00
fix resizing scrolling terminals
This commit is contained in:
parent
cfc18e10cd
commit
a3a819256f
@ -666,6 +666,7 @@ local function shellRead(history)
|
|||||||
end
|
end
|
||||||
|
|
||||||
elseif event == "term_resize" then
|
elseif event == "term_resize" then
|
||||||
|
terminal.reposition(1, 1, oldTerm.getSize())
|
||||||
entry.width = term.getSize() - 3
|
entry.width = term.getSize() - 3
|
||||||
entry:updateScroll()
|
entry:updateScroll()
|
||||||
redraw()
|
redraw()
|
||||||
@ -680,7 +681,7 @@ end
|
|||||||
local history = History.load('usr/.shell_history', 25)
|
local history = History.load('usr/.shell_history', 25)
|
||||||
|
|
||||||
term.setBackgroundColor(_colors.backgroundColor)
|
term.setBackgroundColor(_colors.backgroundColor)
|
||||||
term.clear()
|
--term.clear()
|
||||||
|
|
||||||
if settings.get("motd.enabled") then
|
if settings.get("motd.enabled") then
|
||||||
shell.run("motd")
|
shell.run("motd")
|
||||||
|
@ -4,22 +4,11 @@
|
|||||||
|
|
||||||
local kernel = _G.kernel
|
local kernel = _G.kernel
|
||||||
local keyboard = _G.device.keyboard
|
local keyboard = _G.device.keyboard
|
||||||
local multishell = _ENV.multishell
|
|
||||||
local os = _G.os
|
local os = _G.os
|
||||||
local term = _G.term
|
|
||||||
|
|
||||||
local function systemLog()
|
local function systemLog()
|
||||||
local routine = kernel.getCurrent()
|
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)
|
kernel.hook('mouse_scroll', function(_, eventData)
|
||||||
local dir, y = eventData[1], eventData[3]
|
local dir, y = eventData[1], eventData[3]
|
||||||
|
|
||||||
|
@ -20,7 +20,7 @@ local multishell = { }
|
|||||||
|
|
||||||
shell.setEnv('multishell', multishell)
|
shell.setEnv('multishell', multishell)
|
||||||
|
|
||||||
multishell.term = parentTerm --deprecated use device.terminal
|
kernel.window.reposition(1, 2, w, h - 1)
|
||||||
|
|
||||||
local config = {
|
local config = {
|
||||||
standard = {
|
standard = {
|
||||||
|
@ -109,7 +109,6 @@ function Routine:resume(event, ...)
|
|||||||
end
|
end
|
||||||
|
|
||||||
-- override if any post processing is required
|
-- override if any post processing is required
|
||||||
-- routine:cleanup must be called explicitly if overridden
|
|
||||||
function Routine:onExit(status, message) -- self, status, message
|
function Routine:onExit(status, message) -- self, status, message
|
||||||
if not status and message ~= 'Terminated' then
|
if not status and message ~= 'Terminated' then
|
||||||
_G.printError(message)
|
_G.printError(message)
|
||||||
@ -177,13 +176,17 @@ function kernel.launch(routine)
|
|||||||
|
|
||||||
pcall(routine.onExit, routine, result, err)
|
pcall(routine.onExit, routine, result, err)
|
||||||
routine:cleanup()
|
routine:cleanup()
|
||||||
|
|
||||||
|
if not result then
|
||||||
|
error(err)
|
||||||
|
end
|
||||||
end)
|
end)
|
||||||
|
|
||||||
table.insert(kernel.routines, routine)
|
table.insert(kernel.routines, routine)
|
||||||
|
|
||||||
local s, m = routine:resume()
|
local s, m = routine:resume()
|
||||||
|
|
||||||
return not s and s or routine.uid, m
|
return s and routine.uid, m
|
||||||
end
|
end
|
||||||
|
|
||||||
function kernel.run(args)
|
function kernel.run(args)
|
||||||
@ -278,7 +281,7 @@ end
|
|||||||
|
|
||||||
function kernel.start()
|
function kernel.start()
|
||||||
local s, m
|
local s, m
|
||||||
pcall(function()
|
local s2, m2 = pcall(function()
|
||||||
repeat
|
repeat
|
||||||
local eventData = { os.pullEventRaw() }
|
local eventData = { os.pullEventRaw() }
|
||||||
local event = table.remove(eventData, 1)
|
local event = table.remove(eventData, 1)
|
||||||
@ -290,11 +293,11 @@ function kernel.start()
|
|||||||
until event == 'kernel_halt'
|
until event == 'kernel_halt'
|
||||||
end)
|
end)
|
||||||
|
|
||||||
if not s and m then
|
if (not s and m) or (not s2 and m2) then
|
||||||
kernel.window.setVisible(true)
|
kernel.window.setVisible(true)
|
||||||
term.redirect(kernel.window)
|
term.redirect(kernel.window)
|
||||||
print('\nCrash detected\n')
|
print('\nCrash detected\n')
|
||||||
_G.printError(m)
|
_G.printError(m or m2)
|
||||||
end
|
end
|
||||||
term.redirect(kernel.terminal)
|
term.redirect(kernel.terminal)
|
||||||
end
|
end
|
||||||
|
@ -189,11 +189,22 @@ function input:translate(event, code, p1, p2)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function input:test()
|
if not ({ ...})[1] then
|
||||||
|
local colors = _G.colors
|
||||||
|
local term = _G.term
|
||||||
|
|
||||||
while true do
|
while true do
|
||||||
local ch = self:translate(os.pullEvent())
|
local e = { os.pullEvent() }
|
||||||
|
local ch = input:translate(table.unpack(e))
|
||||||
if ch then
|
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
|
end
|
||||||
end
|
end
|
||||||
|
@ -33,7 +33,7 @@ function Terminal.window(parent, sx, sy, w, h, isVisible)
|
|||||||
end
|
end
|
||||||
|
|
||||||
local win = { }
|
local win = { }
|
||||||
local maxScroll = 100
|
local maxScroll
|
||||||
local cx, cy = 1, 1
|
local cx, cy = 1, 1
|
||||||
local blink = false
|
local blink = false
|
||||||
local _bg, _fg = colors.black, colors.white
|
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.lines[lines + i] = { }
|
||||||
win.canvas:clearLine(lines + i)
|
win.canvas:clearLine(lines + i)
|
||||||
end
|
end
|
||||||
while #win.canvas.lines > maxScroll do
|
while #win.canvas.lines > (maxScroll or win.canvas.height) do
|
||||||
table.remove(win.canvas.lines, 1)
|
table.remove(win.canvas.lines, 1)
|
||||||
end
|
end
|
||||||
scrollTo(#win.canvas.lines)
|
scrollTo(#win.canvas.lines)
|
||||||
@ -213,8 +213,39 @@ function Terminal.window(parent, sx, sy, w, h, isVisible)
|
|||||||
end
|
end
|
||||||
|
|
||||||
function win.reposition(x, y, width, height)
|
function win.reposition(x, y, width, height)
|
||||||
win.canvas.x, win.canvas.y = x, y
|
if not maxScroll then
|
||||||
|
win.canvas:move(x, y)
|
||||||
win.canvas:resize(width or win.canvas.width, height or win.canvas.height)
|
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
|
end
|
||||||
|
|
||||||
--[[ Additional methods ]]--
|
--[[ Additional methods ]]--
|
||||||
|
Loading…
Reference in New Issue
Block a user