diff --git a/sys/apps/shell.lua b/sys/apps/shell.lua index bc3707f..6b23582 100644 --- a/sys/apps/shell.lua +++ b/sys/apps/shell.lua @@ -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") diff --git a/sys/autorun/log.lua b/sys/autorun/log.lua index 9e5b04e..3540f0d 100644 --- a/sys/autorun/log.lua +++ b/sys/autorun/log.lua @@ -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] diff --git a/sys/init/7.multishell.lua b/sys/init/7.multishell.lua index e81b8ca..f37033c 100644 --- a/sys/init/7.multishell.lua +++ b/sys/init/7.multishell.lua @@ -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 = { diff --git a/sys/kernel.lua b/sys/kernel.lua index 7bb0aa5..1535b2c 100644 --- a/sys/kernel.lua +++ b/sys/kernel.lua @@ -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 diff --git a/sys/modules/opus/input.lua b/sys/modules/opus/input.lua index 956e0ba..98e3db2 100644 --- a/sys/modules/opus/input.lua +++ b/sys/modules/opus/input.lua @@ -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 diff --git a/sys/modules/opus/terminal.lua b/sys/modules/opus/terminal.lua index 7d3339c..21fce97 100644 --- a/sys/modules/opus/terminal.lua +++ b/sys/modules/opus/terminal.lua @@ -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 ]]--