From b3c7efd5e45a46b3d655ab12a1942c7c47631ad5 Mon Sep 17 00:00:00 2001 From: Daniel Hahler Date: Sun, 27 Sep 2015 16:55:46 +0200 Subject: [PATCH] Add awful.widget.prompt.spawn_and_handle_error helper This is meant to avoid boilerplate code when creating prompt hooks. --- lib/awful/widget/prompt.lua | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/lib/awful/widget/prompt.lua b/lib/awful/widget/prompt.lua index c8430ea65..37ee82ab8 100644 --- a/lib/awful/widget/prompt.lua +++ b/lib/awful/widget/prompt.lua @@ -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