1
0
mirror of https://github.com/kepler155c/opus synced 2025-01-03 20:30:28 +00:00

Overview update

This commit is contained in:
kepler155c@gmail.com 2019-01-28 17:54:00 -05:00
parent dddb2a6b97
commit 02629e266b
4 changed files with 131 additions and 317 deletions

View File

@ -583,11 +583,11 @@ function UI.Window:sync()
end end
end end
function UI.Window:enable() function UI.Window:enable(...)
self.enabled = true self.enabled = true
if self.children then if self.children then
for _,child in pairs(self.children) do for _,child in pairs(self.children) do
child:enable() child:enable(...)
end end
end end
end end
@ -607,10 +607,12 @@ function UI.Window:setTextScale(textScale)
end end
function UI.Window:clear(bg, fg) function UI.Window:clear(bg, fg)
if self.canvas then if self.enabled then
self.canvas:clear(bg or self.backgroundColor, fg or self.textColor) if self.canvas then
else self.canvas:clear(bg or self.backgroundColor, fg or self.textColor)
self:clearArea(1 + self.offx, 1 + self.offy, self.width, self.height, bg) else
self:clearArea(1 + self.offx, 1 + self.offy, self.width, self.height, bg)
end
end end
end end
@ -628,16 +630,18 @@ function UI.Window:clearArea(x, y, width, height, bg)
end end
function UI.Window:write(x, y, text, bg, tc) function UI.Window:write(x, y, text, bg, tc)
bg = bg or self.backgroundColor if self.enabled then
tc = tc or self.textColor bg = bg or self.backgroundColor
x = x - self.offx tc = tc or self.textColor
y = y - self.offy x = x - self.offx
if y <= self.height and y > 0 then y = y - self.offy
if self.canvas then if y <= self.height and y > 0 then
self.canvas:write(x, y, text, bg, tc) if self.canvas then
else self.canvas:write(x, y, text, bg, tc)
self.parent:write( else
self.x + x - 1, self.y + y - 1, tostring(text), bg, tc) self.parent:write(
self.x + x - 1, self.y + y - 1, tostring(text), bg, tc)
end
end end
end end
end end
@ -2056,6 +2060,7 @@ function UI.MenuBar:eventHandler(event)
if event.type == 'button_press' and event.button.dropmenu then if event.type == 'button_press' and event.button.dropmenu then
if event.button.dropmenu.enabled then if event.button.dropmenu.enabled then
event.button.dropmenu:hide() event.button.dropmenu:hide()
self:refocus()
return true return true
else else
local x, y = getPosition(event.button) local x, y = getPosition(event.button)
@ -2123,7 +2128,6 @@ function UI.DropMenu:setParent()
end end
function UI.DropMenu:enable() function UI.DropMenu:enable()
self.enabled = false
end end
function UI.DropMenu:show(x, y) function UI.DropMenu:show(x, y)
@ -2131,10 +2135,7 @@ function UI.DropMenu:show(x, y)
self.canvas:move(x, y) self.canvas:move(x, y)
self.canvas:setVisible(true) self.canvas:setVisible(true)
self.enabled = true UI.Window.enable(self)
for _,child in pairs(self.children) do
child:enable()
end
self:draw() self:draw()
self:capture(self) self:capture(self)
@ -2442,16 +2443,12 @@ function UI.SlideOut:setParent()
end end
function UI.SlideOut:enable() function UI.SlideOut:enable()
self.enabled = false
end end
function UI.SlideOut:show(...) function UI.SlideOut:show(...)
self:addTransition('expandUp') self:addTransition('expandUp')
self.canvas:setVisible(true) self.canvas:setVisible(true)
self.enabled = true UI.Window.enable(self, ...)
for _,child in pairs(self.children) do
child:enable(...)
end
self:draw() self:draw()
self:capture(self) self:capture(self)
self:focusFirst() self:focusFirst()
@ -2459,12 +2456,7 @@ end
function UI.SlideOut:disable() function UI.SlideOut:disable()
self.canvas:setVisible(false) self.canvas:setVisible(false)
self.enabled = false UI.Window.disable(self)
if self.children then
for _,child in pairs(self.children) do
child:disable()
end
end
end end
function UI.SlideOut:hide() function UI.SlideOut:hide()
@ -2553,7 +2545,6 @@ function UI.Notification:draw()
end end
function UI.Notification:enable() function UI.Notification:enable()
self.enabled = false
end end
function UI.Notification:error(value, timeout) function UI.Notification:error(value, timeout)

