2009-04-27 22:08:33 +02:00
|
|
|
---------------------------------------------------------------------------
|
2017-01-22 19:13:50 +01:00
|
|
|
-- The widget version of `awful.prompt`.
|
|
|
|
--
|
|
|
|
-- @DOC_wibox_awidget_defaults_prompt_EXAMPLE@
|
|
|
|
--
|
2009-04-27 22:08:33 +02:00
|
|
|
-- @author Julien Danjou <julien@danjou.info>
|
|
|
|
-- @copyright 2009 Julien Danjou
|
2018-10-31 09:00:18 +01:00
|
|
|
-- @copyright 2018 Aire-One
|
2019-06-06 08:15:53 +02:00
|
|
|
-- @widgetmod awful.widget.prompt
|
2009-04-27 22:08:33 +02:00
|
|
|
---------------------------------------------------------------------------
|
|
|
|
|
2017-01-22 19:13:50 +01:00
|
|
|
--- The prompt foreground color.
|
|
|
|
-- @beautiful beautiful.prompt_fg
|
|
|
|
-- @param color
|
|
|
|
-- @see gears.color
|
|
|
|
|
|
|
|
--- The prompt background color.
|
|
|
|
-- @beautiful beautiful.prompt_bg
|
|
|
|
-- @param color
|
|
|
|
-- @see gears.color
|
|
|
|
|
2009-04-27 22:08:33 +02:00
|
|
|
local setmetatable = setmetatable
|
|
|
|
|
|
|
|
local completion = require("awful.completion")
|
2017-02-14 00:16:45 +01:00
|
|
|
local gfs = require("gears.filesystem")
|
2015-09-30 00:05:56 +02:00
|
|
|
local spawn = require("awful.spawn")
|
2009-04-27 22:08:33 +02:00
|
|
|
local prompt = require("awful.prompt")
|
2017-01-22 19:13:50 +01:00
|
|
|
local beautiful = require("beautiful")
|
2010-10-06 14:27:16 +02:00
|
|
|
local textbox = require("wibox.widget.textbox")
|
2017-01-22 19:13:50 +01:00
|
|
|
local background = require("wibox.container.background")
|
2010-08-01 16:00:03 +02:00
|
|
|
local type = type
|
2009-04-27 22:08:33 +02:00
|
|
|
|
2012-06-14 01:08:27 +02:00
|
|
|
local widgetprompt = { mt = {} }
|
2009-04-27 22:08:33 +02:00
|
|
|
|
|
|
|
--- Run method for promptbox.
|
2014-05-20 13:02:39 +02:00
|
|
|
--
|
2009-04-27 22:08:33 +02:00
|
|
|
-- @param promptbox The promptbox to run.
|
|
|
|
local function run(promptbox)
|
2016-10-12 00:20:42 +02:00
|
|
|
return prompt.run {
|
2018-10-31 11:42:36 +01:00
|
|
|
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,
|
2018-10-31 11:35:56 +01:00
|
|
|
keyreleased_callback = promptbox.keyreleased_callback,
|
2018-10-31 11:42:36 +01:00
|
|
|
hook = promptbox.hook
|
2016-10-12 00:20:42 +02:00
|
|
|
}
|
2009-04-27 22:08:33 +02:00
|
|
|
end
|
|
|
|
|
2015-09-27 16:55:46 +02:00
|
|
|
local function spawn_and_handle_error(self, ...)
|
2018-12-31 21:38:14 +01:00
|
|
|
local f = self.with_shell and spawn.with_shell or spawn
|
|
|
|
local result = f(...)
|
2015-09-27 16:55:46 +02:00
|
|
|
if type(result) == "string" then
|
|
|
|
self.widget:set_text(result)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-12-31 21:38:14 +01:00
|
|
|
--- Always spawn using a shell.
|
|
|
|
--
|
|
|
|
-- When using the default `exe_callback`, use `awful.spawn.with_shell` instead
|
|
|
|
-- of `awful.spawn`. Depending on the ammount of customization to your shell
|
|
|
|
-- environment, this can increase startup time.
|
|
|
|
-- @property with_shell
|
|
|
|
-- @param[opt=false] boolean
|
|
|
|
|
2009-04-27 22:08:33 +02:00
|
|
|
--- Create a prompt widget which will launch a command.
|
2018-10-31 11:35:56 +01:00
|
|
|
-- For additional documentation about `args` parameter, please refer to
|
|
|
|
-- @{awful.prompt} and @{awful.prompt.run}.
|
2014-05-20 13:02:39 +02:00
|
|
|
--
|
2017-02-11 21:43:07 +01:00
|
|
|
-- @tparam table args Prompt arguments.
|
|
|
|
-- @tparam[opt="Run: "] string args.prompt Prompt text.
|
2018-10-31 11:42:36 +01:00
|
|
|
-- @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.
|
2018-10-31 11:35:56 +01:00
|
|
|
-- @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
|
2018-10-31 11:42:36 +01:00
|
|
|
-- command as argument when finished.
|
2018-12-31 21:38:14 +01:00
|
|
|
-- @tparam[opt=false] boolean args.with_shell Use a (terminal) shell to execute this.
|
2018-04-04 20:43:36 +02:00
|
|
|
-- @tparam[opt=`awful.completion.shell`] function args.completion_callback
|
2018-10-31 11:42:36 +01:00
|
|
|
-- The callback function to call to get completion. See @{awful.prompt.run}
|
|
|
|
-- for details.
|
2018-10-31 11:35:56 +01:00
|
|
|
-- @tparam[opt=`gears.filesystem.get_cache_dir() .. '/history'`] string
|
|
|
|
-- args.history_path File path where the history should be saved.
|
2018-10-31 11:42:36 +01:00
|
|
|
-- @tparam[opt=50] integer args.history_max Set the maximum entries in
|
|
|
|
-- history file.
|
2018-10-31 09:00:18 +01:00
|
|
|
-- @tparam[opt] function args.done_callback
|
2018-10-31 11:42:36 +01:00
|
|
|
-- The callback function to always call without arguments, regardless of
|
|
|
|
-- whether the prompt was cancelled. See @{awful.prompt.run} for details.
|
2018-10-31 11:35:56 +01:00
|
|
|
-- @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.
|
2018-10-31 11:42:36 +01:00
|
|
|
-- @return An instance of prompt widget, inherits from
|
|
|
|
-- `wibox.container.background`.
|
2019-06-07 20:59:34 +02:00
|
|
|
-- @constructorfct awful.widget.prompt
|
2012-06-14 01:08:27 +02:00
|
|
|
function widgetprompt.new(args)
|
2016-02-07 15:12:22 +01:00
|
|
|
args = args or {}
|
2017-01-22 19:13:50 +01:00
|
|
|
local promptbox = background()
|
2017-02-11 21:43:07 +01:00
|
|
|
promptbox.widget = textbox()
|
2010-10-06 14:27:16 +02:00
|
|
|
promptbox.widget:set_ellipsize("start")
|
2009-04-27 22:08:33 +02:00
|
|
|
promptbox.run = run
|
2015-09-27 16:55:46 +02:00
|
|
|
promptbox.spawn_and_handle_error = spawn_and_handle_error
|
2009-04-27 22:08:33 +02:00
|
|
|
promptbox.prompt = args.prompt or "Run: "
|
2017-02-11 21:43:07 +01:00
|
|
|
promptbox.fg = args.fg or beautiful.prompt_fg or beautiful.fg_normal
|
|
|
|
promptbox.bg = args.bg or beautiful.prompt_bg or beautiful.bg_normal
|
2018-10-31 11:35:56 +01:00
|
|
|
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
|
2018-10-31 11:42:36 +01:00
|
|
|
promptbox.exe_callback = args.exe_callback or function (...)
|
|
|
|
promptbox:spawn_and_handle_error(...)
|
|
|
|
end
|
2018-04-04 20:43:36 +02:00
|
|
|
promptbox.completion_callback = args.completion_callback or completion.shell
|
2018-10-31 11:42:36 +01:00
|
|
|
promptbox.history_path = args.history_path or
|
|
|
|
gfs.get_cache_dir() .. 'history'
|
2018-10-31 11:35:56 +01:00
|
|
|
promptbox.history_max = args.history_max or nil
|
2018-10-31 09:00:18 +01:00
|
|
|
promptbox.done_callback = args.done_callback or nil
|
2018-10-31 11:35:56 +01:00
|
|
|
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
|
2009-04-27 22:08:33 +02:00
|
|
|
return promptbox
|
|
|
|
end
|
|
|
|
|
2012-06-14 01:08:27 +02:00
|
|
|
function widgetprompt.mt:__call(...)
|
|
|
|
return widgetprompt.new(...)
|
|
|
|
end
|
|
|
|
|
|
|
|
return setmetatable(widgetprompt, widgetprompt.mt)
|
2009-04-27 22:08:33 +02:00
|
|
|
|
2011-09-11 16:50:01 +02:00
|
|
|
-- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:textwidth=80
|