diff --git a/README.md b/README.md index 8e40eab..4475f60 100644 --- a/README.md +++ b/README.md @@ -133,7 +133,10 @@ require("dressing").setup({ enabled = true, -- Default prompt string - default_prompt = "Input:", + default_prompt = "Input", + + -- Trim trailing `:` from prompt + trim_prompt = true, -- Can be 'left', 'right', or 'center' title_pos = "left", diff --git a/lua/dressing/config.lua b/lua/dressing/config.lua index 655c0fb..d4afe69 100644 --- a/lua/dressing/config.lua +++ b/lua/dressing/config.lua @@ -4,7 +4,10 @@ local default_config = { enabled = true, -- Default prompt string - default_prompt = "Input:", + default_prompt = "Input", + + -- Trim trailing `:` from prompt + trim_prompt = true, -- Can be 'left', 'right', or 'center' title_pos = "left", diff --git a/lua/dressing/input.lua b/lua/dressing/input.lua index bbc3cd1..2e8fc81 100644 --- a/lua/dressing/input.lua +++ b/lua/dressing/input.lua @@ -251,6 +251,17 @@ local function get_max_strwidth(lines) return max end +---@param title string +---@param trim_colon boolean input.trim_prompt config +---@return string +local function trim_and_pad_title(title, trim_colon) + title = vim.trim(title) + if trim_colon then + title = title:gsub(":$", "") + end + return (" %s "):format(title) +end + ---@param config table ---@param prompt_lines string[] ---@param default? string @@ -308,7 +319,7 @@ local function create_or_update_win(config, prompt_lines, default) end end if vim.fn.has("nvim-0.9") == 1 and #prompt_lines == 1 then - winopt.title = prompt_lines[1]:gsub("^%s*(.-)%s*$", " %1 ") + winopt.title = trim_and_pad_title(prompt_lines[1], config.trim_prompt) -- We used to use "prompt_align" here winopt.title_pos = config.prompt_align or config.title_pos end @@ -440,7 +451,7 @@ local function show_input(opts, on_confirm) if vim.fn.has("nvim-0.9") == 0 and #prompt_lines == 1 then util.add_title_to_win( winid, - string.gsub(prompt_lines[1], "^%s*(.-)%s*$", "%1"), + trim_and_pad_title(prompt_lines[1], config.trim_prompt), { align = config.prompt_align } ) end