View File

@ -1,145 +0,0 @@
local UI = require('ui')
local Util = require('util')
local colors = _G.colors
local fs = _G.fs
return function(args)
local columns = {
{ heading = 'Name', key = 'name' },
}
if UI.term.width > 28 then
table.insert(columns,
{ heading = 'Size', key = 'size', width = 5 }
)
end
args = args or { }
local selectFile = UI.Dialog {
x = args.x or 3,
y = args.y or 2,
z = args.z or 2,
-- rex = args.rex or -3,
-- rey = args.rey or -3,
height = args.height,
width = args.width,
title = 'Select File',
grid = UI.ScrollingGrid {
x = 2,
y = 2,
ex = -2,
ey = -4,
path = '',
sortColumn = 'name',
columns = columns,
},
path = UI.TextEntry {
x = 2,
y = -2,
ex = -11,
limit = 256,
accelerators = {
enter = 'path_enter',
}
},
cancel = UI.Button {
text = 'Cancel',
x = -9,
y = -2,
event = 'cancel',
},
}
function selectFile:enable(path, fn)
self:setPath(path)
self.fn = fn
UI.Dialog.enable(self)
end
function selectFile:setPath(path)
self.grid.dir = path
while not fs.isDir(self.grid.dir) do
self.grid.dir = fs.getDir(self.grid.dir)
end
self.path.value = self.grid.dir
end
function selectFile.grid:draw()
local files = fs.listEx(self.dir)
if #self.dir > 0 then
table.insert(files, {
name = '..',
isDir = true,
})
end
self:setValues(files)
self:setIndex(1)
UI.Grid.draw(self)
end
function selectFile.grid:getDisplayValues(row)
if row.size then
row = Util.shallowCopy(row)
row.size = Util.toBytes(row.size)
end
return row
end
function selectFile.grid:getRowTextColor(file)
if file.isDir then
return colors.cyan
end
if file.isReadOnly then
return colors.pink
end
return colors.white
end
function selectFile.grid:sortCompare(a, b)
if self.sortColumn == 'size' then
return a.size < b.size
end
if a.isDir == b.isDir then
return a.name:lower() < b.name:lower()
end
return a.isDir
end
function selectFile:eventHandler(event)
if event.type == 'grid_select' then
self.grid.dir = fs.combine(self.grid.dir, event.selected.name)
self.path.value = self.grid.dir
if event.selected.isDir then
self.grid:draw()
self.path:draw()
else
UI:setPreviousPage()
self.fn(self.path.value)
end
elseif event.type == 'path_enter' then
if fs.isDir(self.path.value) then
self:setPath(self.path.value)
self.grid:draw()
self.path:draw()
else
UI:setPreviousPage()
self.fn(self.path.value)
end
elseif event.type == 'cancel' then
UI:setPreviousPage()
self.fn()
else
return UI.Dialog.eventHandler(self, event)
end
return true
end
return selectFile
end

View File

