2017-09-05 06:09:31 +00:00
|
|
|
requireInjector(getfenv(1))
|
|
|
|
|
2016-12-11 19:24:52 +00:00
|
|
|
local Config = require('config')
|
2017-09-05 06:09:31 +00:00
|
|
|
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,
|
|
|
|
}
|
|
|
|
Config.load('multishell', env)
|
|
|
|
|
|
|
|
UI.TextEntry.defaults.backgroundFocusColor = colors.black
|
|
|
|
|
2016-12-14 18:54:13 +00:00
|
|
|
local systemPage = UI.Page {
|
2017-09-26 02:49:44 +00:00
|
|
|
backgroundColor = colors.cyan,
|
2016-12-14 18:54:13 +00:00
|
|
|
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 {
|
|
|
|
x = 2, y = 2, rex = -2,
|
|
|
|
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 {
|
|
|
|
x = 2, y = 2, rex = -2,
|
2016-12-11 19:24:52 +00:00
|
|
|
limit = 32,
|
|
|
|
shadowText = 'Alias',
|
2016-12-14 18:54:13 +00:00
|
|
|
},
|
|
|
|
path = UI.TextEntry {
|
|
|
|
y = 3, x = 2, rex = -2,
|
|
|
|
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 {
|
2016-12-18 19:38:48 +00:00
|
|
|
x = 9, y = 2, rex = -4,
|
2016-12-14 18:54:13 +00:00
|
|
|
limit = 32,
|
|
|
|
value = os.getComputerLabel(),
|
2016-12-11 19:24:52 +00:00
|
|
|
backgroundFocusColor = colors.black,
|
|
|
|
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 = '' },
|
2017-09-05 06:09:31 +00:00
|
|
|
{ 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()) },
|
|
|
|
},
|
|
|
|
selectable = false,
|
2017-09-26 02:49:44 +00:00
|
|
|
--backgroundColor = colors.blue,
|
2016-12-11 19:24:52 +00:00
|
|
|
columns = {
|
|
|
|
{ key = 'name', width = 12 },
|
|
|
|
{ key = 'value', width = UI.term.width - 15 },
|
|
|
|
},
|
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()
|
|
|
|
Config.update('multishell', env)
|
|
|
|
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()
|
|
|
|
Config.update('multishell', env)
|
|
|
|
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)
|
|
|
|
Config.update('multishell', env)
|
|
|
|
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()
|