1
0
mirror of https://github.com/kepler155c/opus synced 2024-11-14 20:54:50 +00:00
opus/sys/apps/Tasks.lua

76 lines
1.8 KiB
Lua
Raw Normal View History

local Event = require('opus.event')
local UI = require('opus.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
local tasks = multishell and multishell.getTabs and multishell.getTabs() or kernel.routines
2017-10-08 21:45:01 +00:00
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' },
{ text = 'Inspect', event = 'inspect' },
2018-01-24 22:39:38 +00:00
},
},
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 = tasks,
2018-01-24 22:39:38 +00:00
sortColumn = 'uid',
autospace = true,
2019-11-18 21:32:10 +00:00
getDisplayValues = function (_, row)
local elapsed = os.clock()-row.timestamp
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),
}
end
2018-01-24 22:39:38 +00:00
},
accelerators = {
[ 'control-q' ] = 'quit',
2020-05-08 03:34:50 +00:00
[ ' ' ] = 'activate',
2018-01-24 22:39:38 +00:00
t = 'terminate',
},
eventHandler = function (self, event)
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)
elseif event.type == 'inspect' then
multishell.openTab(_ENV, {
path = 'sys/apps/Lua.lua',
args = { t },
focused = true,
})
end
2018-01-24 22:39:38 +00:00
end
if event.type == 'quit' then
UI:quit()
end
UI.Page.eventHandler(self, event)
2018-01-24 22:39:38 +00:00
end
}
2016-12-11 19:24:52 +00:00
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)
UI:start()