@ -19,7 +19,6 @@ local gridColumns = {
{ heading = 'Status', key = 'status' }, { heading = 'Status', key = 'status' },
} }
local trusted = Util.readTable('usr/.known_hosts')
local config = Config.load('network', { }) local config = Config.load('network', { })
if UI.term.width >= 30 then if UI.term.width >= 30 then
@ -36,20 +35,16 @@ local page = UI.Page {
UI.MenuBar.spacer, UI.MenuBar.spacer,
{ text = 'Reboot r', event = 'reboot' }, { text = 'Reboot r', event = 'reboot' },
} }, } },
--{ text = 'Chat', event = 'chat' },
{ text = 'Trust', dropdown = { { text = 'Trust', dropdown = {
{ text = 'Establish', event = 'trust' }, { text = 'Establish', event = 'trust' },
-- { text = 'Remove', event = 'untrust' },
} }, } },
{ text = 'Help', event = 'help', noCheck = true },
{ {
text = '\187', text = '\187',
x = -3, x = -3,
dropdown = { dropdown = {
{ text = 'Ports', event = 'ports', noCheck = true }, { text = 'Port Status', event = 'ports', modem = true },
-- { text = 'Show all', event = 'show_all', noCheck = true }, UI.MenuBar.spacer,
-- UI.MenuBar.spacer, { text = 'Help', event = 'help', noCheck = true },
-- { text = 'Show trusted', event = 'show_trusted', noCheck = true },
}, },
}, },
}, },
@ -117,25 +112,30 @@ function page.ports.grid:update()
local connections = { } local connections = { }
for i = 0, 65535 do pcall(function() -- guard against modem removal
if device.wireless_modem.isOpen(i) then if device.wireless_modem then
local conn = { for i = 0, 65535 do
port = i if device.wireless_modem.isOpen(i) then
} local conn = {
local socket = findConnection(i) port = i
if socket then }
conn.state = 'CONNECTED' local socket = findConnection(i)
local host = socket.dhost if socket then
if network[host] then conn.state = 'CONNECTED'
host = network[host].label local host = socket.dhost
if network[host] then
host = network[host].label
end
conn.connection = host .. ':' .. socket.dport
else
conn.state = 'LISTEN'
end
table.insert(connections, conn)
end end
conn.connection = host .. ':' .. socket.dport
else
conn.state = 'LISTEN'
end end
table.insert(connections, conn)
end end
end end)
self.values = connections self.values = connections
UI.Grid.update(self) UI.Grid.update(self)
end end
@ -173,18 +173,6 @@ function page:eventHandler(event)
elseif event.type == 'trust' then elseif event.type == 'trust' then
shell.openForegroundTab('trust ' .. t.id) shell.openForegroundTab('trust ' .. t.id)
elseif event.type == 'untrust' then
local trustList = Util.readTable('usr/.known_hosts') or { }
trustList[t.id] = nil
Util.writeTable('usr/.known_hosts', trustList)
elseif event.type == 'chat' then
multishell.openTab({
path = 'sys/apps/shell',
args = { 'chat join opusChat-' .. t.id .. ' guest-' .. os.getComputerID() },
title = 'Chatroom',
focused = true,
})
elseif event.type == 'reboot' then elseif event.type == 'reboot' then
sendCommand(t.id, 'reboot') sendCommand(t.id, 'reboot')
@ -228,11 +216,6 @@ This only needs to be done once.
Event.off(self.portsHandler) Event.off(self.portsHandler)
self.ports:hide() self.ports:hide()
elseif event.type == 'show_all' then
config.showTrusted = false
self.grid:setValues(network)
Config.update('network', config)
elseif event.type == 'show_trusted' then elseif event.type == 'show_trusted' then
config.showTrusted = true config.showTrusted = true
Config.update('network', config) Config.update('network', config)
@ -245,16 +228,15 @@ end
function page.menuBar:getActive(menuItem) function page.menuBar:getActive(menuItem)
local t = page.grid:getSelected() local t = page.grid:getSelected()
if menuItem.event == 'untrust' then if menuItem.modem then
local trustList = Util.readTable('usr/.known_hosts') or { } return not not device.wireless_modem
return t and trustList[t.id]
end end
return menuItem.noCheck or not not t return menuItem.noCheck or not not t
end end
function page.grid:getRowTextColor(row, selected) function page.grid:getRowTextColor(row, selected)
if not row.active then if not row.active then
return colors.orange return colors.lightGray
end end
return UI.Grid.getRowTextColor(self, row, selected) return UI.Grid.getRowTextColor(self, row, selected)
end end
@ -278,17 +260,7 @@ function page.grid:getDisplayValues(row)
end end
Event.onInterval(1, function() Event.onInterval(1, function()
local t = { } page.grid:update()
if config.showTrusted then
for k,v in pairs(network) do
if trusted[k] then
t[k] = v
end
end
page.grid:setValues(t)
else
page.grid:update()
end
page.grid:draw() page.grid:draw()
page:sync() page:sync()
end) end)

View File

