1
0
mirror of https://github.com/kepler155c/opus synced 2024-12-26 16:40:27 +00:00
opus/sys/apps/Help.lua

100 lines
2.0 KiB
Lua
Raw Normal View History

2017-10-08 21:45:01 +00:00
_G.requireInjector()
local UI = require('ui')
2017-10-08 03:03:18 +00:00
local Util = require('util')
2017-10-09 17:08:38 +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
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 {
labelText = UI.Text {
x = 3, y = 2,
2016-12-11 19:24:52 +00:00
value = 'Search',
2017-10-01 00:35:36 +00:00
},
filter = UI.TextEntry {
x = 10, y = 2, ex = -3,
2016-12-11 19:24:52 +00:00
limit = 32,
2017-10-01 00:35:36 +00:00
},
grid = UI.ScrollingGrid {
2016-12-11 19:24:52 +00:00
y = 4,
2017-10-08 03:03:18 +00:00
values = topics,
2016-12-11 19:24:52 +00:00
columns = {
2017-10-08 03:03:18 +00:00
{ heading = 'Topic', key = 'name' },
2016-12-11 19:24:52 +00:00
},
sortColumn = 'name',
2017-10-01 00:35:36 +00:00
},
2016-12-11 19:24:52 +00:00
accelerators = {
2017-10-01 00:35:36 +00:00
q = 'quit',
enter = 'grid_select',
2016-12-11 19:24:52 +00:00
},
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 {
backgroundColor = colors.black,
titleBar = UI.TitleBar {
title = 'text',
previousPage = true,
},
helpText = UI.TextArea {
backgroundColor = colors.black,
x = 2, ex = -1, y = 3, ey = -2,
},
accelerators = {
q = 'back',
backspace = 'back',
},
}
function topicPage:eventHandler(event)
if event.type == 'back' then
UI:setPreviousPage()
end
return UI.Page.eventHandler(self, event)
2016-12-11 19:24:52 +00:00
end
function page:eventHandler(event)
if event.type == 'quit' then
2017-10-08 03:03:18 +00:00
UI:exitPullEvents()
2016-12-11 19:24:52 +00:00
2017-10-01 00:35:36 +00:00
elseif event.type == 'grid_select' then
2017-07-28 23:01:59 +00:00
if self.grid:getSelected() then
2017-10-08 03:03:18 +00:00
local name = self.grid:getSelected().name
local f = help.lookup(name)
topicPage.titleBar.title = name
topicPage.helpText:setText(Util.readFile(f))
UI:setPage(topicPage)
2017-07-28 23:01:59 +00:00
end
2016-12-11 19:24:52 +00:00
elseif event.type == 'text_change' then
2017-10-08 03:03:18 +00:00
if #event.text == 0 then
self.grid.values = topics
2016-12-11 19:24:52 +00:00
else
self.grid.values = { }
2017-10-08 03:03:18 +00:00
for _,f in pairs(topics) do
if string.find(f.name, event.text) then
2016-12-11 19:24:52 +00:00
table.insert(self.grid.values, f)
end
end
end
self.grid:update()
self.grid:setIndex(1)
self.grid:draw()
else
2017-10-08 03:03:18 +00:00
return UI.Page.eventHandler(self, event)
2016-12-11 19:24:52 +00:00
end
end
UI:setPage(page)
2017-07-28 23:01:59 +00:00
UI:pullEvents()