From 6af6b4e5fd7de7ce4b6791cc8093783f1af3bd58 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alvaro=20Mu=C3=B1oz?= Date: Thu, 8 Oct 2020 19:34:59 +0200 Subject: [PATCH] feat: prompt_prefix option (#154) * enable prompt_prefix option * add hl and default value * default hl and prefix * fixup: move the redraw til after prompt create * fixup: nits Co-authored-by: TJ DeVries --- lua/telescope/config.lua | 2 ++ lua/telescope/pickers.lua | 25 +++++++++++++------------ plugin/telescope.vim | 2 ++ 3 files changed, 17 insertions(+), 12 deletions(-) diff --git a/lua/telescope/config.lua b/lua/telescope/config.lua index 5ef0b42..1891327 100644 --- a/lua/telescope/config.lua +++ b/lua/telescope/config.lua @@ -46,6 +46,8 @@ function config.set_defaults(defaults) set("results_height", 1) set("results_width", 0.8) + set("prompt_prefix", " > ") + set("border", {}) set("borderchars", { '─', '│', '─', '│', '╭', '╮', '╯', '╰'}) diff --git a/lua/telescope/pickers.lua b/lua/telescope/pickers.lua index eec61a0..6efd749 100644 --- a/lua/telescope/pickers.lua +++ b/lua/telescope/pickers.lua @@ -39,6 +39,7 @@ end local ns_telescope_selection = a.nvim_create_namespace('telescope_selection') local ns_telescope_matching = a.nvim_create_namespace('telescope_matching') local ns_telescope_prompt = a.nvim_create_namespace('telescope_prompt') +local ns_telescope_prompt_prefix = a.nvim_create_namespace('telescope_prompt_prefix') local pickers = {} @@ -64,6 +65,8 @@ function Picker:new(opts) results_title = get_default(opts.results_title, "Results"), preview_title = get_default(opts.preview_title, "Preview"), + prompt_prefix = get_default(opts.prompt_prefix, config.values.prompt_prefix), + default_text = opts.default_text, get_status_text = get_default(opts.get_status_text, config.values.get_status_text), @@ -326,18 +329,20 @@ function Picker:find() local prompt_border_win = prompt_opts.border and prompt_opts.border.win_id if prompt_border_win then vim.api.nvim_win_set_option(prompt_border_win, 'winhl', 'Normal:TelescopePromptBorder') end - -- Draw the screen ASAP. This makes things feel speedier. - vim.cmd [[redraw]] - - local prompt_prefix - if false then - prompt_prefix = " > " + -- Prompt prefix + local prompt_prefix = self.prompt_prefix + if prompt_prefix ~= '' then + if not vim.endswith(prompt_prefix, ' ') then + prompt_prefix = prompt_prefix.." " + end a.nvim_buf_set_option(prompt_bufnr, 'buftype', 'prompt') vim.fn.prompt_setprompt(prompt_bufnr, prompt_prefix) - else - prompt_prefix = "" + a.nvim_buf_add_highlight(prompt_bufnr, ns_telescope_prompt_prefix, 'TelescopePromptPrefix', 0, 0, #prompt_prefix) end + -- Draw the screen ASAP. This makes things feel speedier. + vim.cmd [[redraw]] + -- First thing we want to do is set all the lines to blank. self.max_results = popup_opts.results.height @@ -425,11 +430,7 @@ function Picker:find() end local process_complete = function() - -- prompt_prefix = " hello > " - -- vim.fn.prompt_setprompt(prompt_bufnr, prompt_prefix) - -- TODO: We should either: always leave one result or make sure we actually clean up the results when nothing matches - if selection_strategy == 'row' then self:set_selection(self:get_selection_row()) elseif selection_strategy == 'follow' then diff --git a/plugin/telescope.vim b/plugin/telescope.vim index 3fbc8dd..7a8fa9b 100644 --- a/plugin/telescope.vim +++ b/plugin/telescope.vim @@ -18,6 +18,8 @@ highlight default link TelescopePreviewBorder TelescopeBorder " Used for highlighting characters that you match. highlight default link TelescopeMatching NormalNC +" Used for the prompt prefix +highlight default link TelescopePromptPrefix Identifier " This is like "" in your terminal. " To use it, do `cmap (TelescopeFuzzyCommandSearch)