2019-06-28 17:50:02 +00:00
|
|
|
local Config = require('opus.config')
|
|
|
|
local UI = require('opus.ui')
|
|
|
|
local Util = require('opus.util')
|
2019-03-28 11:29:01 +00:00
|
|
|
|
|
|
|
local colors = _G.colors
|
|
|
|
local os = _G.os
|
|
|
|
|
|
|
|
local config = Config.load('shellprompt')
|
|
|
|
|
|
|
|
local allColors = { }
|
|
|
|
for k,v in pairs(colors) do
|
2019-06-18 19:19:24 +00:00
|
|
|
if type(v) == 'number' then
|
|
|
|
table.insert(allColors, { name = k, value = v })
|
|
|
|
end
|
2019-03-28 11:29:01 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
local defaults = {
|
2019-06-18 19:19:24 +00:00
|
|
|
textColor = colors.white,
|
|
|
|
commandTextColor = colors.yellow,
|
|
|
|
directoryTextColor = colors.orange,
|
|
|
|
promptTextColor = colors.blue,
|
|
|
|
directoryColor = colors.green,
|
|
|
|
fileColor = colors.white,
|
|
|
|
backgroundColor = colors.black,
|
2019-03-28 11:29:01 +00:00
|
|
|
}
|
|
|
|
local _colors = config.color or Util.shallowCopy(defaults)
|
|
|
|
|
|
|
|
local allSettings = { }
|
2020-04-22 04:40:59 +00:00
|
|
|
for k in pairs(defaults) do
|
2019-06-18 19:19:24 +00:00
|
|
|
table.insert(allSettings, { name = k })
|
2019-03-28 11:29:01 +00:00
|
|
|
end
|
|
|
|
|
2019-03-28 11:39:34 +00:00
|
|
|
-- temp
|
|
|
|
if not _colors.backgroundColor then
|
2019-06-18 19:19:24 +00:00
|
|
|
_colors.backgroundColor = colors.black
|
|
|
|
_colors.fileColor = colors.white
|
2019-03-28 11:39:34 +00:00
|
|
|
end
|
|
|
|
|
2020-04-22 04:40:59 +00:00
|
|
|
return UI.Tab {
|
2020-04-27 01:39:58 +00:00
|
|
|
title = 'Shell',
|
2019-06-18 19:19:24 +00:00
|
|
|
description = 'Shell options',
|
|
|
|
grid1 = UI.ScrollingGrid {
|
2020-04-22 04:40:59 +00:00
|
|
|
y = 2, ey = -10, x = 2, ex = -17,
|
2019-03-28 11:29:01 +00:00
|
|
|
disableHeader = true,
|
2019-06-18 19:19:24 +00:00
|
|
|
columns = { { key = 'name' } },
|
|
|
|
values = allSettings,
|
|
|
|
sortColumn = 'name',
|
2019-03-28 11:29:01 +00:00
|
|
|
},
|
2019-06-18 19:19:24 +00:00
|
|
|
grid2 = UI.ScrollingGrid {
|
2020-04-22 04:40:59 +00:00
|
|
|
y = 2, ey = -10, x = -14, ex = -2,
|
2019-03-28 11:29:01 +00:00
|
|
|
disableHeader = true,
|
|
|
|
columns = { { key = 'name' } },
|
2019-06-18 19:19:24 +00:00
|
|
|
values = allColors,
|
|
|
|
sortColumn = 'name',
|
2020-04-22 04:40:59 +00:00
|
|
|
getRowTextColor = function(self, row)
|
|
|
|
local selected = self.parent.grid1:getSelected()
|
|
|
|
if _colors[selected.name] == row.value then
|
|
|
|
return colors.yellow
|
|
|
|
end
|
|
|
|
return UI.Grid.getRowTextColor(self, row)
|
|
|
|
end
|
2019-06-18 19:19:24 +00:00
|
|
|
},
|
|
|
|
directory = UI.Checkbox {
|
2020-04-22 04:40:59 +00:00
|
|
|
x = 2, y = -2,
|
|
|
|
labelBackgroundColor = colors.black,
|
|
|
|
label = 'Directory',
|
2019-06-18 19:19:24 +00:00
|
|
|
value = config.displayDirectory
|
|
|
|
},
|
|
|
|
reset = UI.Button {
|
|
|
|
x = -18, y = -2,
|
|
|
|
text = 'Reset',
|
|
|
|
event = 'reset',
|
|
|
|
},
|
|
|
|
button = UI.Button {
|
|
|
|
x = -9, y = -2,
|
|
|
|
text = 'Update',
|
|
|
|
event = 'update',
|
|
|
|
},
|
|
|
|
display = UI.Window {
|
2020-04-22 04:40:59 +00:00
|
|
|
x = 2, ex = -2, y = -8, height = 5,
|
|
|
|
draw = function(self)
|
|
|
|
self:clear(_colors.backgroundColor)
|
|
|
|
local offset = 0
|
|
|
|
if config.displayDirectory then
|
|
|
|
self:write(1, 1,
|
|
|
|
'==' .. os.getComputerLabel() .. ':/dir/etc',
|
2020-06-13 18:18:04 +00:00
|
|
|
_colors.backgroundColor, _colors.directoryTextColor)
|
2020-04-22 04:40:59 +00:00
|
|
|
offset = 1
|
|
|
|
end
|
|
|
|
|
|
|
|
self:write(1, 1 + offset, '$ ',
|
2020-06-13 18:18:04 +00:00
|
|
|
_colors.backgroundColor, _colors.promptTextColor)
|
2020-04-22 04:40:59 +00:00
|
|
|
|
|
|
|
self:write(3, 1 + offset, 'ls /',
|
|
|
|
_colors.backgroundColor, _colors.commandTextColor)
|
|
|
|
|
|
|
|
self:write(1, 2 + offset, 'sys usr',
|
|
|
|
_colors.backgroundColor, _colors.directoryColor)
|
|
|
|
|
|
|
|
self:write(1, 3 + offset, 'startup',
|
|
|
|
_colors.backgroundColor, _colors.fileColor)
|
|
|
|
end,
|
2019-03-28 11:29:01 +00:00
|
|
|
},
|
2020-04-22 04:40:59 +00:00
|
|
|
eventHandler = function(self, event)
|
|
|
|
if event.type =='checkbox_change' then
|
|
|
|
config.displayDirectory = not not event.checked
|
|
|
|
self.display:draw()
|
|
|
|
|
|
|
|
elseif event.type == 'grid_focus_row' and event.element == self.grid1 then
|
|
|
|
self.grid2:draw()
|
|
|
|
|
|
|
|
elseif event.type == 'grid_select' and event.element == self.grid2 then
|
|
|
|
_colors[self.grid1:getSelected().name] = event.selected.value
|
|
|
|
self.display:draw()
|
|
|
|
self.grid2:draw()
|
|
|
|
|
|
|
|
elseif event.type == 'reset' then
|
|
|
|
config.color = defaults
|
|
|
|
config.displayDirectory = true
|
|
|
|
self.directory.value = true
|
|
|
|
_colors = Util.shallowCopy(defaults)
|
|
|
|
|
|
|
|
Config.update('shellprompt', config)
|
|
|
|
self:draw()
|
|
|
|
|
|
|
|
elseif event.type == 'update' then
|
|
|
|
config.color = _colors
|
|
|
|
Config.update('shellprompt', config)
|
|
|
|
|
|
|
|
end
|
|
|
|
return UI.Tab.eventHandler(self, event)
|
2019-06-18 19:19:24 +00:00
|
|
|
end
|
2020-04-22 04:40:59 +00:00
|
|
|
}
|