awful: add some control with modkeys

Signed-off-by: Julien Danjou <julien@danjou.info>
This commit is contained in:
Julien Danjou 2008-06-17 16:54:46 +02:00
parent 975eba0049
commit 6d2fc20038
1 changed files with 40 additions and 17 deletions

View File

@ -474,6 +474,14 @@ local function menu(args, textbox, exe_callback)
textbox:set("text", prompt .. menu_text_with_cursor(text, inv_col, cur_col, cur_pos)) textbox:set("text", prompt .. menu_text_with_cursor(text, inv_col, cur_col, cur_pos))
keygrabber.run( keygrabber.run(
function (mod, key) function (mod, key)
local has_ctrl = false
-- Compute modifiers keys
for k, v in ipairs(mod) do
if v == "Control" then has_ctrl = true end
end
-- Get out cases
if key == "Return" then if key == "Return" then
textbox:set("text", "") textbox:set("text", "")
exe_callback(command) exe_callback(command)
@ -481,7 +489,18 @@ local function menu(args, textbox, exe_callback)
elseif key == "Escape" then elseif key == "Escape" then
textbox:set("text", "") textbox:set("text", "")
return false return false
elseif key == "BackSpace" then end
-- Control cases
if has_ctrl then
if key == "a" then
cur_pos = 1
elseif key == "e" then
cur_pos = #command + 1
end
else
-- Typin cases
if key == "BackSpace" then
command = command:sub(1, cur_pos - 2) .. command:sub(cur_pos) command = command:sub(1, cur_pos - 2) .. command:sub(cur_pos)
cur_pos = cur_pos - 1 cur_pos = cur_pos - 1
-- That's DEL -- That's DEL
@ -500,7 +519,11 @@ local function menu(args, textbox, exe_callback)
elseif cur_pos > #command + 1 then elseif cur_pos > #command + 1 then
cur_pos = #command + 1 cur_pos = #command + 1
end end
end
-- Update textbox
textbox:set("text", prompt .. menu_text_with_cursor(command, inv_col, cur_col, cur_pos)) textbox:set("text", prompt .. menu_text_with_cursor(command, inv_col, cur_col, cur_pos))
return true return true
end) end)
end end