1
0
mirror of https://github.com/kepler155c/opus synced 2024-06-18 11:20:01 +00:00
opus/sys/services/log.lua

95 lines
2.3 KiB
Lua
Raw Normal View History

2017-10-08 21:45:01 +00:00
_G.requireInjector()
2018-01-13 20:17:26 +00:00
--[[
Adds the control-d hotkey to view the kernel log.
]]
2016-12-11 19:24:52 +00:00
local Terminal = require('terminal')
2018-01-12 01:53:32 +00:00
local kernel = _G.kernel
local keyboard = _G.device.keyboard
2017-10-08 21:45:01 +00:00
local multishell = _ENV.multishell
local os = _G.os
local term = _G.term
2018-01-14 04:40:53 +00:00
local window = _G.window
2017-10-08 21:45:01 +00:00
2018-01-13 20:17:26 +00:00
if multishell and multishell.setTitle then
multishell.setTitle(multishell.getCurrent(), 'System Log')
end
2016-12-11 19:24:52 +00:00
2018-01-14 04:40:53 +00:00
-- jump through a lot of hoops to get around window api limitations
-- mainly failing to provide access to window buffer or knowledge of parent
-- need: window.getParent()
-- window.copy(target)
2018-01-16 01:38:30 +00:00
local terminal = _G.kernel.terminal
2018-01-14 04:40:53 +00:00
local w, h = kernel.window.getSize()
local win = window.create(kernel.window, 1, 1, w, h + 50, false)
-- copy windows contents from parent window to child
local oblit, oscp = terminal.blit, terminal.setCursorPos
kernel.window.setVisible(false)
terminal.blit = function(...)
win.blit(...)
end
terminal.setCursorPos = function(...)
win.setCursorPos(...)
end
kernel.window.setVisible(true)
2016-12-11 19:24:52 +00:00
2018-01-14 04:40:53 +00:00
-- position and resize window for multishell (but don't update screen)
terminal.blit = function() end
terminal.setCursorPos = function() end
kernel.window.reposition(1, 2, w, h - 1)
2018-01-13 20:17:26 +00:00
2018-01-14 04:40:53 +00:00
-- restore original terminal
terminal.blit = oblit
terminal.setCursorPos = oscp
2018-01-13 20:17:26 +00:00
2018-01-14 04:40:53 +00:00
-- add scrolling methods
Terminal.scrollable(win, kernel.window)
-- update kernel with new window, set this tab with the new kernal window
local routine = kernel.getCurrent()
for _,r in pairs(kernel.routines) do
2018-01-16 01:38:30 +00:00
if r.terminal == kernel.window then
2018-01-14 04:40:53 +00:00
r.terminal = win
r.window = win
end
end
2018-01-16 01:38:30 +00:00
--kernel.terminal = win
2018-01-14 04:40:53 +00:00
kernel.window = win
routine.terminal = win
routine.window = win
2018-01-13 20:17:26 +00:00
term.redirect(routine.window)
2016-12-11 19:24:52 +00:00
2018-01-14 04:40:53 +00:00
local previousId
2018-01-12 01:53:32 +00:00
kernel.hook('mouse_scroll', function(_, eventData)
local dir, y = eventData[1], eventData[3]
if y > 1 then
local currentTab = kernel.routines[1]
if currentTab.terminal.scrollUp then
if dir == -1 then
currentTab.terminal.scrollUp()
else
currentTab.terminal.scrollDown()
end
end
end
end)
keyboard.addHotkey('control-d', function()
2018-01-13 20:17:26 +00:00
local current = kernel.getFocused()
if current.uid ~= routine.uid then
previousId = current.uid
kernel.raise(routine.uid)
2016-12-11 19:24:52 +00:00
elseif previousId then
2018-01-13 20:17:26 +00:00
kernel.raise(previousId)
2016-12-11 19:24:52 +00:00
end
end)
os.pullEventRaw('terminate')
keyboard.removeHotkey('control-d')