opus/sys/apps/System.lua

185 lines
4.5 KiB
Lua
Raw Normal View History

requireInjector(getfenv(1))
2016-12-11 19:24:52 +00:00
local Config = require('config')
local Event = require('event')
local UI = require('ui')
local Util = require('util')
2016-12-11 19:24:52 +00:00
multishell.setTitle(multishell.getCurrent(), 'System')
UI:configure('System', ...)
local env = {
path = shell.path(),
aliases = shell.aliases(),
lua_path = LUA_PATH,
}
2017-09-26 19:18:44 +00:00
Config.load('shell', env)
2016-12-11 19:24:52 +00:00
2016-12-14 18:54:13 +00:00
local systemPage = UI.Page {
tabs = UI.Tabs {
pathTab = UI.Window {
2016-12-11 19:24:52 +00:00
tabTitle = 'Path',
2016-12-14 18:54:13 +00:00
entry = UI.TextEntry {
2017-09-30 02:30:01 +00:00
x = 2, y = 2, ex = -2,
2016-12-14 18:54:13 +00:00
limit = 256,
2016-12-11 19:24:52 +00:00
value = shell.path(),
shadowText = 'enter system path',
accelerators = {
enter = 'update_path',
},
2016-12-14 18:54:13 +00:00
},
grid = UI.Grid {
2016-12-11 19:24:52 +00:00
y = 4,
values = paths,
disableHeader = true,
columns = { { key = 'value' } },
autospace = true,
2016-12-14 18:54:13 +00:00
},
},
2016-12-11 19:24:52 +00:00
2016-12-14 18:54:13 +00:00
aliasTab = UI.Window {
2016-12-11 19:24:52 +00:00
tabTitle = 'Aliases',
2016-12-14 18:54:13 +00:00
alias = UI.TextEntry {
2017-09-30 02:30:01 +00:00
x = 2, y = 2, ex = -2,
2016-12-11 19:24:52 +00:00
limit = 32,
shadowText = 'Alias',
2016-12-14 18:54:13 +00:00
},
path = UI.TextEntry {
2017-09-30 02:30:01 +00:00
y = 3, x = 2, ex = -2,
2016-12-14 18:54:13 +00:00
limit = 256,
2016-12-11 19:24:52 +00:00
shadowText = 'Program path',
accelerators = {
enter = 'new_alias',
},
2016-12-14 18:54:13 +00:00
},
grid = UI.Grid {
y = 5,
values = aliases,
autospace = true,
sortColumn = 'alias',
2016-12-11 19:24:52 +00:00
columns = {
{ heading = 'Alias', key = 'alias' },
{ heading = 'Program', key = 'path' },
},
accelerators = {
delete = 'delete_alias',
},
2016-12-14 18:54:13 +00:00
},
},
2016-12-11 19:24:52 +00:00
2016-12-14 18:54:13 +00:00
infoTab = UI.Window {
2016-12-11 19:24:52 +00:00
tabTitle = 'Info',
2016-12-14 18:54:13 +00:00
labelText = UI.Text {
x = 3, y = 2,
value = 'Label'
},
label = UI.TextEntry {
2017-09-30 02:30:01 +00:00
x = 9, y = 2, ex = -4,
2016-12-14 18:54:13 +00:00
limit = 32,
value = os.getComputerLabel(),
2016-12-11 19:24:52 +00:00
accelerators = {
enter = 'update_label',
},
2016-12-14 18:54:13 +00:00
},
grid = UI.ScrollingGrid {
2017-09-26 02:49:44 +00:00
y = 3,
2016-12-11 19:24:52 +00:00
values = {
2017-09-26 02:49:44 +00:00
{ name = '', value = '' },
{ name = 'CC version', value = Util.getVersion() },
2016-12-11 19:24:52 +00:00
{ name = 'Lua version', value = _VERSION },
{ name = 'MC version', value = _MC_VERSION or 'unknown' },
{ name = 'Disk free', value = Util.toBytes(fs.getFreeSpace('/')) },
{ name = 'Computer ID', value = tostring(os.getComputerID()) },
{ name = 'Day', value = tostring(os.day()) },
},
inactive = true,
2016-12-11 19:24:52 +00:00
columns = {
2017-10-01 00:35:36 +00:00
{ key = 'name', width = 12 },
{ key = 'value' },
2016-12-11 19:24:52 +00:00
},
2016-12-14 18:54:13 +00:00
},
},
},
2016-12-11 19:24:52 +00:00
notification = UI.Notification(),
accelerators = {
q = 'quit',
},
2016-12-14 18:54:13 +00:00
}
2016-12-11 19:24:52 +00:00
function systemPage.tabs.pathTab.grid:draw()
self.values = { }
for _,v in ipairs(Util.split(env.path, '(.-):')) do
table.insert(self.values, { value = v })
end
self:update()
UI.Grid.draw(self)
end
function systemPage.tabs.pathTab:eventHandler(event)
if event.type == 'update_path' then
env.path = self.entry.value
self.grid:setIndex(self.grid:getIndex())
self.grid:draw()
2017-09-26 19:18:44 +00:00
Config.update('shell', env)
2016-12-11 19:24:52 +00:00
systemPage.notification:success('reboot to take effect')
2016-12-14 18:54:13 +00:00
return true
2016-12-11 19:24:52 +00:00
end
end
function systemPage.tabs.aliasTab.grid:draw()
self.values = { }
local aliases = { }
for k,v in pairs(env.aliases) do
table.insert(self.values, { alias = k, path = v })
end
self:update()
UI.Grid.draw(self)
end
function systemPage.tabs.aliasTab:eventHandler(event)
if event.type == 'delete_alias' then
env.aliases[self.grid:getSelected().alias] = nil
self.grid:setIndex(self.grid:getIndex())
self.grid:draw()
2017-09-26 19:18:44 +00:00
Config.update('shell', env)
2016-12-11 19:24:52 +00:00
systemPage.notification:success('reboot to take effect')
2016-12-14 18:54:13 +00:00
return true
2016-12-11 19:24:52 +00:00
elseif event.type == 'new_alias' then
env.aliases[self.alias.value] = self.path.value
self.alias:reset()
self.path:reset()
self:draw()
self:setFocus(self.alias)
2017-09-26 19:18:44 +00:00
Config.update('shell', env)
2016-12-11 19:24:52 +00:00
systemPage.notification:success('reboot to take effect')
2016-12-14 18:54:13 +00:00
return true
2016-12-11 19:24:52 +00:00
end
end
function systemPage.tabs.infoTab:eventHandler(event)
if event.type == 'update_label' then
os.setComputerLabel(self.label.value)
systemPage.notification:success('Label updated')
return true
end
end
function systemPage:eventHandler(event)
if event.type == 'quit' then
Event.exitPullEvents()
elseif event.type == 'tab_activate' then
event.activated:focusFirst()
else
return UI.Page.eventHandler(self, event)
end
return true
end
UI:setPage(systemPage)
Event.pullEvents()
UI.term:reset()