mirror of
https://github.com/kepler155c/opus
synced 2025-06-26 23:22:52 +00:00
input redo + env pollution
This commit is contained in:
parent
fb0f3e567a
commit
31b3787695
@ -6,35 +6,35 @@ local os = _G.os
|
|||||||
local modifiers = Util.transpose {
|
local modifiers = Util.transpose {
|
||||||
keys.leftCtrl, keys.rightCtrl,
|
keys.leftCtrl, keys.rightCtrl,
|
||||||
keys.leftShift, keys.rightShift,
|
keys.leftShift, keys.rightShift,
|
||||||
--keys.leftAlt, keys.rightAlt,
|
keys.leftAlt, keys.rightAlt,
|
||||||
}
|
}
|
||||||
|
|
||||||
local input = {
|
local input = {
|
||||||
pressed = { },
|
pressed = { },
|
||||||
}
|
}
|
||||||
|
|
||||||
function input:toCode(code, ch)
|
function input:toCode(ch, code)
|
||||||
|
|
||||||
ch = ch or keys.getName(code)
|
|
||||||
local result = { }
|
local result = { }
|
||||||
|
|
||||||
if self.pressed[keys.leftCtrl] or self.pressed[keys.rightCtrl] then
|
if self.pressed[keys.leftCtrl] or self.pressed[keys.rightCtrl] then
|
||||||
table.insert(result, 'control')
|
table.insert(result, 'control')
|
||||||
end
|
end
|
||||||
|
|
||||||
--if self.pressed[keys.leftAlt] or self.pressed[keys.rightAlt] then
|
if self.pressed[keys.leftAlt] or self.pressed[keys.rightAlt] then
|
||||||
-- table.insert(result, 'alt')
|
table.insert(result, 'alt')
|
||||||
--end
|
|
||||||
|
|
||||||
if self.pressed[keys.leftShift] or self.pressed[keys.rightShift] then
|
|
||||||
if modifiers[code] or #ch > 1 then
|
|
||||||
table.insert(result, 'shift')
|
|
||||||
else
|
|
||||||
ch = ch:upper()
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
if not modifiers[code] then
|
if self.pressed[keys.leftShift] or self.pressed[keys.rightShift] then
|
||||||
|
if code and modifiers[code] then
|
||||||
|
table.insert(result, 'shift')
|
||||||
|
elseif #ch == 1 then
|
||||||
|
table.insert(result, ch:upper())
|
||||||
|
else
|
||||||
|
table.insert(result, 'shift')
|
||||||
|
table.insert(result, keys.getName(code) or ch)
|
||||||
|
end
|
||||||
|
elseif not code or not modifiers[code] then
|
||||||
table.insert(result, ch)
|
table.insert(result, ch)
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -43,7 +43,6 @@ end
|
|||||||
|
|
||||||
function input:reset()
|
function input:reset()
|
||||||
self.pressed = { }
|
self.pressed = { }
|
||||||
self.ch = nil
|
|
||||||
self.fired = nil
|
self.fired = nil
|
||||||
|
|
||||||
self.timer = nil
|
self.timer = nil
|
||||||
@ -55,25 +54,22 @@ function input:translate(event, code, p1, p2)
|
|||||||
if event == 'key' then
|
if event == 'key' then
|
||||||
if p1 then -- key is held down
|
if p1 then -- key is held down
|
||||||
if not modifiers[code] then
|
if not modifiers[code] then
|
||||||
self.fired = input:toCode(code, self.ch)
|
self.fired = input:toCode(keys.getName(code), code)
|
||||||
return self.fired
|
return self.fired
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
self.fired = nil
|
self.fired = nil
|
||||||
self.ch = nil
|
|
||||||
self.pressed[code] = true
|
self.pressed[code] = true
|
||||||
end
|
end
|
||||||
|
|
||||||
elseif event == 'char' then
|
elseif event == 'char' then
|
||||||
self.ch = code
|
self.fired = true
|
||||||
-- reset just in case
|
return input:toCode(code)
|
||||||
self.pressed[keys.leftCtrl] = nil
|
|
||||||
self.pressed[keys.rightCtrl] = nil
|
|
||||||
|
|
||||||
elseif event == 'key_up' then
|
elseif event == 'key_up' then
|
||||||
if not self.fired then
|
if not self.fired then
|
||||||
if self.pressed[code] then
|
if self.pressed[code] then
|
||||||
self.fired = input:toCode(code, self.ch)
|
self.fired = input:toCode(keys.getName(code), code)
|
||||||
self.pressed[code] = nil
|
self.pressed[code] = nil
|
||||||
return self.fired
|
return self.fired
|
||||||
end
|
end
|
||||||
@ -81,11 +77,10 @@ function input:translate(event, code, p1, p2)
|
|||||||
self.pressed[code] = nil
|
self.pressed[code] = nil
|
||||||
|
|
||||||
elseif event == 'paste' then
|
elseif event == 'paste' then
|
||||||
self.ch = 'paste'
|
|
||||||
self.pressed[keys.leftCtrl] = nil
|
self.pressed[keys.leftCtrl] = nil
|
||||||
self.pressed[keys.rightCtrl] = nil
|
self.pressed[keys.rightCtrl] = nil
|
||||||
self.fired = input:toCode(0, self.ch)
|
self.fired = true
|
||||||
return self.fired
|
return input:toCode('paste')
|
||||||
|
|
||||||
elseif event == 'mouse_click' then
|
elseif event == 'mouse_click' then
|
||||||
local buttons = { 'mouse_click', 'mouse_rightclick' }
|
local buttons = { 'mouse_click', 'mouse_rightclick' }
|
||||||
@ -93,9 +88,8 @@ function input:translate(event, code, p1, p2)
|
|||||||
self.mfired = nil
|
self.mfired = nil
|
||||||
|
|
||||||
elseif event == 'mouse_drag' then
|
elseif event == 'mouse_drag' then
|
||||||
self.mch = 'mouse_drag'
|
self.mfired = true
|
||||||
self.mfired = input:toCode(0, self.mch)
|
return input:toCode('mouse_drag')
|
||||||
return self.mfired
|
|
||||||
|
|
||||||
elseif event == 'mouse_up' then
|
elseif event == 'mouse_up' then
|
||||||
if not self.mfired then
|
if not self.mfired then
|
||||||
@ -111,11 +105,12 @@ function input:translate(event, code, p1, p2)
|
|||||||
self.x = p1
|
self.x = p1
|
||||||
self.y = p2
|
self.y = p2
|
||||||
end
|
end
|
||||||
self.mfired = input:toCode(0, self.mch)
|
self.mfired = input:toCode(self.mch)
|
||||||
else
|
else
|
||||||
self.mch = 'mouse_up'
|
self.mch = 'mouse_up'
|
||||||
self.mfired = input:toCode(0, self.mch)
|
self.mfired = input:toCode(self.mch)
|
||||||
end
|
end
|
||||||
|
self.fired = true
|
||||||
return self.mfired
|
return self.mfired
|
||||||
|
|
||||||
elseif event == "mouse_scroll" then
|
elseif event == "mouse_scroll" then
|
||||||
@ -123,8 +118,8 @@ function input:translate(event, code, p1, p2)
|
|||||||
[ -1 ] = 'scrollUp',
|
[ -1 ] = 'scrollUp',
|
||||||
[ 1 ] = 'scrollDown'
|
[ 1 ] = 'scrollDown'
|
||||||
}
|
}
|
||||||
self.mch = directions[code]
|
self.fired = true
|
||||||
return input:toCode(0, self.mch)
|
return input:toCode(directions[code])
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -10,8 +10,6 @@ local _sub = string.sub
|
|||||||
local colors = _G.colors
|
local colors = _G.colors
|
||||||
local device = _G.device
|
local device = _G.device
|
||||||
local fs = _G.fs
|
local fs = _G.fs
|
||||||
local keys = _G.keys
|
|
||||||
local multishell = _ENV.multishell
|
|
||||||
local os = _G.os
|
local os = _G.os
|
||||||
local term = _G.term
|
local term = _G.term
|
||||||
|
|
||||||
@ -121,7 +119,7 @@ function Manager:init()
|
|||||||
|
|
||||||
if ch == 'control-shift-mouse_click' then -- hack
|
if ch == 'control-shift-mouse_click' then -- hack
|
||||||
local event = self:pointToChild(self.target, x, y)
|
local event = self:pointToChild(self.target, x, y)
|
||||||
multishell.openTab({
|
_ENV.multishell.openTab({
|
||||||
path = 'sys/apps/Lua.lua',
|
path = 'sys/apps/Lua.lua',
|
||||||
args = { event.element, self:dump(self.currentPage) },
|
args = { event.element, self:dump(self.currentPage) },
|
||||||
focused = true })
|
focused = true })
|
||||||
@ -152,12 +150,8 @@ function Manager:init()
|
|||||||
self.currentPage:sync()
|
self.currentPage:sync()
|
||||||
end)
|
end)
|
||||||
|
|
||||||
singleThread('char', function(ch)
|
local function keyFunction(event, code, held)
|
||||||
Input:translate('char', ch)
|
local ch = Input:translate(event, code, held)
|
||||||
end)
|
|
||||||
|
|
||||||
singleThread('key_up', function(code)
|
|
||||||
local ch = Input:translate('key_up', code)
|
|
||||||
|
|
||||||
if ch and self.currentPage then
|
if ch and self.currentPage then
|
||||||
local target = self.currentPage.focused or self.currentPage
|
local target = self.currentPage.focused or self.currentPage
|
||||||
@ -165,18 +159,11 @@ function Manager:init()
|
|||||||
{ type = 'key', key = ch, element = target })
|
{ type = 'key', key = ch, element = target })
|
||||||
self.currentPage:sync()
|
self.currentPage:sync()
|
||||||
end
|
end
|
||||||
end)
|
end
|
||||||
|
|
||||||
singleThread('key', function(code, held)
|
singleThread('char', function(code, held) keyFunction('char', code, held) end)
|
||||||
local ch = Input:translate('key', code, held)
|
singleThread('key_up', function(code, held) keyFunction('key_up', code, held) end)
|
||||||
|
singleThread('key', function(code, held) keyFunction('key', code, held) end)
|
||||||
if ch and self.currentPage then
|
|
||||||
local target = self.currentPage.focused or self.currentPage
|
|
||||||
self:inputEvent(target,
|
|
||||||
{ type = 'key', key = ch, element = target })
|
|
||||||
self.currentPage:sync()
|
|
||||||
end
|
|
||||||
end)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
function Manager:configure(appName, ...)
|
function Manager:configure(appName, ...)
|
||||||
@ -1156,6 +1143,7 @@ function UI.Page:setParent()
|
|||||||
UI.Window.setParent(self)
|
UI.Window.setParent(self)
|
||||||
if self.z then
|
if self.z then
|
||||||
self.canvas = self:addLayer(self.backgroundColor, self.textColor)
|
self.canvas = self:addLayer(self.backgroundColor, self.textColor)
|
||||||
|
self.canvas:clear(self.backgroundColor, self.textColor)
|
||||||
else
|
else
|
||||||
self.canvas = self.parent.canvas
|
self.canvas = self.parent.canvas
|
||||||
end
|
end
|
||||||
@ -2281,6 +2269,19 @@ function UI.Wizard:postInit()
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function UI.Wizard:add(pages)
|
||||||
|
Util.merge(self.pages, pages)
|
||||||
|
Util.merge(self, pages)
|
||||||
|
|
||||||
|
for _, child in pairs(self.pages) do
|
||||||
|
child.ey = child.ey or -2
|
||||||
|
end
|
||||||
|
|
||||||
|
if self.parent then
|
||||||
|
self:initChildren()
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
function UI.Wizard:enable()
|
function UI.Wizard:enable()
|
||||||
self.enabled = true
|
self.enabled = true
|
||||||
for _,child in ipairs(self.children) do
|
for _,child in ipairs(self.children) do
|
||||||
@ -2300,10 +2301,10 @@ function UI.Wizard:nextView()
|
|||||||
local nextView = Util.find(self.pages, 'index', currentView.index + 1)
|
local nextView = Util.find(self.pages, 'index', currentView.index + 1)
|
||||||
|
|
||||||
if nextView then
|
if nextView then
|
||||||
|
self:emit({ type = 'enable_view', view = nextView })
|
||||||
self:addTransition('slideLeft')
|
self:addTransition('slideLeft')
|
||||||
currentView:disable()
|
currentView:disable()
|
||||||
nextView:enable()
|
nextView:enable()
|
||||||
self:emit({ type = 'enable_view', view = nextView })
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -2312,10 +2313,10 @@ function UI.Wizard:prevView()
|
|||||||
local nextView = Util.find(self.pages, 'index', currentView.index - 1)
|
local nextView = Util.find(self.pages, 'index', currentView.index - 1)
|
||||||
|
|
||||||
if nextView then
|
if nextView then
|
||||||
|
self:emit({ type = 'enable_view', view = nextView })
|
||||||
self:addTransition('slideRight')
|
self:addTransition('slideRight')
|
||||||
currentView:disable()
|
currentView:disable()
|
||||||
nextView:enable()
|
nextView:enable()
|
||||||
self:emit({ type = 'enable_view', view = nextView })
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -2323,10 +2324,12 @@ function UI.Wizard:eventHandler(event)
|
|||||||
if event.type == 'nextView' then
|
if event.type == 'nextView' then
|
||||||
self:nextView()
|
self:nextView()
|
||||||
self:draw()
|
self:draw()
|
||||||
|
return true
|
||||||
|
|
||||||
elseif event.type == 'previousView' then
|
elseif event.type == 'previousView' then
|
||||||
self:prevView()
|
self:prevView()
|
||||||
self:draw()
|
self:draw()
|
||||||
|
return true
|
||||||
|
|
||||||
elseif event.type == 'enable_view' then
|
elseif event.type == 'enable_view' then
|
||||||
if Util.find(self.pages, 'index', event.view.index - 1) then
|
if Util.find(self.pages, 'index', event.view.index - 1) then
|
||||||
|
@ -312,7 +312,6 @@ function Canvas:applyPalette(palette)
|
|||||||
end
|
end
|
||||||
|
|
||||||
function Canvas.convertWindow(win, parent, wx, wy)
|
function Canvas.convertWindow(win, parent, wx, wy)
|
||||||
|
|
||||||
local w, h = win.getSize()
|
local w, h = win.getSize()
|
||||||
|
|
||||||
win.canvas = Canvas({
|
win.canvas = Canvas({
|
||||||
@ -355,7 +354,7 @@ function Canvas.convertWindow(win, parent, wx, wy)
|
|||||||
end
|
end
|
||||||
|
|
||||||
function win.scroll()
|
function win.scroll()
|
||||||
error('CWin:scroll: not implemented')
|
error('scroll: not implemented')
|
||||||
end
|
end
|
||||||
|
|
||||||
function win.reposition(x, y, width, height)
|
function win.reposition(x, y, width, height)
|
||||||
|
@ -141,7 +141,7 @@ function Util.key(t, value)
|
|||||||
end
|
end
|
||||||
|
|
||||||
function Util.keys(t)
|
function Util.keys(t)
|
||||||
local keys = {}
|
local keys = { }
|
||||||
for k in pairs(t) do
|
for k in pairs(t) do
|
||||||
keys[#keys+1] = k
|
keys[#keys+1] = k
|
||||||
end
|
end
|
||||||
@ -283,6 +283,19 @@ function Util.each(list, func)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function Util.rpairs(t)
|
||||||
|
local tkeys = Util.keys(t)
|
||||||
|
local i = #tkeys
|
||||||
|
return function()
|
||||||
|
local key = tkeys[i]
|
||||||
|
local k,v = key, t[key]
|
||||||
|
i = i - 1
|
||||||
|
if v then
|
||||||
|
return k, v
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
-- http://stackoverflow.com/questions/15706270/sort-a-table-in-lua
|
-- http://stackoverflow.com/questions/15706270/sort-a-table-in-lua
|
||||||
function Util.spairs(t, order)
|
function Util.spairs(t, order)
|
||||||
local keys = Util.keys(t)
|
local keys = Util.keys(t)
|
||||||
|
@ -64,7 +64,6 @@ function topicPage:eventHandler(event)
|
|||||||
end
|
end
|
||||||
|
|
||||||
function page:eventHandler(event)
|
function page:eventHandler(event)
|
||||||
|
|
||||||
if event.type == 'quit' then
|
if event.type == 'quit' then
|
||||||
UI:exitPullEvents()
|
UI:exitPullEvents()
|
||||||
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
local defaultEnv = { }
|
local sandboxEnv = { }
|
||||||
for k,v in pairs(_ENV) do
|
for k,v in pairs(_ENV) do
|
||||||
defaultEnv[k] = v
|
sandboxEnv[k] = v
|
||||||
end
|
end
|
||||||
|
|
||||||
_G.requireInjector()
|
_G.requireInjector()
|
||||||
@ -127,7 +127,7 @@ local function selectTab(tab)
|
|||||||
if coroutine.status(currentTab.co) == 'suspended' then
|
if coroutine.status(currentTab.co) == 'suspended' then
|
||||||
-- the process that opens a new tab won't get the lose focus event
|
-- the process that opens a new tab won't get the lose focus event
|
||||||
-- os.queueEvent('multishell_notifyfocus', currentTab.tabId)
|
-- os.queueEvent('multishell_notifyfocus', currentTab.tabId)
|
||||||
resumeTab(currentTab, 'multishell_losefocus')
|
--resumeTab(currentTab, 'multishell_losefocus')
|
||||||
end
|
end
|
||||||
if tab and not currentTab.hidden then
|
if tab and not currentTab.hidden then
|
||||||
tab.previousTabId = currentTab.tabId
|
tab.previousTabId = currentTab.tabId
|
||||||
@ -151,7 +151,7 @@ local function launchProcess(tab)
|
|||||||
tab.timestamp = os.clock()
|
tab.timestamp = os.clock()
|
||||||
tab.window = window.create(parentTerm, 1, 2, w, h - 1, false)
|
tab.window = window.create(parentTerm, 1, 2, w, h - 1, false)
|
||||||
tab.terminal = tab.window
|
tab.terminal = tab.window
|
||||||
tab.env = Util.shallowCopy(tab.env or defaultEnv)
|
tab.env = Util.shallowCopy(tab.env or sandboxEnv)
|
||||||
|
|
||||||
tab.co = coroutine.create(function()
|
tab.co = coroutine.create(function()
|
||||||
|
|
||||||
@ -229,7 +229,9 @@ end
|
|||||||
function multishell.setTitle(tabId, title)
|
function multishell.setTitle(tabId, title)
|
||||||
local tab = tabs[tabId]
|
local tab = tabs[tabId]
|
||||||
if tab then
|
if tab then
|
||||||
tab.title = title or ''
|
if not tab.isOverview then
|
||||||
|
tab.title = title or ''
|
||||||
|
end
|
||||||
redrawMenu()
|
redrawMenu()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -329,7 +329,8 @@ end
|
|||||||
|
|
||||||
local tArgs = { ... }
|
local tArgs = { ... }
|
||||||
if #tArgs > 0 then
|
if #tArgs > 0 then
|
||||||
return run(_ENV, ...)
|
local env = setmetatable(Util.shallowCopy(sandboxEnv), { __index = _G })
|
||||||
|
return run(env, ...)
|
||||||
end
|
end
|
||||||
|
|
||||||
local Config = require('config')
|
local Config = require('config')
|
||||||
|
@ -36,9 +36,14 @@ term.setCursorPos(w, h)
|
|||||||
local GIT_REPO = 'kepler155c/opus/develop'
|
local GIT_REPO = 'kepler155c/opus/develop'
|
||||||
local BASE = 'https://raw.githubusercontent.com/' .. GIT_REPO
|
local BASE = 'https://raw.githubusercontent.com/' .. GIT_REPO
|
||||||
|
|
||||||
|
local sandboxEnv = setmetatable({ }, { __index = _G })
|
||||||
|
for k,v in pairs(_ENV) do
|
||||||
|
sandboxEnv[k] = v
|
||||||
|
end
|
||||||
|
|
||||||
local function makeEnv()
|
local function makeEnv()
|
||||||
local env = setmetatable({ }, { __index = _G })
|
local env = setmetatable({ }, { __index = _G })
|
||||||
for k,v in pairs(_ENV) do
|
for k,v in pairs(sandboxEnv) do
|
||||||
env[k] = v
|
env[k] = v
|
||||||
end
|
end
|
||||||
return env
|
return env
|
||||||
@ -113,7 +118,7 @@ if config.aliases then
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
shell.setPath(config.path)
|
shell.setPath(config.path)
|
||||||
_ENV.LUA_PATH = config.lua_path
|
sandboxEnv.LUA_PATH = config.lua_path
|
||||||
|
|
||||||
-- extensions
|
-- extensions
|
||||||
local dir = 'sys/extensions'
|
local dir = 'sys/extensions'
|
||||||
|
@ -133,7 +133,7 @@ local methods = { 'delete', 'getFreeSpace', 'exists', 'isDir', 'getSize',
|
|||||||
|
|
||||||
for _,m in pairs(methods) do
|
for _,m in pairs(methods) do
|
||||||
fs[m] = function(dir, ...)
|
fs[m] = function(dir, ...)
|
||||||
dir = fs.combine(dir, '')
|
dir = fs.combine(dir or '', '')
|
||||||
local node = getNode(dir)
|
local node = getNode(dir)
|
||||||
return node.fs[m](node, dir, ...)
|
return node.fs[m](node, dir, ...)
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user