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
|
2014-05-20 13:02:39 +02:00
|
|
|
-- @classmod 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")
|
|
|
|
local util = require("awful.util")
|
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 {
|
|
|
|
prompt = promptbox.prompt,
|
|
|
|
textbox = promptbox.widget,
|
|
|
|
completion_callback = completion.shell,
|
|
|
|
history_path = util.get_cache_dir() .. "/history",
|
|
|
|
exe_callback = function (...)
|
|
|
|
promptbox:spawn_and_handle_error(...)
|
|
|
|
end,
|
|
|
|
}
|
2009-04-27 22:08:33 +02:00
|
|
|
end
|
|
|
|
|
2015-09-27 16:55:46 +02:00
|
|
|
local function spawn_and_handle_error(self, ...)
|
|
|
|
local result = spawn(...)
|
|
|
|
if type(result) == "string" then
|
|
|
|
self.widget:set_text(result)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2009-04-27 22:08:33 +02:00
|
|
|
--- Create a prompt widget which will launch a command.
|
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.
|
|
|
|
-- @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.
|
|
|
|
-- @return An instance of prompt widget, inherits from `wibox.container.background`.
|
2017-01-28 15:03:56 +01:00
|
|
|
-- @function 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
|
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
|