awful: add eval() and more check in menu
Signed-off-by: Julien Danjou <julien@danjou.info>
This commit is contained in:
parent
45d8e16afb
commit
124c650929
12
awful.lua
12
awful.lua
|
@ -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
|
||||||
|
|
Loading…
Reference in New Issue