-
Notifications
You must be signed in to change notification settings - Fork 20
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
Custom highlight groups #69
Comments
The idea is to define highlight groups(boundaries) together with actual line formatting. ---@class BufferList
---@field items {
--- id: string,
--- name: string,
--- is_dir: boolean,
--- basename: string,
--- dirname: string,
--- anchor: string,
--- formatted_name: string, -- pad basename
--- icon: {
--- symbol: string,
--- hlgroup: string,
--- },
---}[]
local BufferList = {
items = {},
}
-- other methods
-- ....
function BufferList:format_lines()
for _, buffer in pairs(self.items) do
---@type {text: string, hlgroup: string}[]
local format = {
{ text = buffer.anchor, hlgroup = highlight_groups.anchor.name },
{ text = buffer.icon.symbol, hlgroup = buffer.icon.hlgroup },
{ text = buffer.formatted_name, hlgroup = highlight_groups.filename.name },
{ text = buffer.dirname, hlgroup = highlight_groups.dirname.name },
}
local delimeter = " "
local line_text = pluck("text", format)
local line = table.concat(line_text, delimeter)
---@type {first: integer, last: integer, hlgroup: string}[]
local highlights = {}
for i = 1, #format do
local first = 0
if i >= 2 then
first = highlights[i - 1].last + #delimeter
end
highlights[i] = {
first = first,
last = first + #format[i].text,
hlgroup = format[i].hlgroup,
}
end
buffer.line = line
buffer.highlights = highlights
end
end This is just a quick and dirty approach, to make things work, but hope you get the idea. |
Would be great to have custom highlight groups for faster and easier identification of target.
Something like this:
I've made a small proof of concept. If you're interested I can share how I approached it.
The text was updated successfully, but these errors were encountered: