Terminal: support multiple lines and make it re-invokeable (#6599)

With this changes you can enter multiple lines with commands and after viewing the output you can re-invoke the terminal with a button
reviewable/pr6603/r1
smartscripts-nl 4 years ago committed by GitHub
parent 0d501f2308
commit 4cff623244
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -21,13 +21,16 @@ function Terminal:init()
self.ui.menu:registerToMainMenu(self)
end
function Terminal:start()
function Terminal:onTerminalStart()
self.input = InputDialog:new{
title = _("Enter a command and press \"Execute\""),
input = self.command,
para_direction_rtl = false, -- force LTR
text_height = math.floor(Screen:getHeight() * 0.4),
input_type = "string",
-- allow multiple lines with commands:
allow_newline = true,
cursor_at_end = true,
buttons = {{{
text = _("Cancel"),
callback = function()
@ -35,7 +38,6 @@ function Terminal:start()
end,
}, {
text = _("Execute"),
is_enter_default = true,
callback = function()
UIManager:close(self.input)
Trapper:wrap(function()
@ -66,12 +68,32 @@ function Terminal:execute()
table.insert(entries, _("Execution canceled."))
end
UIManager:close(wait_msg)
UIManager:show(TextViewer:new{
local viewer
viewer = TextViewer:new {
title = _("Command output"),
text = table.concat(entries, "\n"),
justified = false,
text_face = Font:getFace("smallinfont"),
})
-- support re-invoking the terminal with a button:
buttons_table = {
{
{
text = _("Back"),
callback = function()
UIManager:close(viewer)
self:onTerminalStart()
end,
},
{
text = _("Close"),
callback = function()
UIManager:close(viewer)
end,
},
},
},
}
UIManager:show(viewer)
end
function Terminal:dump(entries)
@ -90,7 +112,7 @@ function Terminal:addToMainMenu(menu_items)
text = _("Terminal emulator"),
keep_menu_open = true,
callback = function()
self:start()
self:onTerminalStart()
end,
}
end

Loading…
Cancel
Save