1
0
mirror of https://github.com/kepler155c/opus synced 2024-11-16 05:34:49 +00:00
opus/sys/apps/system/aliases.lua
2019-04-07 10:09:47 -04:00

73 lines
1.6 KiB
Lua

local Config = require('config')
local UI = require('ui')
local kernel = _G.kernel
local aliasTab = UI.Tab {
tabTitle = 'Aliases',
description = 'Shell aliases',
alias = UI.TextEntry {
x = 2, y = 2, ex = -2,
limit = 32,
shadowText = 'Alias',
},
path = UI.TextEntry {
y = 3, x = 2, ex = -2,
limit = 256,
shadowText = 'Program path',
accelerators = {
enter = 'new_alias',
},
},
grid = UI.Grid {
y = 5,
sortColumn = 'alias',
columns = {
{ heading = 'Alias', key = 'alias' },
{ heading = 'Program', key = 'path' },
},
accelerators = {
delete = 'delete_alias',
},
},
}
function aliasTab.grid:draw()
self.values = { }
local env = Config.load('shell')
for k in pairs(kernel.getShell().aliases()) do
kernel.getShell().clearAlias(k)
end
for k,v in pairs(env.aliases) do
table.insert(self.values, { alias = k, path = v })
kernel.getShell().setAlias(k, v)
end
self:update()
UI.Grid.draw(self)
end
function aliasTab:eventHandler(event)
if event.type == 'delete_alias' then
local env = Config.load('shell', { aliases = { } })
env.aliases[self.grid:getSelected().alias] = nil
Config.update('shell', env)
self.grid:setIndex(self.grid:getIndex())
self.grid:draw()
self:emit({ type = 'success_message', message = 'Aliases updated' })
return true
elseif event.type == 'new_alias' then
local env = Config.load('shell', { aliases = { } })
env.aliases[self.alias.value] = self.path.value
Config.update('shell', env)
self.alias:reset()
self.path:reset()
self:draw()
self:setFocus(self.alias)
self:emit({ type = 'success_message', message = 'Aliases updated' })
return true
end
end
return aliasTab