2019-06-28 17:50:02 +00:00
|
|
|
local UI = require('opus.ui')
|
|
|
|
local Util = require('opus.util')
|
2017-10-08 03:03:18 +00:00
|
|
|
|
2019-04-07 14:09:47 +00:00
|
|
|
local colors = _G.colors
|
|
|
|
local help = _G.help
|
2016-12-11 19:24:52 +00:00
|
|
|
|
|
|
|
UI:configure('Help', ...)
|
|
|
|
|
2017-10-08 03:03:18 +00:00
|
|
|
local topics = { }
|
|
|
|
for _,topic in pairs(help.topics()) do
|
2018-01-24 22:39:38 +00:00
|
|
|
if help.lookup(topic) then
|
|
|
|
table.insert(topics, { name = topic })
|
|
|
|
end
|
2016-12-11 19:24:52 +00:00
|
|
|
end
|
|
|
|
|
2017-10-01 00:35:36 +00:00
|
|
|
local page = UI.Page {
|
2018-01-24 22:39:38 +00:00
|
|
|
labelText = UI.Text {
|
|
|
|
x = 3, y = 2,
|
|
|
|
value = 'Search',
|
|
|
|
},
|
|
|
|
filter = UI.TextEntry {
|
|
|
|
x = 10, y = 2, ex = -3,
|
|
|
|
limit = 32,
|
2019-07-11 16:36:17 +00:00
|
|
|
transform = 'lowercase',
|
2018-01-24 22:39:38 +00:00
|
|
|
},
|
|
|
|
grid = UI.ScrollingGrid {
|
|
|
|
y = 4,
|
|
|
|
values = topics,
|
|
|
|
columns = {
|
|
|
|
{ heading = 'Topic', key = 'name' },
|
|
|
|
},
|
|
|
|
sortColumn = 'name',
|
|
|
|
},
|
|
|
|
accelerators = {
|
2019-07-02 18:11:33 +00:00
|
|
|
[ 'control-q' ] = 'quit',
|
2018-01-24 22:39:38 +00:00
|
|
|
enter = 'grid_select',
|
|
|
|
},
|
2017-10-01 00:35:36 +00:00
|
|
|
}
|
2016-12-11 19:24:52 +00:00
|
|
|
|
2017-10-08 03:03:18 +00:00
|
|
|
local topicPage = UI.Page {
|
2018-01-24 22:39:38 +00:00
|
|
|
backgroundColor = colors.black,
|
|
|
|
titleBar = UI.TitleBar {
|
|
|
|
title = 'text',
|
2019-04-07 14:09:47 +00:00
|
|
|
event = 'back',
|
2018-01-24 22:39:38 +00:00
|
|
|
},
|
|
|
|
helpText = UI.TextArea {
|
|
|
|
backgroundColor = colors.black,
|
|
|
|
x = 2, ex = -1, y = 3, ey = -2,
|
|
|
|
},
|
|
|
|
accelerators = {
|
2019-07-02 18:11:33 +00:00
|
|
|
[ 'control-q' ] = 'back',
|
2018-01-24 22:39:38 +00:00
|
|
|
backspace = 'back',
|
|
|
|
},
|
2017-10-08 03:03:18 +00:00
|
|
|
}
|
|
|
|
|
2019-04-07 14:09:47 +00:00
|
|
|
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)
|
|
|
|
|
|
|
|
return UI.Page.enable(self)
|
|
|
|
end
|
|
|
|
|
2017-10-08 03:03:18 +00:00
|
|
|
function topicPage:eventHandler(event)
|
2018-01-24 22:39:38 +00:00
|
|
|
if event.type == 'back' then
|
2019-04-07 14:09:47 +00:00
|
|
|
UI:setPage(page)
|
2018-01-24 22:39:38 +00:00
|
|
|
end
|
|
|
|
return UI.Page.eventHandler(self, event)
|
2016-12-11 19:24:52 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function page:eventHandler(event)
|
2018-01-24 22:39:38 +00:00
|
|
|
if event.type == 'quit' then
|
|
|
|
UI:exitPullEvents()
|
2016-12-11 19:24:52 +00:00
|
|
|
|
2018-01-24 22:39:38 +00:00
|
|
|
elseif event.type == 'grid_select' then
|
|
|
|
if self.grid:getSelected() then
|
|
|
|
local name = self.grid:getSelected().name
|
2017-10-08 03:03:18 +00:00
|
|
|
|
2019-04-07 14:09:47 +00:00
|
|
|
UI:setPage(topicPage, name)
|
2018-01-24 22:39:38 +00:00
|
|
|
end
|
2016-12-11 19:24:52 +00:00
|
|
|
|
2018-01-24 22:39:38 +00:00
|
|
|
elseif event.type == 'text_change' then
|
|
|
|
if #event.text == 0 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
|
2016-12-11 19:24:52 +00:00
|
|
|
end
|
|
|
|
|
2019-07-23 19:29:43 +00:00
|
|
|
local args = Util.parse(...)
|
2019-04-19 23:03:34 +00:00
|
|
|
UI:setPage(args[1] and topicPage or page, args[1])
|
2017-07-28 23:01:59 +00:00
|
|
|
UI:pullEvents()
|