Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

telescope results line color / highlight #3117

Open
sand4rt opened this issue May 18, 2024 · 5 comments · May be fixed by #3139
Open

telescope results line color / highlight #3117

sand4rt opened this issue May 18, 2024 · 5 comments · May be fixed by #3139
Labels
enhancement Enhancement to performance, inner workings or existent features good first issue Good for newcomers

Comments

@sand4rt
Copy link

sand4rt commented May 18, 2024

Is your feature request related to a problem? Please describe.
The ability to change the color of the line next to the line numbers (the red one in the screenshot) without effecting the normal text.

Describe the solution you'd like
A new highlight group to change the color.

Describe alternatives you've considered
I changed TelescopeResultsNormal, but that also affects other text.

Additional context
Screenshot 2024-05-18 at 20 39 49

@sand4rt sand4rt added the enhancement Enhancement to performance, inner workings or existent features label May 18, 2024
@jamestrew jamestrew added the good first issue Good for newcomers label May 23, 2024
@jamestrew
Copy link
Contributor

jamestrew commented May 23, 2024

There technically is a separator_hl option deep inside the results entry creation mechanism that you could take advantage of but it's pretty inaccessible at the moment and none of the builtin pickers utilize it so I'm an agreement that it's probably better to just have a hl group for the separator.

But this is pretty low priority for me personally. If someone wants to have a go at it, I'd be willing to offer some help.

@MovieMaker93
Copy link
Contributor

MovieMaker93 commented May 23, 2024

@jamestrew, do you mean this piece of code?:
image
By creating a new hl_group, do you mean to make it and add it as default like the others?
Also, how did you configure the line next to the number? By default, I have only the line number and not the separator @sand4rt

@jamestrew
Copy link
Contributor

@MovieMaker93 that's right.

function make_entry.gen_from_buffer_lines(opts)
local displayer = entry_display.create {
separator = "",
items = {
{ width = 5 },
{ remaining = true },
},
}

We could technically make current_buffer_fuzzy_find and other pickers using entry_display take a separator_hl option but I feel like just adding a new hl group, something like TelescopeResultsSeparator would be a cleaner way.

@MovieMaker93
Copy link
Contributor

@MovieMaker93 that's right.

function make_entry.gen_from_buffer_lines(opts)
local displayer = entry_display.create {
separator = "",
items = {
{ width = 5 },
{ remaining = true },
},
}

We could technically make current_buffer_fuzzy_find and other pickers using entry_display take a separator_hl option, but I feel like just adding a new hl group, something like TelescopeResultsSeparator would be a cleaner way.

Thanks for the answer. I'm trying to understand how the highlighters work for the pickers, but I haven't fully grasped it yet.
I've added the new hlgroup here:

local popup_opts = picker:get_window_options(vim.o.columns, line_count)
-- `popup.nvim` massaging so people don't have to remember minheight shenanigans
popup_opts.results.focusable = true
popup_opts.results.minheight = popup_opts.results.height
popup_opts.results.highlight = "TelescopeResultsNormal"
popup_opts.results.borderhighlight = "TelescopeResultsBorder"
popup_opts.results.titlehighlight = "TelescopeResultsTitle"
popup_opts.prompt.minheight = popup_opts.prompt.height
popup_opts.prompt.highlight = "TelescopePromptNormal"
popup_opts.prompt.borderhighlight = "TelescopePromptBorder"
popup_opts.prompt.titlehighlight = "TelescopePromptTitle"

image
and as default here:
-- "Normal" in the floating windows created by telescope.
TelescopeNormal = { default = true, link = "Normal" },
TelescopePreviewNormal = { default = true, link = "TelescopeNormal" },
TelescopePromptNormal = { default = true, link = "TelescopeNormal" },
TelescopeResultsNormal = { default = true, link = "TelescopeNormal" },

image
However, I don't know where to specify this hlgroup option. I didn't understand where the popup_opts has been defined or how to define the new hlgroup besides the one place specified above.
Could you guide me further on how to do it?

@jamestrew
Copy link
Contributor

On second thought, maybe TelescopeResultsEntrySeparator might be clearer.

However, I don't know where to specify this hlgroup option.

I think you could just do something like

configuration.separator_hl = vim.F.if_nil(configuration.separator_hl, "TelescopeResultsEntrySeparator")

at the top of the entry_display.create function. This should add the highlight group to a table of highlights for the entry.
The actual setting of the entry highlights happens closer to here:

local display, display_highlights = entry_display.resolve(self, entry)
if not display then
log.info("Weird entry", entry)
return
end
-- 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
local prefix = self.entry_prefix
display = prefix .. display
self:_increment "displayed"
local offset = insert and 0 or 1
if not vim.api.nvim_buf_is_valid(self.results_bufnr) then
log.debug "ON_ENTRY: Invalid buffer"
return
end
-- TODO: Does this every get called?
-- local line_count = vim.api.nvim_win_get_height(self.results_win)
local line_count = vim.api.nvim_buf_line_count(self.results_bufnr)
if row > line_count then
return
end
if insert then
if self.sorting_strategy == "descending" then
vim.api.nvim_buf_set_lines(self.results_bufnr, 0, 1, false, {})
end
end
local set_ok, msg = pcall(vim.api.nvim_buf_set_lines, self.results_bufnr, row, row + offset, false, { display })
if set_ok then
if display_highlights then
self.highlighter:hi_display(row, prefix, display_highlights)

The hi_display function will loop over the table of highlights and call nvim_buf_add_highlight

@MovieMaker93 MovieMaker93 linked a pull request May 26, 2024 that will close this issue
4 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement Enhancement to performance, inner workings or existent features good first issue Good for newcomers
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants