mirror of https://github.com/kepler155c/opus
cleanup + theme editor
This commit is contained in:
parent
9eeec8719c
commit
3e41996b9b
|
@ -58,10 +58,16 @@ local page = UI.Page {
|
|||
},
|
||||
[2] = UI.Tab {
|
||||
tabTitle = 'Output',
|
||||
backgroundColor = colors.black,
|
||||
output = UI.Embedded {
|
||||
y = 2,
|
||||
maxScroll = 1000,
|
||||
backgroundColor = colors.black,
|
||||
},
|
||||
draw = function(self)
|
||||
self:write(1, 1, string.rep('\131', self.width), colors.black, UI.colors.primary)
|
||||
self:drawChildren()
|
||||
end,
|
||||
},
|
||||
},
|
||||
}
|
||||
|
|
|
@ -56,6 +56,31 @@ local page = UI.Page {
|
|||
columns = gridColumns,
|
||||
sortColumn = 'label',
|
||||
autospace = true,
|
||||
getRowTextColor = function(self, row, selected)
|
||||
if not row.active then
|
||||
return colors.lightGray
|
||||
end
|
||||
return UI.Grid.getRowTextColor(self, row, selected)
|
||||
end,
|
||||
getDisplayValues = function(_, row)
|
||||
row = Util.shallowCopy(row)
|
||||
if row.uptime then
|
||||
if row.uptime < 60 then
|
||||
row.uptime = string.format("%ds", math.floor(row.uptime))
|
||||
elseif row.uptime < 3600 then
|
||||
row.uptime = string.format("%sm", math.floor(row.uptime / 60))
|
||||
else
|
||||
row.uptime = string.format("%sh", math.floor(row.uptime / 3600))
|
||||
end
|
||||
end
|
||||
if row.fuel then
|
||||
row.fuel = row.fuel > 0 and Util.toBytes(row.fuel) or ''
|
||||
end
|
||||
if row.distance then
|
||||
row.distance = Util.toBytes(Util.round(row.distance, 1))
|
||||
end
|
||||
return row
|
||||
end,
|
||||
},
|
||||
ports = UI.SlideOut {
|
||||
titleBar = UI.TitleBar {
|
||||
|
@ -72,6 +97,12 @@ local page = UI.Page {
|
|||
sortColumn = 'port',
|
||||
autospace = true,
|
||||
},
|
||||
eventHandler = function(self, event)
|
||||
if event.type == 'grid_select' then
|
||||
shell.openForegroundTab('Sniff ' .. event.selected.port)
|
||||
end
|
||||
return UI.SlideOut.eventHandler(self, event)
|
||||
end,
|
||||
},
|
||||
help = UI.SlideOut {
|
||||
x = 5, ex = -5, height = 8, y = -8,
|
||||
|
@ -125,13 +156,6 @@ local function sendCommand(host, command)
|
|||
end
|
||||
end
|
||||
|
||||
function page.ports:eventHandler(event)
|
||||
if event.type == 'grid_select' then
|
||||
shell.openForegroundTab('Sniff ' .. event.selected.port)
|
||||
end
|
||||
return UI.SlideOut.eventHandler(self, event)
|
||||
end
|
||||
|
||||
function page.ports.grid:update()
|
||||
local transport = network:getTransport()
|
||||
|
||||
|
@ -241,33 +265,6 @@ function page.menuBar:getActive(menuItem)
|
|||
return menuItem.noCheck or not not t
|
||||
end
|
||||
|
||||
function page.grid:getRowTextColor(row, selected)
|
||||
if not row.active then
|
||||
return colors.lightGray
|
||||
end
|
||||
return UI.Grid.getRowTextColor(self, row, selected)
|
||||
end
|
||||
|
||||
function page.grid:getDisplayValues(row)
|
||||
row = Util.shallowCopy(row)
|
||||
if row.uptime then
|
||||
if row.uptime < 60 then
|
||||
row.uptime = string.format("%ds", math.floor(row.uptime))
|
||||
elseif row.uptime < 3600 then
|
||||
row.uptime = string.format("%sm", math.floor(row.uptime / 60))
|
||||
else
|
||||
row.uptime = string.format("%sh", math.floor(row.uptime / 3600))
|
||||
end
|
||||
end
|
||||
if row.fuel then
|
||||
row.fuel = row.fuel > 0 and Util.toBytes(row.fuel) or ''
|
||||
end
|
||||
if row.distance then
|
||||
row.distance = Util.toBytes(Util.round(row.distance, 1))
|
||||
end
|
||||
return row
|
||||
end
|
||||
|
||||
Event.onInterval(1, function()
|
||||
page.grid:update()
|
||||
page.grid:draw()
|
||||
|
|
|
@ -102,20 +102,18 @@ local page = UI.Page {
|
|||
},
|
||||
tray = UI.Window {
|
||||
y = -1, width = 8,
|
||||
backgroundColor = colors.lightGray,
|
||||
newApp = UI.Button {
|
||||
backgroundColor = UI.colors.tertiary,
|
||||
newApp = UI.FlatButton {
|
||||
x = 2,
|
||||
text = '+', event = 'new',
|
||||
backgroundFocusColor = colors.lightGray,
|
||||
},
|
||||
mode = UI.Button {
|
||||
x = 3,
|
||||
mode = UI.FlatButton {
|
||||
x = 4,
|
||||
text = '=', event = 'display_mode',
|
||||
backgroundFocusColor = colors.lightGray,
|
||||
},
|
||||
help = UI.Button {
|
||||
x = 5,
|
||||
help = UI.FlatButton {
|
||||
x = 6,
|
||||
text = '?', event = 'help',
|
||||
backgroundFocusColor = colors.lightGray,
|
||||
},
|
||||
},
|
||||
editor = UI.SlideOut {
|
||||
|
|
|
@ -2,8 +2,9 @@ local UI = require('opus.ui')
|
|||
local Util = require('opus.util')
|
||||
|
||||
local shell = _ENV.shell
|
||||
local multishell = _ENV.multishell
|
||||
|
||||
-- fileui [--path=path] [--exec=filename]
|
||||
-- fileui [--path=path] [--exec=filename] [--title=title]
|
||||
|
||||
local page = UI.Page {
|
||||
fileselect = UI.FileSelect { },
|
||||
|
@ -22,6 +23,10 @@ local page = UI.Page {
|
|||
|
||||
local _, args = Util.parse(...)
|
||||
|
||||
if args.title and multishell then
|
||||
multishell.setTitle(multishell.getCurrent(), args.title)
|
||||
end
|
||||
|
||||
UI:setPage(page, args.path)
|
||||
UI:start()
|
||||
UI.term:setCursorBlink(false)
|
||||
|
@ -31,5 +36,4 @@ if args.exec and page.selected then
|
|||
return
|
||||
end
|
||||
|
||||
-- print('selected: ' .. tostring(selected))
|
||||
return page.selected
|
||||
|
|
|
@ -28,7 +28,7 @@ local defaults = {
|
|||
local _colors = config.color or Util.shallowCopy(defaults)
|
||||
|
||||
local allSettings = { }
|
||||
for k, v in pairs(defaults) do
|
||||
for k in pairs(defaults) do
|
||||
table.insert(allSettings, { name = k })
|
||||
end
|
||||
|
||||
|
@ -112,7 +112,7 @@ return UI.Tab {
|
|||
self.grid2:draw()
|
||||
|
||||
elseif event.type == 'grid_select' and event.element == self.grid2 then
|
||||
_colors[tab.grid1:getSelected().name] = event.selected.value
|
||||
_colors[self.grid1:getSelected().name] = event.selected.value
|
||||
self.display:draw()
|
||||
self.grid2:draw()
|
||||
|
||||
|
|
|
@ -0,0 +1,89 @@
|
|||
local Config = require('opus.config')
|
||||
local UI = require('opus.ui')
|
||||
local Util = require('opus.util')
|
||||
|
||||
local colors = _G.colors
|
||||
|
||||
local allColors = { }
|
||||
for k,v in pairs(colors) do
|
||||
if type(v) == 'number' then
|
||||
table.insert(allColors, { name = k, value = v })
|
||||
end
|
||||
end
|
||||
|
||||
local allSettings = { }
|
||||
for k,v in pairs(UI.colors) do
|
||||
allSettings[k] = { name = k, value = v }
|
||||
end
|
||||
|
||||
return UI.Tab {
|
||||
tabTitle = 'Theme',
|
||||
description = 'Theme colors',
|
||||
grid1 = UI.ScrollingGrid {
|
||||
y = 2, ey = -10, x = 2, ex = -17,
|
||||
disableHeader = true,
|
||||
columns = { { key = 'name' } },
|
||||
values = allSettings,
|
||||
sortColumn = 'name',
|
||||
},
|
||||
grid2 = UI.ScrollingGrid {
|
||||
y = 2, ey = -10, x = -14, ex = -2,
|
||||
disableHeader = true,
|
||||
columns = { { key = 'name' } },
|
||||
values = allColors,
|
||||
sortColumn = 'name',
|
||||
getRowTextColor = function(self, row)
|
||||
local selected = self.parent.grid1:getSelected()
|
||||
if selected.value == row.value then
|
||||
return colors.yellow
|
||||
end
|
||||
return UI.Grid.getRowTextColor(self, row)
|
||||
end
|
||||
},
|
||||
button = UI.Button {
|
||||
x = -9, y = -2,
|
||||
text = 'Update',
|
||||
event = 'update',
|
||||
},
|
||||
display = UI.Window {
|
||||
x = 2, ex = -2, y = -8, height = 5,
|
||||
textColor = colors.black,
|
||||
backgroundColor = colors.black,
|
||||
draw = function(self)
|
||||
self:clear()
|
||||
|
||||
self:write(1, 1, Util.widthify(' Local Global Device', self.width),
|
||||
allSettings.secondary.value)
|
||||
|
||||
self:write(2, 2, 'enter command ',
|
||||
colors.black, colors.gray)
|
||||
|
||||
self:write(1, 3, ' Formatted ',
|
||||
allSettings.primary.value)
|
||||
|
||||
self:write(12, 3, Util.widthify(' Output ', self.width - 11),
|
||||
allSettings.tertiary.value)
|
||||
|
||||
self:write(1, 4, Util.widthify(' Key', self.width),
|
||||
allSettings.primary.value)
|
||||
end,
|
||||
},
|
||||
eventHandler = function(self, event)
|
||||
if 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
|
||||
self.grid1:getSelected().value = event.selected.value
|
||||
self.display:draw()
|
||||
self.grid2:draw()
|
||||
|
||||
elseif event.type == 'update' then
|
||||
local config = Config.load('ui.theme', { colors = { } })
|
||||
for k,v in pairs(allSettings) do
|
||||
config.colors[k] = v.value
|
||||
end
|
||||
Config.update('ui.theme', config)
|
||||
end
|
||||
return UI.Tab.eventHandler(self, event)
|
||||
end
|
||||
}
|
|
@ -165,7 +165,7 @@ function input:translate(event, code, p1, p2)
|
|||
self.mch = 'mouse_up'
|
||||
self.mfired = input:toCode(self.mch, 255)
|
||||
end
|
||||
_syslog(self.mfired)
|
||||
|
||||
return {
|
||||
code = self.mfired,
|
||||
button = code,
|
||||
|
|
|
@ -209,6 +209,15 @@ end
|
|||
|
||||
function Manager:generateTheme(filename)
|
||||
local t = { }
|
||||
|
||||
local function getName(d)
|
||||
for c, n in pairs(colors) do
|
||||
if n == d then
|
||||
return 'colors.' .. c
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
for k,v in pairs(self) do
|
||||
if type(v) == 'table' then
|
||||
if v._preload then
|
||||
|
@ -221,17 +230,17 @@ function Manager:generateTheme(filename)
|
|||
if not t[k] then
|
||||
t[k] = { }
|
||||
end
|
||||
for c, n in pairs(colors) do
|
||||
if n == d then
|
||||
t[k][p] = 'colors.' .. c
|
||||
break
|
||||
end
|
||||
end
|
||||
t[k][p] = getName(d)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
t.colors = {
|
||||
primary = getName(self.colors.primary),
|
||||
secondary = getName(self.colors.secondary),
|
||||
tertiary = getName(self.colors.tertiary),
|
||||
}
|
||||
Util.writeFile(filename, textutils.serialize(t):gsub('(")', ''))
|
||||
end
|
||||
|
||||
|
@ -409,8 +418,8 @@ end
|
|||
|
||||
Manager.colors = {
|
||||
primary = colors.cyan,
|
||||
secondary = colors.blue,
|
||||
tertiary = colors.blue,
|
||||
secondary = colors.lightGray,
|
||||
tertiary = colors.gray,
|
||||
}
|
||||
|
||||
Manager.exitPullEvents = Event.exitPullEvents
|
||||
|
@ -652,7 +661,7 @@ function UI.Window:setCursorPos(x, y)
|
|||
end
|
||||
|
||||
function UI.Window:setCursorBlink(blink)
|
||||
self.parent:setCursorBlink(blink)
|
||||
self.cursorBlink = blink
|
||||
end
|
||||
|
||||
UI.Window.docs.draw = [[draw(VOID)
|
||||
|
@ -1072,7 +1081,6 @@ end
|
|||
|
||||
function UI.Device:setCursorBlink(blink)
|
||||
self.cursorBlink = blink
|
||||
self.device.setCursorBlink(blink)
|
||||
end
|
||||
|
||||
function UI.Device:setTextScale(textScale)
|
||||
|
@ -1130,9 +1138,7 @@ function UI.Device:sync()
|
|||
local transitions = self.effectsEnabled and self.transitions
|
||||
self.transitions = nil
|
||||
|
||||
if self:getCursorBlink() then
|
||||
self.device.setCursorBlink(false)
|
||||
end
|
||||
self.device.setCursorBlink(false)
|
||||
|
||||
if transitions then
|
||||
self:runTransitions(transitions)
|
||||
|
@ -1182,6 +1188,7 @@ end
|
|||
loadComponents()
|
||||
UI:loadTheme('usr/config/ui.theme')
|
||||
Util.merge(UI.Window.defaults, UI.theme.Window)
|
||||
Util.merge(UI.colors, UI.theme.colors)
|
||||
UI:setDefaultDevice(UI.Device({ device = term.current() }))
|
||||
|
||||
return UI
|
||||
|
|
|
@ -21,6 +21,9 @@ function UI.Embedded:layout()
|
|||
if not self.win then
|
||||
function self.render()
|
||||
self:sync()
|
||||
if self.focused then
|
||||
self:setCursorPos(self.win.getCursorPos())
|
||||
end
|
||||
end
|
||||
self.win = Terminal.window(UI.term.device, self.x, self.y, self.width, self.height, false)
|
||||
self.win.canvas = self
|
||||
|
@ -38,6 +41,9 @@ end
|
|||
|
||||
function UI.Embedded:focus()
|
||||
-- allow scrolling
|
||||
if self.focused then
|
||||
self:setCursorBlink(self.win.getCursorBlink())
|
||||
end
|
||||
end
|
||||
|
||||
function UI.Embedded:enable()
|
||||
|
@ -67,6 +73,7 @@ function UI.Embedded.example()
|
|||
local term = _G.term
|
||||
|
||||
return UI.Embedded {
|
||||
y = 2, x = 2, ex = -2, ey = -2,
|
||||
enable = function (self)
|
||||
UI.Embedded.enable(self)
|
||||
Event.addRoutine(function()
|
||||
|
@ -75,10 +82,11 @@ function UI.Embedded.example()
|
|||
term.redirect(oterm)
|
||||
end)
|
||||
end,
|
||||
eventHandler = function(_, event)
|
||||
eventHandler = function(self, event)
|
||||
if event.type == 'key' then
|
||||
return true
|
||||
end
|
||||
return UI.Embedded.eventHandler(self, event)
|
||||
end
|
||||
}
|
||||
end
|
||||
|
|
|
@ -0,0 +1,18 @@
|
|||
local class = require('opus.class')
|
||||
local UI = require('opus.ui')
|
||||
|
||||
local colors = _G.colors
|
||||
|
||||
UI.FlatButton = class(UI.Button)
|
||||
UI.FlatButton.defaults = {
|
||||
UIElement = 'FlatButton',
|
||||
textColor = colors.black,
|
||||
textFocusColor = colors.white,
|
||||
noPadding = true,
|
||||
}
|
||||
function UI.FlatButton:setParent()
|
||||
self.backgroundColor = self.parent:getProperty('backgroundColor')
|
||||
self.backgroundFocusColor = self.backgroundColor
|
||||
|
||||
UI.Button.setParent(self)
|
||||
end
|
|
@ -60,7 +60,7 @@ UI.Grid.defaults = {
|
|||
textSelectedColor = colors.white,
|
||||
backgroundColor = colors.black,
|
||||
backgroundSelectedColor = colors.gray,
|
||||
headerBackgroundColor = UI.colors.tertiary,
|
||||
headerBackgroundColor = UI.colors.primary,
|
||||
headerTextColor = colors.white,
|
||||
headerSortColor = colors.yellow,
|
||||
unfocusedTextSelectedColor = colors.white,
|
||||
|
|
|
@ -8,7 +8,7 @@ UI.MenuBar.defaults = {
|
|||
UIElement = 'MenuBar',
|
||||
buttons = { },
|
||||
height = 1,
|
||||
backgroundColor = colors.lightGray,
|
||||
backgroundColor = UI.colors.secondary,
|
||||
textColor = colors.black,
|
||||
spacing = 2,
|
||||
lastx = 1,
|
||||
|
|
|
@ -1,11 +1,8 @@
|
|||
local class = require('opus.class')
|
||||
local UI = require('opus.ui')
|
||||
|
||||
local colors = _G.colors
|
||||
|
||||
UI.MenuItem = class(UI.Button)
|
||||
UI.MenuItem = class(UI.FlatButton)
|
||||
UI.MenuItem.defaults = {
|
||||
UIElement = 'MenuItem',
|
||||
textFocusColor = colors.white,
|
||||
backgroundFocusColor = colors.lightGray,
|
||||
noPadding = false,
|
||||
}
|
||||
|
|
|
@ -24,17 +24,10 @@ function UI.Page:postInit()
|
|||
self.__target = self
|
||||
end
|
||||
|
||||
function UI.Page:enable()
|
||||
UI.Window.enable(self)
|
||||
|
||||
if not self.focused or not self.focused.enabled then
|
||||
self:focusFirst()
|
||||
end
|
||||
end
|
||||
|
||||
function UI.Page:sync()
|
||||
if self.enabled then
|
||||
self:checkFocus()
|
||||
self.parent:setCursorBlink(self.focused and self.focused.cursorBlink)
|
||||
self.parent:sync()
|
||||
end
|
||||
end
|
||||
|
@ -137,15 +130,7 @@ end
|
|||
|
||||
function UI.Page:checkFocus()
|
||||
if not self.focused or not self.focused.enabled then
|
||||
local el = self.__target
|
||||
while el do
|
||||
local focusables = el:getFocusables()
|
||||
if focusables[1] then
|
||||
self:setFocus(focusables[1])
|
||||
break
|
||||
end
|
||||
el = el.parent
|
||||
end
|
||||
self.__target:focusFirst()
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -2,14 +2,13 @@ local class = require('opus.class')
|
|||
local UI = require('opus.ui')
|
||||
local Util = require('opus.util')
|
||||
|
||||
local colors = _G.colors
|
||||
|
||||
UI.TabBar = class(UI.MenuBar)
|
||||
UI.TabBar.defaults = {
|
||||
UIElement = 'TabBar',
|
||||
buttonClass = 'TabBarMenuItem',
|
||||
selectedBackgroundColor = UI.colors.secondary,
|
||||
unselectedBackgroundColor = colors.lightGray,
|
||||
backgroundColor = UI.colors.tertiary,
|
||||
selectedBackgroundColor = UI.colors.primary,
|
||||
unselectedBackgroundColor = UI.colors.tertiary,
|
||||
}
|
||||
function UI.TabBar:enable()
|
||||
UI.MenuBar.enable(self)
|
||||
|
|
|
@ -28,6 +28,7 @@ UI.TextEntry.defaults = {
|
|||
backgroundFocusColor = colors.black, --lightGray,
|
||||
height = 1,
|
||||
limit = 6,
|
||||
cursorBlink = true,
|
||||
accelerators = {
|
||||
[ 'control-c' ] = 'copy',
|
||||
}
|
||||
|
@ -114,11 +115,6 @@ end
|
|||
|
||||
function UI.TextEntry:focus()
|
||||
self:draw()
|
||||
if self.focused then
|
||||
self:setCursorBlink(true)
|
||||
else
|
||||
self:setCursorBlink(false)
|
||||
end
|
||||
end
|
||||
|
||||
function UI.TextEntry:eventHandler(event)
|
||||
|
|
Loading…
Reference in New Issue