2017-10-08 21:45:01 +00:00
|
|
|
_G.requireInjector()
|
2017-10-14 07:41:54 +00:00
|
|
|
|
2017-09-05 06:09:31 +00:00
|
|
|
local Util = require('util')
|
2017-10-14 07:41:54 +00:00
|
|
|
|
2017-10-15 06:36:54 +00:00
|
|
|
local keys = _G.keys
|
2017-10-14 07:41:54 +00:00
|
|
|
local multishell = _ENV.multishell
|
2017-10-15 06:36:54 +00:00
|
|
|
local textutils = _G.textutils
|
2017-09-05 06:09:31 +00:00
|
|
|
|
2017-10-08 21:45:01 +00:00
|
|
|
local clipboard = { }
|
2017-05-12 05:12:58 +00:00
|
|
|
|
|
|
|
function clipboard.getText()
|
|
|
|
if clipboard.data then
|
2017-10-15 06:36:54 +00:00
|
|
|
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
|
2017-05-12 05:12:58 +00:00
|
|
|
return Util.tostring(clipboard.data)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function clipboard.useInternal(mode)
|
2017-05-14 00:46:26 +00:00
|
|
|
if mode ~= clipboard.internal then
|
2017-05-12 05:12:58 +00:00
|
|
|
clipboard.internal = mode
|
2017-10-14 07:41:54 +00:00
|
|
|
local text = 'Clipboard (^m): ' .. ((mode and 'internal') or 'normal')
|
|
|
|
multishell.showMessage(text)
|
2017-05-12 05:12:58 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-10-14 07:41:54 +00:00
|
|
|
multishell.hook('clipboard_copy', function(_, args)
|
2017-10-15 06:36:54 +00:00
|
|
|
clipboard.data = args[1]
|
|
|
|
if clipboard.data then
|
|
|
|
clipboard.useInternal(true)
|
|
|
|
end
|
2017-10-14 07:41:54 +00:00
|
|
|
end)
|
|
|
|
|
|
|
|
multishell.hook('paste', function(_, args)
|
2017-10-15 06:36:54 +00:00
|
|
|
if clipboard.internal then
|
2017-10-14 07:41:54 +00:00
|
|
|
args[1] = clipboard.getText() or ''
|
|
|
|
end
|
|
|
|
end)
|
|
|
|
|
2017-10-15 06:36:54 +00:00
|
|
|
-- control-m - toggle clipboard mode
|
|
|
|
multishell.addHotkey(keys.m, function()
|
|
|
|
clipboard.useInternal(not clipboard.internal)
|
2017-10-14 07:41:54 +00:00
|
|
|
end)
|