opus/sys/apps/Help.lua

96 lines
1.9 KiB
Lua
Raw Normal View History

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 {
UI.Text {
2018-01-24 22:39:38 +00:00
x = 3, y = 2,
value = 'Search',
},
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 = {
[ '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
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()
2019-12-07 19:04:58 +00:00
else
return UI.Page.eventHandler(self, event)
end
end,
})
UI:addPage('topic', UI.Page {
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 = {
[ '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
local args = Util.parse(...)
2019-12-07 19:04:58 +00:00
UI:setPage(args[1] and 'topic' or 'main', args[1])
UI:start()