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

97 lines
2.0 KiB
Lua
Raw Normal View History

local fuzzy = require('opus.fuzzy')
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.sortColumn = 'lname'
2019-12-07 19:04:58 +00:00
else
self.grid.sortColumn = 'score'
self.grid.inverseSort = false
local pattern = event.text:lower()
for _,v in pairs(self.grid.values) do
v.score = -fuzzy(v.lname, pattern)
2019-12-07 19:04:58 +00:00
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()