opus/sys/apps/Tasks.lua

77 lines
1.7 KiB
Lua
Raw Normal View History

2018-01-21 10:44:13 +00:00
_G.requireInjector(_ENV)
2016-12-11 19:24:52 +00:00
local Event = require('event')
local UI = require('ui')
local Util = require('util')
2016-12-11 19:24:52 +00:00
2018-01-20 12:18:13 +00:00
local kernel = _G.kernel
2017-10-08 21:45:01 +00:00
local multishell = _ENV.multishell
2018-01-12 01:53:32 +00:00
UI:configure('Tasks', ...)
2016-12-11 19:24:52 +00:00
local page = UI.Page {
menuBar = UI.MenuBar {
buttons = {
{ text = 'Activate', event = 'activate' },
{ text = 'Terminate', event = 'terminate' },
},
},
grid = UI.ScrollingGrid {
y = 2,
columns = {
2018-01-14 23:28:23 +00:00
{ heading = 'ID', key = 'uid', width = 3 },
2016-12-11 19:24:52 +00:00
{ heading = 'Title', key = 'title' },
{ heading = 'Status', key = 'status' },
{ heading = 'Time', key = 'timestamp' },
},
2018-01-20 12:18:13 +00:00
values = kernel.routines,
2018-01-14 04:40:53 +00:00
sortColumn = 'uid',
2016-12-11 19:24:52 +00:00
autospace = true,
},
accelerators = {
q = 'quit',
space = 'activate',
t = 'terminate',
},
}
function page:eventHandler(event)
local t = self.grid:getSelected()
if t then
if event.type == 'activate' or event.type == 'grid_select' then
2018-01-12 01:53:32 +00:00
multishell.setFocus(t.uid)
2016-12-11 19:24:52 +00:00
elseif event.type == 'terminate' then
2018-01-12 01:53:32 +00:00
multishell.terminate(t.uid)
2016-12-11 19:24:52 +00:00
end
end
if event.type == 'quit' then
Event.exitPullEvents()
end
UI.Page.eventHandler(self, event)
end
function page.grid:getDisplayValues(row)
row = Util.shallowCopy(row)
local elapsed = os.clock()-row.timestamp
if elapsed < 60 then
row.timestamp = string.format("%ds", math.floor(elapsed))
else
2017-07-24 02:37:07 +00:00
row.timestamp = string.format("%sm", math.floor(elapsed/6)/10)
2016-12-11 19:24:52 +00:00
end
if row.isDead then
row.status = 'error'
else
row.status = coroutine.status(row.co)
end
return row
end
2017-07-28 23:01:59 +00:00
Event.onInterval(1, function()
2016-12-11 19:24:52 +00:00
page.grid:update()
page.grid:draw()
page:sync()
end)
UI:setPage(page)
2017-07-28 23:01:59 +00:00
UI:pullEvents()