multishell hooks
This commit is contained in:
@@ -2,52 +2,44 @@ _G.requireInjector()
|
||||
|
||||
local Util = require('util')
|
||||
|
||||
local keys = _G.keys
|
||||
local multishell = _ENV.multishell
|
||||
local os = _G.os
|
||||
local textutils = _G.textutils
|
||||
|
||||
local clipboard = { }
|
||||
|
||||
function clipboard.getData()
|
||||
return clipboard.data
|
||||
end
|
||||
|
||||
function clipboard.setData(data)
|
||||
clipboard.data = data
|
||||
if data then
|
||||
clipboard.useInternal(true)
|
||||
end
|
||||
end
|
||||
|
||||
function clipboard.getText()
|
||||
if clipboard.data then
|
||||
if type(clipboard.data) == 'table' then
|
||||
local s, m = pcall(textutils.serialize, clipboard.data)
|
||||
clipboard.data = (s and m) or Util.tostring(clipboard.data)
|
||||
end
|
||||
return Util.tostring(clipboard.data)
|
||||
end
|
||||
end
|
||||
|
||||
function clipboard.isInternal()
|
||||
return clipboard.internal
|
||||
end
|
||||
|
||||
function clipboard.useInternal(mode)
|
||||
if mode ~= clipboard.internal then
|
||||
clipboard.internal = mode
|
||||
local text = 'Clipboard (^m): ' .. ((mode and 'internal') or 'normal')
|
||||
multishell.showMessage(text)
|
||||
os.queueEvent('clipboard_mode', mode)
|
||||
end
|
||||
end
|
||||
|
||||
multishell.hook('clipboard_copy', function(_, args)
|
||||
clipboard.setData(args[1])
|
||||
clipboard.data = args[1]
|
||||
if clipboard.data then
|
||||
clipboard.useInternal(true)
|
||||
end
|
||||
end)
|
||||
|
||||
multishell.hook('paste', function(_, args)
|
||||
if clipboard.isInternal() then
|
||||
if clipboard.internal then
|
||||
args[1] = clipboard.getText() or ''
|
||||
end
|
||||
end)
|
||||
|
||||
-- control-m - clipboard mode
|
||||
multishell.addHotkey(50, function()
|
||||
clipboard.useInternal(not clipboard.isInternal())
|
||||
-- control-m - toggle clipboard mode
|
||||
multishell.addHotkey(keys.m, function()
|
||||
clipboard.useInternal(not clipboard.internal)
|
||||
end)
|
||||
|
||||
58
sys/autorun/hotkeys.lua
Normal file
58
sys/autorun/hotkeys.lua
Normal file
@@ -0,0 +1,58 @@
|
||||
_G.requireInjector()
|
||||
|
||||
local Util = require('util')
|
||||
|
||||
local keys = _G.keys
|
||||
|
||||
local multishell = _ENV.multishell
|
||||
|
||||
-- control-o - overview
|
||||
multishell.addHotkey(keys.o, function()
|
||||
for _,tab in pairs(multishell.getTabs()) do
|
||||
if tab.isOverview then
|
||||
multishell.setFocus(tab.tabId)
|
||||
end
|
||||
end
|
||||
end)
|
||||
|
||||
-- control-backspace - restart tab
|
||||
multishell.addHotkey(keys.backspace, function()
|
||||
local tabs = multishell.getTabs()
|
||||
local tabId = multishell.getFocus()
|
||||
local tab = tabs[tabId]
|
||||
if not tab.isOverview then
|
||||
multishell.terminate(tabId)
|
||||
tab = Util.shallowCopy(tab)
|
||||
tab.isDead = false
|
||||
tab.focused = true
|
||||
multishell.openTab(tab)
|
||||
end
|
||||
end)
|
||||
|
||||
-- control-tab - next tab
|
||||
multishell.addHotkey(keys.tab, function()
|
||||
local tabs = multishell.getTabs()
|
||||
local visibleTabs = { }
|
||||
local currentTabId = multishell.getFocus()
|
||||
|
||||
local function compareTab(a, b)
|
||||
return a.tabId < b.tabId
|
||||
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
|
||||
if tab.tabId == currentTabId then
|
||||
if k < #visibleTabs then
|
||||
multishell.setFocus(visibleTabs[k + 1].tabId)
|
||||
return
|
||||
end
|
||||
end
|
||||
end
|
||||
if #visibleTabs > 0 then
|
||||
multishell.setFocus(visibleTabs[1].tabId)
|
||||
end
|
||||
end)
|
||||
Reference in New Issue
Block a user