1
0
mirror of https://github.com/kepler155c/opus synced 2024-12-28 09:30:34 +00:00
opus/sys/apps/Tasks.lua

73 lines
1.6 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 {
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
row = Util.shallowCopy(row)
local elapsed = os.clock()-row.timestamp
if elapsed < 60 then
row.timestamp = string.format("%ds", math.floor(elapsed))
else
row.timestamp = string.format("%sm", math.floor(elapsed/6)/10)
end
row.status = row.isDead and 'error' or coroutine.status(row.co)
return row
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()