UI improvements

This commit is contained in:
kepler155c
2017-10-07 23:02:38 -04:00
parent 8ef97df223
commit bba7841c43
2 changed files with 86 additions and 101 deletions

View File

@@ -56,7 +56,7 @@ local sources = {
shell.setDir(APP_DIR) shell.setDir(APP_DIR)
function downloadApp(app) local function downloadApp(app)
local h local h
if type(app.url) == "table" then if type(app.url) == "table" then
@@ -72,7 +72,7 @@ function downloadApp(app)
end end
end end
function runApp(app, checkExists, ...) local function runApp(app, checkExists, ...)
local path, fn local path, fn
local args = { ... } local args = { ... }
@@ -173,29 +173,27 @@ local getSourceListing = function(source)
end end
end end
local appPage = UI.Page({ local appPage = UI.Page {
menuBar = UI.MenuBar({ menuBar = UI.MenuBar {
showBackButton = not pocket, -- showBackButton = not pocket,
buttons = { buttons = {
{ text = '\027', event = 'back' },
{ text = 'Install', event = 'install' }, { text = 'Install', event = 'install' },
{ text = 'Run', event = 'run' }, { text = 'Run', event = 'run' },
{ text = 'View', event = 'view' }, { text = 'View', event = 'view' },
{ text = 'Remove', event = 'uninstall', name = 'removeButton' }, { text = 'Remove', event = 'uninstall', name = 'removeButton' },
}, },
}), },
container = UI.Window({ container = UI.Window {
x = 2, x = 2, y = 3, ex = -2, ey = -3,
y = 3, viewport = UI.Viewport(),
height = UI.term.height - 3, },
width = UI.term.width - 2,
viewport = UI.ViewportWindow(),
}),
notification = UI.Notification(), notification = UI.Notification(),
accelerators = { accelerators = {
q = 'back', q = 'back',
backspace = 'back', backspace = 'back',
}, },
}) }
function appPage.container.viewport:draw() function appPage.container.viewport:draw()
local app = self.parent.parent.app local app = self.parent.parent.app
@@ -293,31 +291,26 @@ function appPage:eventHandler(event)
return true return true
end end
local categoryPage = UI.Page({ local categoryPage = UI.Page {
menuBar = UI.MenuBar({ menuBar = UI.MenuBar {
buttons = { buttons = {
{ text = 'Catalog', event = 'dropdown', dropdown = 'sourceMenu' }, { text = 'Catalog', dropdown = sources },
{ text = 'Category', event = 'dropdown', dropdown = 'categoryMenu' }, { text = 'Category', name = 'categoryButton', dropdown = { } },
}, },
}), },
sourceMenu = UI.DropMenu({ grid = UI.ScrollingGrid {
buttons = sources, y = 2, ey = -2,
}),
grid = UI.ScrollingGrid({
y = 2,
height = UI.term.height - 2,
columns = { columns = {
{ heading = 'Title', key = 'title' }, { heading = 'Title', key = 'title' },
}, },
sortColumn = 'title', sortColumn = 'title',
autospace = true, },
}),
statusBar = UI.StatusBar(), statusBar = UI.StatusBar(),
accelerators = { accelerators = {
l = 'lua', l = 'lua',
q = 'quit', q = 'quit',
}, },
}) }
function categoryPage:setCategory(source, name, index) function categoryPage:setCategory(source, name, index)
self.grid.values = { } self.grid.values = { }
@@ -359,19 +352,17 @@ function categoryPage:setSource(source)
end end
source.categoryMenu = UI.DropMenu({ source.categoryMenu = UI.DropMenu({
y = 2,
x = 1,
buttons = buttons, buttons = buttons,
}) })
source.index, source.name = Util.first(source.storeCatagoryNames) source.index, source.name = Util.first(source.storeCatagoryNames)
categoryPage:add({ categoryPage.menuBar.categoryButton:add({
categoryMenu = source.categoryMenu categoryMenu = source.categoryMenu
}) })
end end
self.source = source self.source = source
self.categoryMenu = source.categoryMenu self.menuBar.categoryButton.dropmenu = source.categoryMenu
categoryPage:setCategory(source, source.name, source.index) categoryPage:setCategory(source, source.name, source.index)
end end

View File

@@ -1,24 +1,28 @@
requireInjector(getfenv(1)) requireInjector(getfenv(1))
local Ansi = require('ansi')
local Event = require('event') local Event = require('event')
local UI = require('ui') local UI = require('ui')
local Util = require('util') local Util = require('util')
local colors = _G.colors
local peripheral = _G.peripheral
multishell.setTitle(multishell.getCurrent(), 'Devices') multishell.setTitle(multishell.getCurrent(), 'Devices')
--[[ -- PeripheralsPage -- ]] -- --[[ -- PeripheralsPage -- ]] --
local peripheralsPage = UI.Page { local peripheralsPage = UI.Page {
grid = UI.ScrollingGrid { grid = UI.ScrollingGrid {
ey = -2,
columns = { columns = {
{ heading = 'Type', key = 'type' }, { heading = 'Type', key = 'type' },
{ heading = 'Side', key = 'side' }, { heading = 'Side', key = 'side' },
}, },
sortColumn = 'type', sortColumn = 'type',
height = UI.term.height - 1,
autospace = true, autospace = true,
}, },
statusBar = UI.StatusBar { statusBar = UI.StatusBar {
status = 'Select peripheral' values = 'Select peripheral',
}, },
accelerators = { accelerators = {
q = 'quit', q = 'quit',
@@ -60,16 +64,17 @@ end
--[[ -- MethodsPage -- ]] -- --[[ -- MethodsPage -- ]] --
local methodsPage = UI.Page { local methodsPage = UI.Page {
backgroundColor = colors.black,
doc = UI.TextArea {
backgroundColor = colors.black,
x = 2, y = 2, ex = -1, ey = -7,
},
grid = UI.ScrollingGrid { grid = UI.ScrollingGrid {
y = -6, ey = -2,
columns = { columns = {
{ heading = 'Name', key = 'name', width = UI.term.width } { heading = 'Name', key = 'name', width = UI.term.width }
}, },
sortColumn = 'name', sortColumn = 'name',
height = 7,
},
viewportConsole = UI.ViewportWindow {
y = 8,
height = UI.term.height - 8,
}, },
statusBar = UI.StatusBar { statusBar = UI.StatusBar {
status = 'q to return', status = 'q to return',
@@ -84,8 +89,9 @@ function methodsPage:enable(p)
self.peripheral = p or self.peripheral self.peripheral = p or self.peripheral
local p = peripheral.wrap(self.peripheral.side) p = peripheral.wrap(self.peripheral.side)
if p.getDocs then if p.getDocs then
-- plethora
self.grid.values = { } self.grid.values = { }
for k,v in pairs(p.getDocs()) do for k,v in pairs(p.getDocs()) do
table.insert(self.grid.values, { table.insert(self.grid.values, {
@@ -94,27 +100,35 @@ function methodsPage:enable(p)
}) })
end end
elseif not p.getAdvancedMethodsData then elseif not p.getAdvancedMethodsData then
-- computercraft
self.grid.values = { } self.grid.values = { }
for name,f in pairs(p) do for name in pairs(p) do
table.insert(self.grid.values, { table.insert(self.grid.values, {
name = name, name = name,
noext = true, noext = true,
}) })
end end
else else
-- open peripherals
self.grid.values = p.getAdvancedMethodsData() self.grid.values = p.getAdvancedMethodsData()
for name,f in pairs(self.grid.values) do for name,f in pairs(self.grid.values) do
f.name = name f.name = name
end end
end end
self.viewportConsole.offy = 0
self.grid:update() self.grid:update()
self.grid:setIndex(1) self.grid:setIndex(1)
self.doc:setText(self:getDocumentation())
self.statusBar:setStatus(self.peripheral.type) self.statusBar:setStatus(self.peripheral.type)
UI.Page.enable(self) UI.Page.enable(self)
self:setFocus(self.grid)
end
function methodsPage.doc:focus()
-- allow keyboard scrolling
end end
function methodsPage:eventHandler(event) function methodsPage:eventHandler(event)
@@ -122,82 +136,62 @@ function methodsPage:eventHandler(event)
UI:setPage(peripheralsPage) UI:setPage(peripheralsPage)
return true return true
elseif event.type == 'grid_focus_row' then elseif event.type == 'grid_focus_row' then
self.viewportConsole.offy = 0 self.doc:setText(self:getDocumentation())
self.viewportConsole:draw()
end end
return UI.Page.eventHandler(self, event) return UI.Page.eventHandler(self, event)
end end
function methodsPage.viewportConsole:draw() function methodsPage:getDocumentation()
local c = self
local method = methodsPage.grid:getSelected()
c:clear() local method = self.grid:getSelected()
c:setCursorPos(1, 1)
if method.noext then if method.noext then -- computercraft docs
c.cursorY = 2 return 'No documentation'
c:print('No extended Information')
return 2
end end
if method.doc then if method.doc then -- plethora docs
c:print(method.doc, nil, colors.yellow) return Ansi.yellow .. method.doc
c.ymax = c.cursorY + 1
return
end end
-- open peripherals docs
local sb = { }
if method.description then if method.description then
c:print(method.description) table.insert(sb, method.description .. '\n\n')
end end
c.cursorY = c.cursorY + 2
c.cursorX = 1
if method.returnTypes ~= '()' then if method.returnTypes ~= '()' then
c:print(method.returnTypes .. ' ', nil, colors.yellow) table.insert(sb, Ansi.yellow .. method.returnTypes .. ' ')
end end
c:print(method.name, nil, colors.black) table.insert(sb, Ansi.blue .. method.name .. Ansi.reset .. '(')
c:print('(')
local maxArgLen = 1
for k,arg in ipairs(method.args) do for k,arg in ipairs(method.args) do
if #arg.description > 0 then
maxArgLen = math.max(#arg.name, maxArgLen)
end
local argName = arg.name
local fg = colors.green
if arg.optional then if arg.optional then
argName = string.format('[%s]', arg.name) table.insert(sb, Ansi.orange .. string.format('[%s]', arg.name))
fg = colors.orange else
table.insert(sb, Ansi.green .. arg.name)
end end
c:print(argName, nil, fg)
if k < #method.args then if k < #method.args then
c:print(', ') table.insert(sb, ',')
end end
end end
c:print(')') table.insert(sb, Ansi.reset .. ')')
c.cursorY = c.cursorY + 1
Util.filterInplace(method.args, function(a) return #a.description > 0 end)
if #method.args > 0 then if #method.args > 0 then
for _,arg in ipairs(method.args) do table.insert(sb, '\n\n')
if #arg.description > 0 then for k,arg in ipairs(method.args) do
c.cursorY = c.cursorY + 1
c.cursorX = 1
local fg = colors.green
if arg.optional then if arg.optional then
fg = colors.orange table.insert(sb, Ansi.orange)
else
table.insert(sb, Ansi.green)
end end
c:print(arg.name .. ': ', nil, fg) table.insert(sb, arg.name .. Ansi.reset .. ': ' .. arg.description)
c.cursorX = maxArgLen + 3 if k ~= #method.args then
c:print(arg.description, nil, nil, maxArgLen + 3) table.insert(sb, '\n\n')
end end
end end
end end
return table.concat(sb)
c.ymax = c.cursorY + 1
end end
Event.on('peripheral', function() Event.on('peripheral', function()