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 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
|
2019-12-07 19:04:58 +00:00
|
|
|
table.insert(topics, { name = topic, lname = topic:lower() })
|
2016-12-11 19:24:52 +00:00
|
|
|
end
|
|
|
|
|
2019-12-07 19:04:58 +00:00
|
|
|
UI:addPage('main', UI.Page {
|
2020-04-22 04:40:59 +00:00
|
|
|
UI.Text {
|
2018-01-24 22:39:38 +00:00
|
|
|
x = 3, y = 2,
|
|
|
|
value = 'Search',
|
|
|
|
},
|
2020-04-22 04:40:59 +00:00
|
|
|
UI.TextEntry {
|
2018-01-24 22:39:38 +00:00
|
|
|
x = 10, y = 2, ex = -3,
|
|
|
|
limit = 32,
|
|
|
|
},
|
|
|
|
grid = UI.ScrollingGrid {
|
|
|
|
y = 4,
|
|
|
|
values = topics,
|
|
|
|
columns = {
|
|
|
|
{ heading = 'Topic', key = 'name' },
|
|
|
|
},
|
2019-12-07 19:04:58 +00:00
|
|
|
sortColumn = 'lname',
|
2018-01-24 22:39:38 +00:00
|
|
|
},
|
|
|
|
accelerators = {
|
2019-07-02 18:11:33 +00:00
|
|
|
[ 'control-q' ] = 'quit',
|
2018-01-24 22:39:38 +00:00
|
|
|
enter = 'grid_select',
|
|
|
|
},
|
2019-12-07 19:04:58 +00:00
|
|
|
eventHandler = function(self, event)
|
|
|
|
if event.type == 'quit' then
|
|
|
|
UI:quit()
|
2016-12-11 19:24:52 +00:00
|
|
|
|
2019-12-07 19:04:58 +00:00
|
|
|
elseif event.type == 'grid_select' then
|
|
|
|
if self.grid:getSelected() then
|
2020-04-22 04:40:59 +00:00
|
|
|
UI:setPage('topic', self.grid:getSelected().name)
|
2019-12-07 19:04:58 +00:00
|
|
|
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()
|
2020-04-22 04:40:59 +00:00
|
|
|
|
2019-12-07 19:04:58 +00:00
|
|
|
else
|
|
|
|
return UI.Page.eventHandler(self, event)
|
|
|
|
end
|
|
|
|
end,
|
|
|
|
})
|
|
|
|
|
|
|
|
UI:addPage('topic', UI.Page {
|
2020-04-22 04:40:59 +00:00
|
|
|
backgroundColor = 'black',
|
2018-01-24 22:39:38 +00:00
|
|
|
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 {
|
|
|
|
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',
|
|
|
|
},
|
2019-12-07 19:04:58 +00:00
|
|
|
enable = function(self, name)
|
|
|
|
local f = help.lookup(name)
|
2019-04-07 14:09:47 +00:00
|
|
|
|
2019-12-07 19:04:58 +00:00
|
|
|
self.titleBar.title = name
|
|
|
|
self.helpText:setText(f and Util.readFile(f) or 'No help available for ' .. name)
|
2019-04-07 14:09:47 +00:00
|
|
|
|
2019-12-07 19:04:58 +00:00
|
|
|
return UI.Page.enable(self)
|
|
|
|
end,
|
|
|
|
eventHandler = function(self, event)
|
|
|
|
if event.type == 'back' then
|
|
|
|
UI:setPage('main')
|
2018-01-24 22:39:38 +00:00
|
|
|
end
|
|
|
|
return UI.Page.eventHandler(self, event)
|
2019-12-07 19:04:58 +00:00
|
|
|
end,
|
|
|
|
})
|
2016-12-11 19:24:52 +00:00
|
|
|
|
2019-07-23 19:29:43 +00:00
|
|
|
local args = Util.parse(...)
|
2019-12-07 19:04:58 +00:00
|
|
|
UI:setPage(args[1] and 'topic' or 'main', args[1])
|
|
|
|
UI:start()
|