1
0
mirror of https://github.com/kepler155c/opus synced 2024-11-16 13:44:49 +00:00
opus/sys/apps/Help.lua

100 lines
1.8 KiB
Lua
Raw Normal View History

2018-01-24 22:39:38 +00:00
_G.requireInjector(_ENV)
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
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,
},
grid = UI.ScrollingGrid {
y = 4,
values = topics,
columns = {
{ heading = 'Topic', key = 'name' },
},
sortColumn = 'name',
},
accelerators = {
q = 'quit',
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',
previousPage = true,
},
helpText = UI.TextArea {
backgroundColor = colors.black,
x = 2, ex = -1, y = 3, ey = -2,
},
accelerators = {
q = 'back',
backspace = 'back',
},
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
UI:setPreviousPage()
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
local f = help.lookup(name)
2017-10-08 03:03:18 +00:00
2018-01-24 22:39:38 +00:00
topicPage.titleBar.title = name
topicPage.helpText:setText(Util.readFile(f))
2017-10-08 03:03:18 +00:00
2018-01-24 22:39:38 +00:00
UI:setPage(topicPage)
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
UI:setPage(page)
2017-07-28 23:01:59 +00:00
UI:pullEvents()