opus/sys/autorun/hotkeys.lua

58 lines
1.3 KiB
Lua
Raw Normal View History

2017-10-15 06:36:54 +00:00
_G.requireInjector()
local Util = require('util')
2018-01-12 01:53:32 +00:00
local kernel = _G.kernel
local keyboard = _G.device.keyboard
2017-10-15 06:36:54 +00:00
local multishell = _ENV.multishell
2017-10-15 23:55:05 +00:00
-- overview
keyboard.addHotkey('control-o', function()
2017-10-15 06:36:54 +00:00
for _,tab in pairs(multishell.getTabs()) do
if tab.isOverview then
multishell.setFocus(tab.tabId)
end
end
end)
2017-10-15 23:55:05 +00:00
-- restart tab
keyboard.addHotkey('control-backspace', function()
2018-01-12 01:53:32 +00:00
local uid = multishell.getFocus()
local tab = kernel.find(uid)
2017-10-15 06:36:54 +00:00
if not tab.isOverview then
2018-01-12 01:53:32 +00:00
multishell.terminate(uid)
2017-10-15 06:36:54 +00:00
tab = Util.shallowCopy(tab)
tab.isDead = false
tab.focused = true
multishell.openTab(tab)
end
end)
2017-10-15 23:55:05 +00:00
-- next tab
keyboard.addHotkey('control-tab', function()
2017-10-15 06:36:54 +00:00
local tabs = multishell.getTabs()
local visibleTabs = { }
local currentTabId = multishell.getFocus()
local function compareTab(a, b)
2018-01-12 01:53:32 +00:00
return a.uid < b.uid
2017-10-15 06:36:54 +00:00
end
for _,tab in Util.spairs(tabs, compareTab) do
if not tab.hidden then
table.insert(visibleTabs, tab)
end
end
for k,tab in ipairs(visibleTabs) do
2018-01-12 01:53:32 +00:00
if tab.uid == currentTabId then
2017-10-15 06:36:54 +00:00
if k < #visibleTabs then
2018-01-12 01:53:32 +00:00
multishell.setFocus(visibleTabs[k + 1].uid)
2017-10-15 06:36:54 +00:00
return
end
end
end
if #visibleTabs > 0 then
2018-01-12 01:53:32 +00:00
multishell.setFocus(visibleTabs[1].uid)
2017-10-15 06:36:54 +00:00
end
end)