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