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

81 lines
1.6 KiB
Lua
Raw Normal View History

requireInjector(getfenv(1))
2016-12-11 19:24:52 +00:00
local Event = require('event')
local UI = require('ui')
2016-12-11 19:24:52 +00:00
multishell.setTitle(multishell.getCurrent(), 'Help')
UI:configure('Help', ...)
local files = { }
2017-10-01 00:35:36 +00:00
for _,f in pairs(help.topics()) do
2016-12-11 19:24:52 +00:00
table.insert(files, { name = f })
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,
values = files,
columns = {
2017-10-01 00:35:36 +00:00
{ heading = 'Name', 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
local function showHelp(name)
UI.term:reset()
shell.run('help ' .. name)
print('Press enter to return')
2017-07-30 23:53:43 +00:00
repeat
2017-10-01 00:35:36 +00:00
os.pullEvent('key')
2017-07-30 23:53:43 +00:00
local _, k = os.pullEvent('key_up')
until k == keys.enter
2016-12-11 19:24:52 +00:00
end
function page:eventHandler(event)
if event.type == 'quit' then
Event.exitPullEvents()
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
showHelp(self.grid:getSelected().name)
self:setFocus(self.filter)
self:draw()
end
2016-12-11 19:24:52 +00:00
elseif event.type == 'text_change' then
local text = event.text
if #text == 0 then
self.grid.values = files
else
self.grid.values = { }
for _,f in pairs(files) do
if string.find(f.name, text) then
table.insert(self.grid.values, f)
end
end
end
self.grid:update()
self.grid:setIndex(1)
self.grid:draw()
else
UI.Page.eventHandler(self, event)
end
end
UI:setPage(page)
2017-07-28 23:01:59 +00:00
UI:pullEvents()