@ -3,7 +3,6 @@ _G.requireInjector(_ENV)
local class = require('class') local class = require('class')
local Config = require('config') local Config = require('config')
local Event = require('event') local Event = require('event')
local FileUI = require('ui.fileui')
local NFT = require('nft') local NFT = require('nft')
local Packages = require('packages') local Packages = require('packages')
local SHA1 = require('sha1') local SHA1 = require('sha1')
@ -13,6 +12,7 @@ local Util = require('util')
local colors = _G.colors local colors = _G.colors
local fs = _G.fs local fs = _G.fs
local os = _G.os
local pocket = _G.pocket local pocket = _G.pocket
local shell = _ENV.shell local shell = _ENV.shell
local term = _G.term local term = _G.term
@ -75,7 +75,7 @@ function UI.VerticalTabBar:setParent()
self.x = 1 self.x = 1
self.width = 8 self.width = 8
self.height = nil self.height = nil
self.ey = -1 self.ey = -2
UI.TabBar.setParent(self) UI.TabBar.setParent(self)
for k,c in pairs(self.children) do for k,c in pairs(self.children) do
c.x = 1 c.x = 1
@ -88,17 +88,60 @@ end
local cx = 9 local cx = 9
local cy = 1 local cy = 1
if sx < 30 then
UI.VerticalTabBar = UI.TabBar
cx = 1
cy = 2
end
local page = UI.Page { local page = UI.Page {
container = UI.Viewport { container = UI.Viewport {
x = cx, x = cx,
y = cy, y = cy,
}, },
tray = UI.Window {
y = -1, width = 8,
backgroundColor = colors.lightGray,
newApp = UI.Button {
text = '+', event = 'new',
},
volume = UI.Button {
x = 3,
text = '\15', event = 'volume',
}
},
editor = UI.SlideOut {
backgroundColor = colors.cyan,
titleBar = UI.TitleBar {
title = 'Edit Application',
event = 'slide_hide',
},
form = UI.Form {
y = 2, ey = -2,
[1] = UI.TextEntry {
formLabel = 'Title', formKey = 'title', limit = 11, help = 'Application title',
required = true,
},
[2] = UI.TextEntry {
formLabel = 'Run', formKey = 'run', limit = 100, help = 'Full path to application',
required = true,
},
[3] = UI.TextEntry {
formLabel = 'Category', formKey = 'category', limit = 11, help = 'Category of application',
required = true,
},
iconFile = UI.TextEntry {
x = 11, ex = -12, y = 7,
limit = 128, help = 'Path to icon file',
shadowText = 'Path to icon file',
},
loadIcon = UI.Button {
x = 11, y = 9,
text = 'Load', event = 'loadIcon', help = 'Load icon file',
},
image = UI.NftImage {
backgroundColor = colors.black,
y = 7, x = 2, height = 3, width = 8,
},
},
notification = UI.Notification(),
statusBar = UI.StatusBar(),
},
notification = UI.Notification(), notification = UI.Notification(),
accelerators = { accelerators = {
r = 'refresh', r = 'refresh',
@ -172,7 +215,6 @@ local function loadApplications()
end end
table.sort(buttons, function(a, b) return a.text < b.text end) table.sort(buttons, function(a, b) return a.text < b.text end)
table.insert(buttons, 1, { text = 'Recent' }) table.insert(buttons, 1, { text = 'Recent' })
table.insert(buttons, { text = '+', event = 'new' })
Util.removeByValue(page.children, page.tabBar) Util.removeByValue(page.children, page.tabBar)
@ -421,12 +463,12 @@ function page:eventHandler(event)
if config.currentCategory ~= 'Recent' then if config.currentCategory ~= 'Recent' then
category = config.currentCategory or 'Apps' category = config.currentCategory or 'Apps'
end end
UI:setPage('editor', { category = category }) self.editor:show({ category = category })
elseif event.type == 'edit' then elseif event.type == 'edit' then
local focused = page:getFocused() local focused = page:getFocused()
if focused.app then if focused.app then
UI:setPage('editor', focused.app) self.editor:show(focused.app)
end end
else else
@ -435,40 +477,7 @@ function page:eventHandler(event)
return true return true
end end
local formWidth = math.max(UI.term.width - 8, 26) function page.editor:show(app)
local editor = UI.Dialog {
height = 11,
width = formWidth,
title = 'Edit Application',
form = UI.Form {
y = 2,
height = 9,
title = UI.TextEntry {
formLabel = 'Title', formKey = 'title', limit = 11, help = 'Application title',
required = true,
},
run = UI.TextEntry {
formLabel = 'Run', formKey = 'run', limit = 100, help = 'Full path to application',
required = true,
},
category = UI.TextEntry {
formLabel = 'Category', formKey = 'category', limit = 11, help = 'Category of application',
required = true,
},
loadIcon = UI.Button {
x = 11, y = 6,
text = 'Icon', event = 'loadIcon', help = 'Select icon'
},
image = UI.NftImage {
y = 6, x = 2, height = 3, width = 8,
},
},
statusBar = UI.StatusBar(),
iconFile = '',
}
function editor:enable(app)
if app then if app then
self.form:setValues(app) self.form:setValues(app)
@ -481,16 +490,16 @@ function editor:enable(app)
end end
self.form.image:setImage(icon) self.form.image:setImage(icon)
end end
UI.Dialog.enable(self) UI.SlideOut.show(self)
self:focusFirst() self:focusFirst()
end end
function editor.form.image:draw() function page.editor.form.image:draw()
self:clear() self:clear()
UI.NftImage.draw(self) UI.NftImage.draw(self)
end end
function editor:updateApplications(app) function page.editor:updateApplications(app)
if not app.key then if not app.key then
app.key = SHA1.sha1(app.title) app.key = SHA1.sha1(app.title)
end end
@ -499,51 +508,39 @@ function editor:updateApplications(app)
loadApplications() loadApplications()
end end
function editor:eventHandler(event) function page.editor:eventHandler(event)
if event.type == 'form_cancel' or event.type == 'cancel' then if event.type == 'form_cancel' or event.type == 'cancel' then
UI:setPreviousPage() self:hide()
elseif event.type == 'focus_change' then elseif event.type == 'focus_change' then
self.statusBar:setStatus(event.focused.help or '') self.statusBar:setStatus(event.focused.help or '')
self.statusBar:draw() self.statusBar:draw()
elseif event.type == 'loadIcon' then elseif event.type == 'loadIcon' then
local fileui = FileUI({ local s, m = pcall(function()
x = self.x, local iconLines = Util.readFile(self.form.iconFile.value)
y = self.y, if not iconLines then
z = 2, error('Must be an NFT image - 3 rows, 8 cols max')
width = self.width,
height = self.height,
})
UI:setPage(fileui, fs.getDir(self.iconFile), function(fileName)
if fileName then
self.iconFile = fileName
local s, m = pcall(function()
local iconLines = Util.readFile(fileName)
if not iconLines then
error('Must be an NFT image - 3 rows, 8 cols max')
end
local icon, m = parseIcon(iconLines)
if not icon then
error(m)
end
if extSupport then
self.form.values.iconExt = iconLines
else
self.form.values.icon = iconLines
end
self.form.image:setImage(icon)
self.form.image:draw()
end)
if not s and m then
local msg = m:gsub('.*: (.*)', '%1')
page.notification:error(msg)
end
end end
local icon, m = parseIcon(iconLines)
if not icon then
error(m)
end
if extSupport then
self.form.values.iconExt = iconLines
else
self.form.values.icon = iconLines
end
self.form.image:setImage(icon)
self.form.image:draw()
end) end)
if not s and m then
local msg = m:gsub('.*: (.*)', '%1')
self.notification:error(msg)
end
elseif event.type == 'form_invalid' then elseif event.type == 'form_invalid' then
page.notification:error(event.message) self.notification:error(event.message)
elseif event.type == 'form_complete' then elseif event.type == 'form_complete' then
local values = self.form.values local values = self.form.values
@ -555,13 +552,12 @@ function editor:eventHandler(event)
Config.update('Overview', config) Config.update('Overview', config)
os.queueEvent('overview_refresh') os.queueEvent('overview_refresh')
else else
return UI.Dialog.eventHandler(self, event) return UI.SlideOut.eventHandler(self, event)
end end
return true return true
end end
UI:setPages({ UI:setPages({
editor = editor,
main = page, main = page,
}) })