alternatives

This commit is contained in:
kepler155c@gmail.com
2019-11-08 19:54:41 -07:00
parent 6d8d62d309
commit 57ea46dde7
5 changed files with 63 additions and 8 deletions

View 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

View File

@@ -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