1
0
mirror of https://github.com/kepler155c/opus synced 2024-06-26 07:03:21 +00:00
opus/sys/apps/fileui.lua

40 lines
831 B
Lua
Raw Normal View History

2020-03-31 15:57:23 +00:00
local UI = require('opus.ui')
local Util = require('opus.util')
local shell = _ENV.shell
2020-04-14 20:12:04 +00:00
local multishell = _ENV.multishell
2020-03-31 15:57:23 +00:00
2020-04-14 20:12:04 +00:00
-- fileui [--path=path] [--exec=filename] [--title=title]
2020-03-31 15:57:23 +00:00
local page = UI.Page {
2020-04-05 02:56:53 +00:00
fileselect = UI.FileSelect { },
eventHandler = function(self, event)
if event.type == 'select_file' then
self.selected = event.file
2020-03-31 15:57:23 +00:00
UI:quit()
2020-04-05 02:56:53 +00:00
elseif event.type == 'select_cancel' then
2020-03-31 15:57:23 +00:00
UI:quit()
end
2020-04-05 02:56:53 +00:00
return UI.FileSelect.eventHandler(self, event)
end,
}
2020-03-31 15:57:23 +00:00
local _, args = Util.parse(...)
2020-04-14 20:12:04 +00:00
if args.title and multishell then
multishell.setTitle(multishell.getCurrent(), args.title)
end
2020-03-31 15:57:23 +00:00
UI:setPage(page, args.path)
UI:start()
UI.term:setCursorBlink(false)
2020-04-05 02:56:53 +00:00
if args.exec and page.selected then
shell.openForegroundTab(string.format('%s %s', args.exec, page.selected))
2020-03-31 15:57:23 +00:00
return
end
2020-04-05 02:56:53 +00:00
return page.selected