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
|
|
|
---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
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")
|
2010-10-06 14:27:16 +02:00
|
|
|
local widget_base = require("wibox.widget.base")
|
|
|
|
local textbox = require("wibox.widget.textbox")
|
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)
|
|
|
|
return prompt.run({ prompt = promptbox.prompt },
|
|
|
|
promptbox.widget,
|
2010-08-01 16:00:03 +02:00
|
|
|
function (...)
|
2015-09-27 16:55:46 +02:00
|
|
|
promptbox:spawn_and_handle_error(...)
|
2010-08-01 16:00:03 +02:00
|
|
|
end,
|
2009-04-27 22:08:33 +02:00
|
|
|
completion.shell,
|
2015-11-28 19:36:26 +01:00
|
|
|
util.get_cache_dir() .. "/history")
|
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
|
|
|
--
|
2010-10-06 14:27:16 +02:00
|
|
|
-- @param args Arguments table. "prompt" is the prompt to use.
|
2009-04-27 22:08:33 +02:00
|
|
|
-- @return A launcher widget.
|
2012-06-14 01:08:27 +02:00
|
|
|
function widgetprompt.new(args)
|
2016-02-07 15:12:22 +01:00
|
|
|
args = args or {}
|
2010-10-06 14:27:16 +02:00
|
|
|
local widget = textbox()
|
|
|
|
local promptbox = widget_base.make_widget(widget)
|
|
|
|
|
|
|
|
promptbox.widget = widget
|
|
|
|
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: "
|
|
|
|
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
|