From d5f20a7e0b12da2451d9f661f1b92b7e70572d33 Mon Sep 17 00:00:00 2001 From: Aire-One Date: Wed, 31 Oct 2018 09:00:18 +0100 Subject: [PATCH 1/3] Add `done_callback` parameter to awful.widget.prompt constructor. --- lib/awful/widget/prompt.lua | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/lib/awful/widget/prompt.lua b/lib/awful/widget/prompt.lua index 8c12d1e1..55f5cf83 100644 --- a/lib/awful/widget/prompt.lua +++ b/lib/awful/widget/prompt.lua @@ -5,6 +5,7 @@ -- -- @author Julien Danjou <julien@danjou.info> -- @copyright 2009 Julien Danjou +-- @copyright 2018 Aire-One -- @classmod awful.widget.prompt --------------------------------------------------------------------------- @@ -43,6 +44,7 @@ local function run(promptbox) exe_callback = function (...) promptbox:spawn_and_handle_error(...) end, + done_callback = promptbox.done_callback } end @@ -61,6 +63,9 @@ end -- @tparam[opt=`beautiful.prompt_fg` or `beautiful.fg_normal`] color args.fg Prompt foreground color. -- @tparam[opt=`awful.completion.shell`] function args.completion_callback -- The callback function to call to get completion. See @{awful.prompt.run} for details. +-- @tparam[opt] function args.done_callback +-- The callback function to always call without arguments, regardless of +-- whether the prompt was cancelled. See @{awful.prompt.run} for details. -- @return An instance of prompt widget, inherits from `wibox.container.background`. -- @function awful.widget.prompt function widgetprompt.new(args) @@ -74,6 +79,7 @@ function widgetprompt.new(args) promptbox.fg = args.fg or beautiful.prompt_fg or beautiful.fg_normal promptbox.bg = args.bg or beautiful.prompt_bg or beautiful.bg_normal promptbox.completion_callback = args.completion_callback or completion.shell + promptbox.done_callback = args.done_callback or nil return promptbox end From bc822c0af7cbd25dcfb417d192a2644b42e99f68 Mon Sep 17 00:00:00 2001 From: Aire-One Date: Wed, 31 Oct 2018 11:35:56 +0100 Subject: [PATCH 2/3] Add all parameters from awful.prompt to awful.widget.prompt constructor. --- lib/awful/widget/prompt.lua | 54 +++++++++++++++++++++++++++++++++---- 1 file changed, 49 insertions(+), 5 deletions(-) diff --git a/lib/awful/widget/prompt.lua b/lib/awful/widget/prompt.lua index 55f5cf83..fc5264b3 100644 --- a/lib/awful/widget/prompt.lua +++ b/lib/awful/widget/prompt.lua @@ -39,12 +39,21 @@ local function run(promptbox) return prompt.run { prompt = promptbox.prompt, textbox = promptbox.widget, + fg_cursor = promptbox.fg_cursor, + bg_cursor = promptbox.bg_cursor, + ul_cursor = promptbox.ul_cursor, + font = promptbox.font, + autoexec = promptbox.autoexec, + highlighter = promptbox.highlighter, + exe_callback = promptbox.exe_callback, completion_callback = promptbox.completion_callback, - history_path = gfs.get_cache_dir() .. "/history", - exe_callback = function (...) - promptbox:spawn_and_handle_error(...) - end, - done_callback = promptbox.done_callback + history_path = promptbox.history_path, + history_max = promptbox.history_max, + done_callback = promptbox.done_callback, + changed_callback = promptbox.changed_callback, + keypressed_callback = promptbox.keypressed_callback, + keyreleased_callback = promptbox.keyreleased_callback, + hook = promptbox.hook } end @@ -56,16 +65,38 @@ local function spawn_and_handle_error(self, ...) end --- Create a prompt widget which will launch a command. +-- For additional documentation about `args` parameter, please refer to +-- @{awful.prompt} and @{awful.prompt.run}. -- -- @tparam table args Prompt arguments. -- @tparam[opt="Run: "] string args.prompt Prompt text. -- @tparam[opt=`beautiful.prompt_bg` or `beautiful.bg_normal`] color args.bg Prompt background color. -- @tparam[opt=`beautiful.prompt_fg` or `beautiful.fg_normal`] color args.fg Prompt foreground color. +-- @tparam[opt] gears.color args.fg_cursor +-- @tparam[opt] gears.color args.bg_cursor +-- @tparam[opt] gears.color args.ul_cursor +-- @tparam[opt] string args.font +-- @tparam[opt] boolean args.autoexec +-- @tparam[opt] function args.highlighter A function to add syntax highlighting +-- to the command. +-- @tparam[opt] function args.exe_callback The callback function to call with +-- command as argument when finished. -- @tparam[opt=`awful.completion.shell`] function args.completion_callback -- The callback function to call to get completion. See @{awful.prompt.run} for details. +-- @tparam[opt=`gears.filesystem.get_cache_dir() .. '/history'`] string +-- args.history_path File path where the history should be saved. +-- @tparam[opt=50] integer args.history_max Set the maximum entries in history file. -- @tparam[opt] function args.done_callback -- The callback function to always call without arguments, regardless of -- whether the prompt was cancelled. See @{awful.prompt.run} for details. +-- @tparam[opt] function args.changed_callback The callback function to call +-- with command as argument when a command was changed. +-- @tparam[opt] function args.keypressed_callback The callback function to call +-- with mod table, key and command as arguments when a key was pressed. +-- @tparam[opt] function args.keyreleased_callback The callback function to call +-- with mod table, key and command as arguments when a key was pressed. +-- @tparam[opt] table args.hook Similar to @{awful.key}. It will call a function +-- for the matching modifiers + key. See @{awful.prompt.run} for details. -- @return An instance of prompt widget, inherits from `wibox.container.background`. -- @function awful.widget.prompt function widgetprompt.new(args) @@ -78,8 +109,21 @@ function widgetprompt.new(args) promptbox.prompt = args.prompt or "Run: " promptbox.fg = args.fg or beautiful.prompt_fg or beautiful.fg_normal promptbox.bg = args.bg or beautiful.prompt_bg or beautiful.bg_normal + promptbox.fg_cursor = args.fg_cursor or nil + promptbox.bg_cursor = args.bg_cursor or nil + promptbox.ul_cursor = args.ul_cursor or nil + promptbox.font = args.font or nil + promptbox.autoexec = args.autoexec or nil + promptbox.highlighter = args.highlighter or nil + promptbox.exe_callback = args.exe_callback or function (...) promptbox:spawn_and_handle_error(...) end promptbox.completion_callback = args.completion_callback or completion.shell + promptbox.history_path = args.history_path or gfs.get_cache_dir() .. '/history' + promptbox.history_max = args.history_max or nil promptbox.done_callback = args.done_callback or nil + promptbox.changed_callback = args.changed_callback or nil + promptbox.keypressed_callback = args.keypressed_callback or nil + promptbox.keyreleased_callback = args.keyreleased_callback or nil + promptbox.hook = args.hook or nil return promptbox end From 1a96642615e7a27eb45a43313d7e8f8c0a88fbe8 Mon Sep 17 00:00:00 2001 From: Aire-One Date: Wed, 31 Oct 2018 11:42:36 +0100 Subject: [PATCH 3/3] format code and doc --- lib/awful/widget/prompt.lua | 60 +++++++++++++++++++++---------------- 1 file changed, 34 insertions(+), 26 deletions(-) diff --git a/lib/awful/widget/prompt.lua b/lib/awful/widget/prompt.lua index fc5264b3..c0fe2f5c 100644 --- a/lib/awful/widget/prompt.lua +++ b/lib/awful/widget/prompt.lua @@ -37,23 +37,23 @@ local widgetprompt = { mt = {} } -- @param promptbox The promptbox to run. local function run(promptbox) return prompt.run { - prompt = promptbox.prompt, - textbox = promptbox.widget, - fg_cursor = promptbox.fg_cursor, - bg_cursor = promptbox.bg_cursor, - ul_cursor = promptbox.ul_cursor, - font = promptbox.font, - autoexec = promptbox.autoexec, - highlighter = promptbox.highlighter, - exe_callback = promptbox.exe_callback, - completion_callback = promptbox.completion_callback, - history_path = promptbox.history_path, - history_max = promptbox.history_max, - done_callback = promptbox.done_callback, - changed_callback = promptbox.changed_callback, - keypressed_callback = promptbox.keypressed_callback, + prompt = promptbox.prompt, + textbox = promptbox.widget, + fg_cursor = promptbox.fg_cursor, + bg_cursor = promptbox.bg_cursor, + ul_cursor = promptbox.ul_cursor, + font = promptbox.font, + autoexec = promptbox.autoexec, + highlighter = promptbox.highlighter, + exe_callback = promptbox.exe_callback, + completion_callback = promptbox.completion_callback, + history_path = promptbox.history_path, + history_max = promptbox.history_max, + done_callback = promptbox.done_callback, + changed_callback = promptbox.changed_callback, + keypressed_callback = promptbox.keypressed_callback, keyreleased_callback = promptbox.keyreleased_callback, - hook = promptbox.hook + hook = promptbox.hook } end @@ -70,8 +70,10 @@ end -- -- @tparam table args Prompt arguments. -- @tparam[opt="Run: "] string args.prompt Prompt text. --- @tparam[opt=`beautiful.prompt_bg` or `beautiful.bg_normal`] color args.bg Prompt background color. --- @tparam[opt=`beautiful.prompt_fg` or `beautiful.fg_normal`] color args.fg Prompt foreground color. +-- @tparam[opt=`beautiful.prompt_bg` or `beautiful.bg_normal`] color args.bg +-- Prompt background color. +-- @tparam[opt=`beautiful.prompt_fg` or `beautiful.fg_normal`] color args.fg +-- Prompt foreground color. -- @tparam[opt] gears.color args.fg_cursor -- @tparam[opt] gears.color args.bg_cursor -- @tparam[opt] gears.color args.ul_cursor @@ -80,15 +82,17 @@ end -- @tparam[opt] function args.highlighter A function to add syntax highlighting -- to the command. -- @tparam[opt] function args.exe_callback The callback function to call with --- command as argument when finished. +-- command as argument when finished. -- @tparam[opt=`awful.completion.shell`] function args.completion_callback --- The callback function to call to get completion. See @{awful.prompt.run} for details. +-- The callback function to call to get completion. See @{awful.prompt.run} +-- for details. -- @tparam[opt=`gears.filesystem.get_cache_dir() .. '/history'`] string -- args.history_path File path where the history should be saved. --- @tparam[opt=50] integer args.history_max Set the maximum entries in history file. +-- @tparam[opt=50] integer args.history_max Set the maximum entries in +-- history file. -- @tparam[opt] function args.done_callback --- The callback function to always call without arguments, regardless of --- whether the prompt was cancelled. See @{awful.prompt.run} for details. +-- The callback function to always call without arguments, regardless of +-- whether the prompt was cancelled. See @{awful.prompt.run} for details. -- @tparam[opt] function args.changed_callback The callback function to call -- with command as argument when a command was changed. -- @tparam[opt] function args.keypressed_callback The callback function to call @@ -97,7 +101,8 @@ end -- with mod table, key and command as arguments when a key was pressed. -- @tparam[opt] table args.hook Similar to @{awful.key}. It will call a function -- for the matching modifiers + key. See @{awful.prompt.run} for details. --- @return An instance of prompt widget, inherits from `wibox.container.background`. +-- @return An instance of prompt widget, inherits from +-- `wibox.container.background`. -- @function awful.widget.prompt function widgetprompt.new(args) args = args or {} @@ -115,9 +120,12 @@ function widgetprompt.new(args) promptbox.font = args.font or nil promptbox.autoexec = args.autoexec or nil promptbox.highlighter = args.highlighter or nil - promptbox.exe_callback = args.exe_callback or function (...) promptbox:spawn_and_handle_error(...) end + promptbox.exe_callback = args.exe_callback or function (...) + promptbox:spawn_and_handle_error(...) + end promptbox.completion_callback = args.completion_callback or completion.shell - promptbox.history_path = args.history_path or gfs.get_cache_dir() .. '/history' + promptbox.history_path = args.history_path or + gfs.get_cache_dir() .. 'history' promptbox.history_max = args.history_max or nil promptbox.done_callback = args.done_callback or nil promptbox.changed_callback = args.changed_callback or nil