2009-04-27 22:08:33 +02:00
|
|
|
---------------------------------------------------------------------------
|
|
|
|
-- @author Julien Danjou <julien@danjou.info>
|
|
|
|
-- @copyright 2009 Julien Danjou
|
|
|
|
-- @release @AWESOME_VERSION@
|
|
|
|
---------------------------------------------------------------------------
|
|
|
|
|
|
|
|
local setmetatable = setmetatable
|
|
|
|
|
|
|
|
local completion = require("awful.completion")
|
|
|
|
local util = require("awful.util")
|
|
|
|
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
|
|
|
|
|
|
|
module("awful.widget.prompt")
|
|
|
|
|
|
|
|
--- Run method for promptbox.
|
|
|
|
-- @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 (...)
|
|
|
|
local result = util.spawn(...)
|
|
|
|
if type(result) == "string" then
|
2010-10-14 21:17:02 +02:00
|
|
|
promptbox.widget:set_text(result)
|
2010-08-01 16:00:03 +02:00
|
|
|
end
|
|
|
|
end,
|
2009-04-27 22:08:33 +02:00
|
|
|
completion.shell,
|
|
|
|
util.getdir("cache") .. "/history")
|
|
|
|
end
|
|
|
|
|
|
|
|
--- Create a prompt widget which will launch a command.
|
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.
|
|
|
|
function new(args)
|
|
|
|
local 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
|
|
|
|
promptbox.prompt = args.prompt or "Run: "
|
|
|
|
return promptbox
|
|
|
|
end
|
|
|
|
|
2009-05-25 11:14:08 +02:00
|
|
|
setmetatable(_M, { __call = function (_, ...) return new(...) end })
|
2009-04-27 22:08:33 +02:00
|
|
|
|
|
|
|
-- vim: filetype=lua:expandtab:shiftwidth=4:tabstop=8:softtabstop=4:encoding=utf-8:textwidth=80
|