diff options
| author | TJ DeVries <devries.timothyj@gmail.com> | 2020-10-24 22:55:45 -0400 |
|---|---|---|
| committer | TJ DeVries <devries.timothyj@gmail.com> | 2020-10-24 22:55:45 -0400 |
| commit | a8e780708698a431621a3556a802ca44031d64fd (patch) | |
| tree | 3a5652fab330f4afacba89007f54c12e4f988cfa /lua/telescope/pickers.lua | |
| parent | 7eda4e80f9fa0b16b2030e81528f17bdaf118041 (diff) | |
feat: Use colors from nvim-devicons
Diffstat (limited to 'lua/telescope/pickers.lua')
| -rw-r--r-- | lua/telescope/pickers.lua | 17 |
1 files changed, 10 insertions, 7 deletions
diff --git a/lua/telescope/pickers.lua b/lua/telescope/pickers.lua index 30780d1..935f6cf 100644 --- a/lua/telescope/pickers.lua +++ b/lua/telescope/pickers.lua @@ -37,6 +37,7 @@ local extend = function(opts, defaults) end local ns_telescope_selection = a.nvim_create_namespace('telescope_selection') +local ns_telescope_entry = a.nvim_create_namespace('telescope_entry') 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') @@ -772,10 +773,10 @@ function Picker:entry_adder(index, entry, score) return end - local display + local display, display_highlights if type(entry.display) == 'function' then self:_increment("display_fn") - display = entry:display() + display, display_highlights = entry:display() elseif type(entry.display) == 'string' then display = entry.display else @@ -786,11 +787,8 @@ function Picker:entry_adder(index, entry, score) -- This is the two spaces to manage the '> ' stuff. -- Maybe someday we can use extmarks or floaty text or something to draw this and not insert here. -- until then, insert two spaces - if TELESCOPE_DEBUG then - display = ' ' .. score .. display - else - display = ' ' .. display - end + local prefix = TELESCOPE_DEBUG and (' ' .. score) or ' ' + display = prefix .. display self:_increment("displayed") @@ -803,6 +801,11 @@ function Picker:entry_adder(index, entry, score) local set_ok = pcall(vim.api.nvim_buf_set_lines, self.results_bufnr, row, row + 1, false, {display}) + if set_ok and display_highlights then + for _, hl_block in ipairs(display_highlights) do + a.nvim_buf_add_highlight(self.results_bufnr, ns_telescope_entry, hl_block[2], row, #prefix + hl_block[1][1], #prefix + hl_block[1][2]) + end + end -- This pretty much only fails when people leave newlines in their results. -- So we'll clean it up for them if it fails. |
