From 4c031ba398db963a196e03d2d5d22fd7e819a215 Mon Sep 17 00:00:00 2001 From: koniu Date: Wed, 19 Nov 2008 12:40:13 +0000 Subject: [PATCH] awful.prompt: add trail space in prompt_text_with_cursor() Adds a trailing space after text if cursor position < text length to prevent width of the widget changing particularly useful when using 'text' and 'selectall' to do eg. in-place renaming. Sample textbox content (# space, _ cursor). Before: textbox before prompt: #term# selectall prompt textbox : #_erm <- shorter than other cases after pressing end : #term_ After: textbox before prompt: #term# selectall prompt textbox : #_erm# after pressing end : #term_ Signed-off-by: koniu --- lib/awful/prompt.lua.in | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/awful/prompt.lua.in b/lib/awful/prompt.lua.in index 6d3bb279..880f9e10 100644 --- a/lib/awful/prompt.lua.in +++ b/lib/awful/prompt.lua.in @@ -107,17 +107,19 @@ end -- @param cursor_pos The cursor position. -- @param cursor_pos The cursor underline style. local function prompt_text_with_cursor(text, text_color, cursor_color, cursor_pos, cursor_ul) - local char + local char, spacer if not text then text = "" end if #text < cursor_pos then char = " " + spacer = "" else char = util.escape(text:sub(cursor_pos, cursor_pos)) + spacer = " " end local underline = cursor_ul or "none" local text_start = util.escape(text:sub(1, cursor_pos - 1)) local text_end = util.escape(text:sub(cursor_pos + 1)) - return text_start .. "" .. char .. "" .. text_end + return text_start .. "" .. char .. "" .. text_end .. spacer end --- Run a prompt in a box.