1
0
mirror of https://github.com/kepler155c/opus synced 2024-12-28 01:20:27 +00:00
opus/sys/apps/Tabs.lua

77 lines
1.7 KiB
Lua
Raw Normal View History

2017-10-08 21:45:01 +00:00
_G.requireInjector()
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
2017-10-08 21:45:01 +00:00
local multishell = _ENV.multishell
2016-12-11 19:24:52 +00:00
multishell.setTitle(multishell.getCurrent(), 'Tabs')
UI:configure('Tabs', ...)
local page = UI.Page {
menuBar = UI.MenuBar {
buttons = {
{ text = 'Activate', event = 'activate' },
{ text = 'Terminate', event = 'terminate' },
},
},
grid = UI.ScrollingGrid {
y = 2,
columns = {
2017-09-30 02:30:01 +00:00
{ heading = 'ID', key = 'tabId', width = 4 },
2016-12-11 19:24:52 +00:00
{ heading = 'Title', key = 'title' },
{ heading = 'Status', key = 'status' },
{ heading = 'Time', key = 'timestamp' },
},
values = multishell.getTabs(),
sortColumn = 'title',
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
multishell.setFocus(t.tabId)
elseif event.type == 'terminate' then
multishell.terminate(t.tabId)
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()