This commit is contained in:
kepler155c@gmail.com 2019-12-07 12:04:58 -07:00
parent 424fff7842
commit 28b2ba3386
6 changed files with 85 additions and 101 deletions

View File

@ -8,12 +8,10 @@ UI:configure('Help', ...)
local topics = { }
for _,topic in pairs(help.topics()) do
if help.lookup(topic) then
table.insert(topics, { name = topic })
end
table.insert(topics, { name = topic, lname = topic:lower() })
end
local page = UI.Page {
UI:addPage('main', UI.Page {
labelText = UI.Text {
x = 3, y = 2,
value = 'Search',
@ -21,7 +19,6 @@ local page = UI.Page {
filter = UI.TextEntry {
x = 10, y = 2, ex = -3,
limit = 32,
transform = 'lowercase',
},
grid = UI.ScrollingGrid {
y = 4,
@ -29,15 +26,44 @@ local page = UI.Page {
columns = {
{ heading = 'Topic', key = 'name' },
},
sortColumn = 'name',
sortColumn = 'lname',
},
accelerators = {
[ 'control-q' ] = 'quit',
enter = 'grid_select',
},
}
eventHandler = function(self, event)
if event.type == 'quit' then
UI:quit()
local topicPage = UI.Page {
elseif event.type == 'grid_select' then
if self.grid:getSelected() then
local name = self.grid:getSelected().name
UI:setPage('topic', name)
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()
else
return UI.Page.eventHandler(self, event)
end
end,
})
UI:addPage('topic', UI.Page {
backgroundColor = colors.black,
titleBar = UI.TitleBar {
title = 'text',
@ -51,54 +77,22 @@ local topicPage = UI.Page {
[ 'control-q' ] = 'back',
backspace = 'back',
},
}
enable = function(self, name)
local f = help.lookup(name)
function topicPage:enable(name)
local f = help.lookup(name)
self.titleBar.title = name
self.helpText:setText(f and Util.readFile(f) or 'No help available for ' .. name)
self.titleBar.title = name
self.helpText:setText(f and Util.readFile(f) or 'No help available for ' .. name)
return UI.Page.enable(self)
end
function topicPage:eventHandler(event)
if event.type == 'back' then
UI:setPage(page)
end
return UI.Page.eventHandler(self, event)
end
function page:eventHandler(event)
if event.type == 'quit' then
UI:exitPullEvents()
elseif event.type == 'grid_select' then
if self.grid:getSelected() then
local name = self.grid:getSelected().name
UI:setPage(topicPage, name)
return UI.Page.enable(self)
end,
eventHandler = function(self, event)
if event.type == 'back' then
UI:setPage('main')
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.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
end
end,
})
local args = Util.parse(...)
UI:setPage(args[1] and topicPage or page, args[1])
UI:pullEvents()
UI:setPage(args[1] and 'topic' or 'main', args[1])
UI:start()

View File

@ -27,6 +27,12 @@ local DEFAULT_ICON = NFT.parse("\0308\0317\153\153\153\153\153\
\0307\0318\153\153\153\153\153\
\0308\0317\153\153\153\153\153")
-- overview
local uid = _ENV.multishell.getCurrent()
device.keyboard.addHotkey('control-o', function()
_ENV.multishell.setFocus(uid)
end)
UI:configure('Overview', ...)
local config = {

View File

@ -4,58 +4,45 @@ local kernel = _G.kernel
local keyboard = _G.device.keyboard
local multishell = _ENV.multishell
if not multishell or not multishell.getTabs then
return
end
-- overview
keyboard.addHotkey('control-o', function()
for _,tab in pairs(multishell.getTabs()) do
if tab.isOverview then
multishell.setFocus(tab.uid)
if multishell and multishell.getTabs then
-- restart tab
keyboard.addHotkey('control-backspace', function()
local tab = kernel.getFocused()
if tab and not tab.noTerminate then
multishell.terminate(tab.uid)
multishell.openTab({
path = tab.path,
env = tab.env,
args = tab.args,
focused = true,
})
end
end
end)
-- restart tab
keyboard.addHotkey('control-backspace', function()
local uid = multishell.getFocus()
local tab = kernel.find(uid)
if not tab.isOverview then
multishell.terminate(uid)
multishell.openTab({
path = tab.path,
env = tab.env,
args = tab.args,
focused = true,
})
end
end)
end)
end
-- next tab
keyboard.addHotkey('control-tab', function()
local tabs = multishell.getTabs()
local visibleTabs = { }
local currentTabId = multishell.getFocus()
local currentTab = kernel.getFocused()
local function compareTab(a, b)
return a.uid < b.uid
end
for _,tab in Util.spairs(tabs, compareTab) do
for _,tab in Util.spairs(kernel.routines, compareTab) do
if not tab.hidden and not tab.noFocus then
table.insert(visibleTabs, tab)
end
end
for k,tab in ipairs(visibleTabs) do
if tab.uid == currentTabId then
if tab.uid == currentTab.uid then
if k < #visibleTabs then
multishell.setFocus(visibleTabs[k + 1].uid)
kernel.raise(visibleTabs[k + 1].uid)
return
end
end
end
if #visibleTabs > 0 then
multishell.setFocus(visibleTabs[1].uid)
kernel.raise(visibleTabs[1].uid)
end
end)

View File

@ -50,16 +50,9 @@ local function systemLog()
keyboard.removeHotkey('control-d')
end
if multishell and multishell.openTab then
multishell.openTab({
title = 'System Log',
fn = systemLog,
noTerminate = true,
hidden = true,
})
else
kernel.run({
title = 'Syslog',
fn = systemLog,
})
end
kernel.run({
title = 'System Log',
fn = systemLog,
noTerminate = true,
hidden = true,
})

View File

@ -18,3 +18,7 @@ deleteIfExists('sys/autorun/gpshost.lua')
deleteIfExists('sys/apps/network/redserver.lua')
deleteIfExists('sys/apis')
deleteIfExists('sys/autorun/apps.lua')
deleteIfExists('sys/init/6.tl3.lua')
-- remove this file
deleteIfExists('sys/autorun/upgraded.lua')

View File

@ -388,9 +388,9 @@ function Manager:pullEvents(...)
end
end
function Manager:exitPullEvents()
Event.exitPullEvents()
end
Manager.exitPullEvents = Event.exitPullEvents
Manager.quit = Event.exitPullEvents
Manager.start = Manager.pullEvents
local UI = Manager()