mirror of
https://github.com/kepler155c/opus
synced 2025-06-10 10:34:11 +00:00
threads
This commit is contained in:
parent
5c12b20fae
commit
c2500f0167
@ -34,7 +34,7 @@ local page = UI.Page({
|
|||||||
up = 'history_back',
|
up = 'history_back',
|
||||||
down = 'history_forward',
|
down = 'history_forward',
|
||||||
mouse_rightclick = 'clear_prompt',
|
mouse_rightclick = 'clear_prompt',
|
||||||
[ 'control-space' ] = 'autocomplete',
|
-- [ 'control-space' ] = 'autocomplete',
|
||||||
},
|
},
|
||||||
}),
|
}),
|
||||||
grid = UI.ScrollingGrid({
|
grid = UI.ScrollingGrid({
|
||||||
@ -73,7 +73,7 @@ function page:enable()
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function autocomplete(env, oLine, x)
|
local function autocomplete(env, oLine, x)
|
||||||
|
|
||||||
local sLine = oLine:sub(1, x)
|
local sLine = oLine:sub(1, x)
|
||||||
local nStartPos = sLine:find("[a-zA-Z0-9_%.]+$")
|
local nStartPos = sLine:find("[a-zA-Z0-9_%.]+$")
|
||||||
|
@ -7,37 +7,37 @@ multishell.setTitle(multishell.getCurrent(), 'Network')
|
|||||||
UI:configure('Network', ...)
|
UI:configure('Network', ...)
|
||||||
|
|
||||||
local gridColumns = {
|
local gridColumns = {
|
||||||
{ heading = 'Label', key = 'label' },
|
{ heading = 'Label', key = 'label' },
|
||||||
{ heading = 'Dist', key = 'distance' },
|
{ heading = 'Dist', key = 'distance' },
|
||||||
{ heading = 'Status', key = 'status' },
|
{ heading = 'Status', key = 'status' },
|
||||||
}
|
}
|
||||||
|
|
||||||
if UI.term.width >= 30 then
|
if UI.term.width >= 30 then
|
||||||
table.insert(gridColumns, { heading = 'Fuel', key = 'fuel' })
|
table.insert(gridColumns, { heading = 'Fuel', key = 'fuel' })
|
||||||
table.insert(gridColumns, { heading = 'Uptime', key = 'uptime' })
|
table.insert(gridColumns, { heading = 'Uptime', key = 'uptime' })
|
||||||
end
|
end
|
||||||
|
|
||||||
local page = UI.Page({
|
local page = UI.Page {
|
||||||
menuBar = UI.MenuBar({
|
menuBar = UI.MenuBar {
|
||||||
buttons = {
|
buttons = {
|
||||||
{ text = 'Telnet', event = 'telnet' },
|
{ text = 'Telnet', event = 'telnet' },
|
||||||
{ text = 'VNC', event = 'vnc' },
|
{ text = 'VNC', event = 'vnc' },
|
||||||
{ text = 'Reboot', event = 'reboot' },
|
{ text = 'Reboot', event = 'reboot' },
|
||||||
},
|
},
|
||||||
}),
|
},
|
||||||
grid = UI.ScrollingGrid({
|
grid = UI.ScrollingGrid {
|
||||||
y = 2,
|
y = 2,
|
||||||
values = network,
|
values = network,
|
||||||
columns = gridColumns,
|
columns = gridColumns,
|
||||||
sortColumn = 'label',
|
sortColumn = 'label',
|
||||||
autospace = true,
|
autospace = true,
|
||||||
}),
|
},
|
||||||
notification = UI.Notification(),
|
notification = UI.Notification { },
|
||||||
accelerators = {
|
accelerators = {
|
||||||
q = 'quit',
|
q = 'quit',
|
||||||
c = 'clear',
|
c = 'clear',
|
||||||
},
|
},
|
||||||
})
|
}
|
||||||
|
|
||||||
function sendCommand(host, command)
|
function sendCommand(host, command)
|
||||||
|
|
||||||
@ -60,7 +60,7 @@ function sendCommand(host, command)
|
|||||||
end
|
end
|
||||||
|
|
||||||
function page:eventHandler(event)
|
function page:eventHandler(event)
|
||||||
local t = self.grid.selected
|
local t = self.grid:getSelected()
|
||||||
if t then
|
if t then
|
||||||
if event.type == 'telnet' or event.type == 'grid_select' then
|
if event.type == 'telnet' or event.type == 'grid_select' then
|
||||||
multishell.openTab({
|
multishell.openTab({
|
||||||
@ -113,14 +113,6 @@ function page.grid:getDisplayValues(row)
|
|||||||
return row
|
return row
|
||||||
end
|
end
|
||||||
|
|
||||||
function page.grid:draw()
|
|
||||||
self:adjustWidth()
|
|
||||||
UI.Grid.draw(self)
|
|
||||||
if page.notification.enabled then
|
|
||||||
page.notification:draw()
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
Event.addThread(function()
|
Event.addThread(function()
|
||||||
while true do
|
while true do
|
||||||
page.grid:update()
|
page.grid:update()
|
||||||
|
@ -62,11 +62,6 @@ function page.grid:getDisplayValues(row)
|
|||||||
return row
|
return row
|
||||||
end
|
end
|
||||||
|
|
||||||
function page.grid:draw()
|
|
||||||
self:adjustWidth()
|
|
||||||
UI.Grid.draw(self)
|
|
||||||
end
|
|
||||||
|
|
||||||
Event.addTimer(1, true, function()
|
Event.addTimer(1, true, function()
|
||||||
page.grid:update()
|
page.grid:update()
|
||||||
page.grid:draw()
|
page.grid:draw()
|
||||||
|
@ -121,14 +121,9 @@ end
|
|||||||
local exitPullEvents = false
|
local exitPullEvents = false
|
||||||
|
|
||||||
local function _pullEvents()
|
local function _pullEvents()
|
||||||
|
|
||||||
--exitPullEvents = false
|
|
||||||
while true do
|
while true do
|
||||||
local e = { Process:pullEvent() }
|
local e = { os.pullEvent() }
|
||||||
Event.processEvent(e)
|
Event.processEvent(e)
|
||||||
if exitPullEvents or e[1] == 'terminate' then
|
|
||||||
break
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -144,13 +139,19 @@ function Event.addThread(fn)
|
|||||||
end
|
end
|
||||||
|
|
||||||
function Event.pullEvents(...)
|
function Event.pullEvents(...)
|
||||||
|
Process:addThread(_pullEvents)
|
||||||
local routines = { ... }
|
local routines = { ... }
|
||||||
if #routines > 0 then
|
if #routines > 0 then
|
||||||
for _, routine in ipairs(routines) do
|
for _, routine in ipairs(routines) do
|
||||||
Process:addThread(routine)
|
Process:addThread(routine)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
_pullEvents()
|
while true do
|
||||||
|
local e = Process:pullEvent()
|
||||||
|
if exitPullEvents or e == 'terminate' then
|
||||||
|
break
|
||||||
|
end
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
function Event.exitPullEvents()
|
function Event.exitPullEvents()
|
||||||
|
@ -87,8 +87,11 @@ function Process:resume(event, ...)
|
|||||||
return true, self.filter
|
return true, self.filter
|
||||||
end
|
end
|
||||||
|
|
||||||
function Process:pullEvent(filter)
|
-- confusing...
|
||||||
|
|
||||||
|
-- pull either one event if no filter or until event matches filter
|
||||||
|
-- or until terminated (regardless of filter)
|
||||||
|
function Process:pullEvent(filter)
|
||||||
while true do
|
while true do
|
||||||
local e = { os.pullEventRaw() }
|
local e = { os.pullEventRaw() }
|
||||||
self:threadEvent(unpack(e))
|
self:threadEvent(unpack(e))
|
||||||
@ -99,12 +102,12 @@ function Process:pullEvent(filter)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- pull events until either the filter is matched or terminated
|
||||||
function Process:pullEvents(filter)
|
function Process:pullEvents(filter)
|
||||||
|
|
||||||
while true do
|
while true do
|
||||||
local e = { os.pullEventRaw(filter) }
|
local e = { os.pullEventRaw() }
|
||||||
self:threadEvent(unpack(e))
|
self:threadEvent(unpack(e))
|
||||||
if e[1] == 'terminate' then
|
if (filter and e[1] == filter) or e[1] == 'terminate' then
|
||||||
return unpack(e)
|
return unpack(e)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user