awful: add eval() and more check in menu

Signed-off-by: Julien Danjou <julien@danjou.info>
This commit is contained in:
Julien Danjou 2008-06-13 17:51:28 +02:00
parent 45d8e16afb
commit 124c650929
1 changed files with 11 additions and 1 deletions

View File

@ -15,6 +15,8 @@ else
end
-- Grab environment we need
local assert = assert
local loadstring = loadstring
local ipairs = ipairs
local pairs = pairs
local unpack = unpack
@ -441,15 +443,22 @@ local function spawn(cmd)
return os.execute(cmd .. "&")
end
local function eval(cmd)
assert(loadstring(cmd))()
end
local function menu(p, textbox, exe_callback)
local command = ""
local prompt = p or ""
if not textbox or not exe_callback then
return
end
textbox:set("text", prompt)
keygrabber.run(
function (mod, key)
if key == "Return" then
exe_callback(command)
textbox:set("text", "")
exe_callback(command)
return false
elseif key == "Escape" then
textbox:set("text", "")
@ -529,5 +538,6 @@ P.layout =
P.spawn = spawn
P.menu = menu
P.escape = escape
P.eval = eval
return P