2016-12-11 19:24:52 +00:00
|
|
|
local Event = require('event')
|
2017-09-05 06:09:31 +00:00
|
|
|
local UI = require('ui')
|
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 {
|
2018-01-24 22:39:38 +00:00
|
|
|
menuBar = UI.MenuBar {
|
|
|
|
buttons = {
|
|
|
|
{ text = 'Activate', event = 'activate' },
|
|
|
|
{ text = 'Terminate', event = 'terminate' },
|
|
|
|
},
|
|
|
|
},
|
|
|
|
grid = UI.ScrollingGrid {
|
|
|
|
y = 2,
|
|
|
|
columns = {
|
|
|
|
{ heading = 'ID', key = 'uid', width = 3 },
|
|
|
|
{ heading = 'Title', key = 'title' },
|
|
|
|
{ heading = 'Status', key = 'status' },
|
|
|
|
{ heading = 'Time', key = 'timestamp' },
|
|
|
|
},
|
|
|
|
values = kernel.routines,
|
|
|
|
sortColumn = 'uid',
|
|
|
|
autospace = true,
|
|
|
|
},
|
|
|
|
accelerators = {
|
|
|
|
q = 'quit',
|
|
|
|
space = 'activate',
|
|
|
|
t = 'terminate',
|
|
|
|
},
|
2016-12-11 19:24:52 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function page:eventHandler(event)
|
2018-01-24 22:39:38 +00:00
|
|
|
local t = self.grid:getSelected()
|
|
|
|
if t then
|
|
|
|
if event.type == 'activate' or event.type == 'grid_select' then
|
|
|
|
multishell.setFocus(t.uid)
|
|
|
|
elseif event.type == 'terminate' then
|
|
|
|
multishell.terminate(t.uid)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
if event.type == 'quit' then
|
|
|
|
Event.exitPullEvents()
|
|
|
|
end
|
|
|
|
UI.Page.eventHandler(self, event)
|
2016-12-11 19:24:52 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
function page.grid:getDisplayValues(row)
|
2018-01-24 22:39:38 +00:00
|
|
|
local elapsed = os.clock()-row.timestamp
|
2019-02-27 13:10:09 +00:00
|
|
|
return {
|
|
|
|
uid = row.uid,
|
|
|
|
title = row.title,
|
|
|
|
status = row.isDead and 'error' or coroutine.status(row.co),
|
|
|
|
timestamp = elapsed < 60 and
|
|
|
|
string.format("%ds", math.floor(elapsed)) or
|
|
|
|
string.format("%sm", math.floor(elapsed/6)/10),
|
|
|
|
}
|
2016-12-11 19:24:52 +00:00
|
|
|
end
|
|
|
|
|
2017-07-28 23:01:59 +00:00
|
|
|
Event.onInterval(1, function()
|
2018-01-24 22:39:38 +00:00
|
|
|
page.grid:update()
|
|
|
|
page.grid:draw()
|
|
|
|
page:sync()
|
2016-12-11 19:24:52 +00:00
|
|
|
end)
|
|
|
|
|
|
|
|
UI:setPage(page)
|
2017-07-28 23:01:59 +00:00
|
|
|
UI:pullEvents()
|