diff --git a/sys/apps/Files.lua b/sys/apps/Files.lua index f254a97..b39ddd9 100644 --- a/sys/apps/Files.lua +++ b/sys/apps/Files.lua @@ -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) diff --git a/sys/apps/Overview.lua b/sys/apps/Overview.lua index 8cd2c92..92c09bf 100644 --- a/sys/apps/Overview.lua +++ b/sys/apps/Overview.lua @@ -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 diff --git a/sys/apps/network/telnet.lua b/sys/apps/network/telnet.lua index 8bd11de..9aec83c 100644 --- a/sys/apps/network/telnet.lua +++ b/sys/apps/network/telnet.lua @@ -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 diff --git a/sys/modules/opus/alternate.lua b/sys/modules/opus/alternate.lua new file mode 100644 index 0000000..532fc20 --- /dev/null +++ b/sys/modules/opus/alternate.lua @@ -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 diff --git a/sys/modules/opus/util.lua b/sys/modules/opus/util.lua index 4604199..564b9f8 100644 --- a/sys/modules/opus/util.lua +++ b/sys/modules/opus/util.lua @@ -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