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
|
|
|
|
|
|
|
local multishell = _ENV.multishell
|
|
|
|
local os = _G.os
|
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.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
|
|
|
|
return Util.tostring(clipboard.data)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
function clipboard.isInternal()
|
|
|
|
return clipboard.internal
|
|
|
|
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
|
|
|
os.queueEvent('clipboard_mode', mode)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-10-14 07:41:54 +00:00
|
|
|
multishell.hook('clipboard_copy', function(_, args)
|
|
|
|
clipboard.setData(args[1])
|
|
|
|
end)
|
|
|
|
|
|
|
|
multishell.hook('paste', function(_, args)
|
|
|
|
if clipboard.isInternal() then
|
|
|
|
args[1] = clipboard.getText() or ''
|
|
|
|
end
|
|
|
|
end)
|
|
|
|
|
|
|
|
-- control-m - clipboard mode
|
|
|
|
multishell.addHotkey(50, function()
|
|
|
|
clipboard.useInternal(not clipboard.isInternal())
|
|
|
|
end)
|