Add awful.widget.prompt.spawn_and_handle_error helper
This is meant to avoid boilerplate code when creating prompt hooks.
This commit is contained in:
parent
ce2d31cbde
commit
b3c7efd5e4
|
@ -24,15 +24,19 @@ local function run(promptbox)
|
|||
return prompt.run({ prompt = promptbox.prompt },
|
||||
promptbox.widget,
|
||||
function (...)
|
||||
local result = spawn(...)
|
||||
if type(result) == "string" then
|
||||
promptbox.widget:set_text(result)
|
||||
end
|
||||
promptbox:spawn_and_handle_error(...)
|
||||
end,
|
||||
completion.shell,
|
||||
util.getdir("cache") .. "/history")
|
||||
end
|
||||
|
||||
local function spawn_and_handle_error(self, ...)
|
||||
local result = spawn(...)
|
||||
if type(result) == "string" then
|
||||
self.widget:set_text(result)
|
||||
end
|
||||
end
|
||||
|
||||
--- Create a prompt widget which will launch a command.
|
||||
--
|
||||
-- @param args Arguments table. "prompt" is the prompt to use.
|
||||
|
@ -45,6 +49,7 @@ function widgetprompt.new(args)
|
|||
promptbox.widget = widget
|
||||
promptbox.widget:set_ellipsize("start")
|
||||
promptbox.run = run
|
||||
promptbox.spawn_and_handle_error = spawn_and_handle_error
|
||||
promptbox.prompt = args.prompt or "Run: "
|
||||
return promptbox
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue