This commit is contained in:
kepler155c@gmail.com
2019-12-07 12:04:58 -07:00
parent 424fff7842
commit 28b2ba3386
6 changed files with 85 additions and 101 deletions

View File

@@ -8,12 +8,10 @@ UI:configure('Help', ...)
local topics = { }
for _,topic in pairs(help.topics()) do
if help.lookup(topic) then
table.insert(topics, { name = topic })
end
table.insert(topics, { name = topic, lname = topic:lower() })
end
local page = UI.Page {
UI:addPage('main', UI.Page {
labelText = UI.Text {
x = 3, y = 2,
value = 'Search',
@@ -21,7 +19,6 @@ local page = UI.Page {
filter = UI.TextEntry {
x = 10, y = 2, ex = -3,
limit = 32,
transform = 'lowercase',
},
grid = UI.ScrollingGrid {
y = 4,
@@ -29,15 +26,44 @@ local page = UI.Page {
columns = {
{ heading = 'Topic', key = 'name' },
},
sortColumn = 'name',
sortColumn = 'lname',
},
accelerators = {
[ 'control-q' ] = 'quit',
enter = 'grid_select',
},
}
eventHandler = function(self, event)
if event.type == 'quit' then
UI:quit()
local topicPage = UI.Page {
elseif event.type == 'grid_select' then
if self.grid:getSelected() then
local name = self.grid:getSelected().name
UI:setPage('topic', name)
end
elseif event.type == 'text_change' then
if not event.text then
self.grid.values = topics
else
self.grid.values = { }
for _,f in pairs(topics) do
if string.find(f.lname, event.text:lower()) then
table.insert(self.grid.values, f)
end
end
end
self.grid:update()
self.grid:setIndex(1)
self.grid:draw()
else
return UI.Page.eventHandler(self, event)
end
end,
})
UI:addPage('topic', UI.Page {
backgroundColor = colors.black,
titleBar = UI.TitleBar {
title = 'text',
@@ -51,54 +77,22 @@ local topicPage = UI.Page {
[ 'control-q' ] = 'back',
backspace = 'back',
},
}
enable = function(self, name)
local f = help.lookup(name)
function topicPage:enable(name)
local f = help.lookup(name)
self.titleBar.title = name
self.helpText:setText(f and Util.readFile(f) or 'No help available for ' .. name)
self.titleBar.title = name
self.helpText:setText(f and Util.readFile(f) or 'No help available for ' .. name)
return UI.Page.enable(self)
end
function topicPage:eventHandler(event)
if event.type == 'back' then
UI:setPage(page)
end
return UI.Page.eventHandler(self, event)
end
function page:eventHandler(event)
if event.type == 'quit' then
UI:exitPullEvents()
elseif event.type == 'grid_select' then
if self.grid:getSelected() then
local name = self.grid:getSelected().name
UI:setPage(topicPage, name)
return UI.Page.enable(self)
end,
eventHandler = function(self, event)
if event.type == 'back' then
UI:setPage('main')
end
elseif event.type == 'text_change' then
if not event.text then
self.grid.values = topics
else
self.grid.values = { }
for _,f in pairs(topics) do
if string.find(f.name, event.text) then
table.insert(self.grid.values, f)
end
end
end
self.grid:update()
self.grid:setIndex(1)
self.grid:draw()
else
return UI.Page.eventHandler(self, event)
end
end
end,
})
local args = Util.parse(...)
UI:setPage(args[1] and topicPage or page, args[1])
UI:pullEvents()
UI:setPage(args[1] and 'topic' or 'main', args[1])
UI:start()