From 1edaef82477d4580fde2a35db999f219b8a412ba Mon Sep 17 00:00:00 2001 From: Julien Danjou Date: Wed, 18 Jun 2008 13:00:11 +0200 Subject: [PATCH] awful: support completion callback Signed-off-by: Julien Danjou --- awful.lua | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/awful.lua b/awful.lua index f026aa3c..510ffd7d 100644 --- a/awful.lua +++ b/awful.lua @@ -461,13 +461,16 @@ local function menu_text_with_cursor(text, text_color, cursor_color, cursor_pos) return text_start .. "" .. char .. "" .. text_end end -local function menu(args, textbox, exe_callback) +local function menu(args, textbox, exe_callback, completion_callback) if not args then return end local command = "" local prompt = args.prompt or "" local inv_col = args.cursor_fg or "black" local cur_col = args.cursor_bg or "white" + -- The cursor position local cur_pos = 1 + -- The completion element to use on completion request. + local ncomp = 1 if not textbox or not exe_callback then return end @@ -506,6 +509,16 @@ local function menu(args, textbox, exe_callback) cur_pos = #command + 1 end else + if completion_callback then + -- That's tab + if key:byte() == 9 then + command, cur_pos = completion_callback(command, cur_pos, ncomp) + ncomp = ncomp + 1 + else + ncomp = 1 + end + end + -- Typin cases if key == "BackSpace" then if cur_pos > 1 then