mirror of
https://github.com/kepler155c/opus
synced 2024-12-31 19:00:27 +00:00
alternatives
This commit is contained in:
parent
6d8d62d309
commit
57ea46dde7
@ -1,3 +1,4 @@
|
||||
local Alt = require('opus.alternate')
|
||||
local Config = require('opus.config')
|
||||
local Event = require('opus.event')
|
||||
local pastebin = require('opus.http.pastebin')
|
||||
@ -353,7 +354,7 @@ function Browser:eventHandler(event)
|
||||
self:setStatus('Started cloud edit')
|
||||
|
||||
elseif event.type == 'shell' then
|
||||
self:run('sys/apps/shell.lua')
|
||||
self:run(Alt.get('shell'))
|
||||
|
||||
elseif event.type == 'refresh' then
|
||||
self:updateDirectory(self.dir)
|
||||
|
@ -1,3 +1,4 @@
|
||||
local Alt = require('opus.alternate')
|
||||
local class = require('opus.class')
|
||||
local Config = require('opus.config')
|
||||
local Event = require('opus.event')
|
||||
@ -420,13 +421,13 @@ function page:eventHandler(event)
|
||||
shell.switchTab(shell.openTab(event.button.app.run))
|
||||
|
||||
elseif event.type == 'shell' then
|
||||
shell.switchTab(shell.openTab('sys/apps/shell.lua'))
|
||||
shell.switchTab(shell.openTab(Alt.get('shell')))
|
||||
|
||||
elseif event.type == 'lua' then
|
||||
shell.switchTab(shell.openTab('sys/apps/Lua.lua'))
|
||||
shell.switchTab(shell.openTab(Alt.get('lua')))
|
||||
|
||||
elseif event.type == 'files' then
|
||||
shell.switchTab(shell.openTab('sys/apps/Files.lua'))
|
||||
shell.switchTab(shell.openTab(Alt.get('files')))
|
||||
|
||||
elseif event.type == 'focus_change' then
|
||||
if event.focused.parent.UIElement == 'Icon' then
|
||||
|
@ -1,3 +1,4 @@
|
||||
local Alt = require('opus.alternate')
|
||||
local Event = require('opus.event')
|
||||
local Socket = require('opus.socket')
|
||||
local Util = require('opus.util')
|
||||
@ -46,7 +47,7 @@ local function telnetHost(socket, mode)
|
||||
title = mode .. ' client',
|
||||
hidden = true,
|
||||
co = coroutine.create(function()
|
||||
Util.run(_ENV, 'sys/apps/shell.lua', table.unpack(termInfo.program))
|
||||
Util.run(_ENV, Alt.get('shell'), table.unpack(termInfo.program))
|
||||
if socket.queue then
|
||||
socket:write(socket.queue)
|
||||
end
|
||||
|
52
sys/modules/opus/alternate.lua
Normal file
52
sys/modules/opus/alternate.lua
Normal file
@ -0,0 +1,52 @@
|
||||
local Config = require('opus.config')
|
||||
local Util = require('opus.util')
|
||||
|
||||
local function getConfig()
|
||||
return Config.load('alternate', {
|
||||
default = {
|
||||
shell = 'sys/apps/shell.lua',
|
||||
lua = 'sys/apps/Lua.lua',
|
||||
files = 'sys/apps/Files.lua',
|
||||
},
|
||||
choices = {
|
||||
shell = {
|
||||
'sys/apps/shell.lua',
|
||||
'rom/programs/shell',
|
||||
},
|
||||
lua = {
|
||||
'sys/apps/Lua.lua',
|
||||
'rom/programs/lua.lua',
|
||||
},
|
||||
files = {
|
||||
'sys/apps/Files.lua',
|
||||
}
|
||||
}
|
||||
})
|
||||
end
|
||||
|
||||
local Alt = { }
|
||||
|
||||
function Alt.get(key)
|
||||
return getConfig().default[key]
|
||||
end
|
||||
|
||||
function Alt.set(key, value)
|
||||
local config = getConfig()
|
||||
|
||||
config.default[key] = value
|
||||
Config.update('alternate', config)
|
||||
end
|
||||
|
||||
function Alt.addChoice(key, value)
|
||||
local config = getConfig()
|
||||
|
||||
if not config.choices[key] then
|
||||
config.choices[key] = { }
|
||||
end
|
||||
if not Util.contains(config.choices[key], value) then
|
||||
config.choices[key] = value
|
||||
Config.update('alternate', config)
|
||||
end
|
||||
end
|
||||
|
||||
return Alt
|
@ -621,17 +621,17 @@ end
|
||||
|
||||
-- http://snippets.luacode.org/?p=snippets/trim_whitespace_from_string_76
|
||||
function Util.trim(s)
|
||||
return s:find'^%s*$' and '' or s:match'^%s*(.*%S)'
|
||||
return s:find('^%s*$') and '' or s:match('^%s*(.*%S)')
|
||||
end
|
||||
|
||||
-- trim whitespace from left end of string
|
||||
function Util.triml(s)
|
||||
return s:match'^%s*(.*)'
|
||||
return s:match('^%s*(.*)')
|
||||
end
|
||||
|
||||
-- trim whitespace from right end of string
|
||||
function Util.trimr(s)
|
||||
return s:find'^%s*$' and '' or s:match'^(.*%S)'
|
||||
return s:find('^%s*$') and '' or s:match('^(.*%S)')
|
||||
end
|
||||
-- end http://snippets.luacode.org/?p=snippets/trim_whitespace_from_string_76
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user