From dc18e8722a98ef5914bb83766ea36fbc3c7def63 Mon Sep 17 00:00:00 2001 From: Famiu Haque Date: Mon, 27 Sep 2021 10:12:21 +0600 Subject: [PATCH] feat: allow customizing section gaps BREAKING CHANGE: Section gaps no longer use the default `bg` color by default, so the section gap highlights need to be specified manually. For more info, see: https://github.com/famiu/feline.nvim/blob/develop/USAGE.md#highlight-section-gaps --- USAGE.md | 31 ++++++++++++++++++++++++++++++- lua/feline/generator.lua | 2 +- 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/USAGE.md b/USAGE.md index 6cec179..ac06673 100644 --- a/USAGE.md +++ b/USAGE.md @@ -96,7 +96,7 @@ You can use component values to customize each component to your liking. Most va Feline will automatically evaluate the function if it is one. In case a function is provided, the type of the value the function returns must be the same as the type of value required by the component. For example, since [`enabled`](#conditionally-enable-components) requires a boolean value, if you set it to a function, the function must also return a boolean value. -Note that you can omit all of the component values except `provider`, in which case the defaults would be used instead. The different kinds of component values are discussed below. +Note that you can omit all of the component values, in which case the defaults would be used instead. The different kinds of component values are discussed below. #### Component providers @@ -167,6 +167,8 @@ provider = function(_, _, opts) end ``` +If you omit the provider value, it will be set to an empty string. A component with no provider or an empty provider may be useful for things like [applying a highlight to section gaps](#highlight-section-gaps) or just having an icon or separator as a component. + #### Conditionally enable components The `enabled` value of a component can be a boolean or function. This value determines if the component is enabled or not. If false, the component is not shown in the statusline. If it's a function, it can take either the window handler as an argument, or it can take no arguments. For example: @@ -638,6 +640,33 @@ require('feline').reset_highlights() And then Feline will automatically regenerate those highlights when it needs them, so you don't have to worry about setting the highlights yourself. +### Highlight section gaps + +By default, gaps between two sections inherit the highlight of the last element of the section. If you wish to customize the highlight of the gap between two sections, you can just add a component with only an `hl` value to the end of the first section. + +For example, if you had two sections in the active statusline and wanted the gap between the first and second section to use a certain background color, you could do this: + +```lua +components.active[1] = { + { + -- Insert all components of first section here + + -- Component for customizing highlight for the gap between section 1 and 2 + { + hl = { + -- Replace 'oceanblue' with whatever color you want the gap to be. + bg = 'oceanblue' + } + } + }, + { + -- Insert all components of second section here + } +} +``` + +It's even simpler if you want to use the default `bg` color for the gap between sections. In that case, you can just put an empty component at the end of the first section. You don't even have the define the `hl` manually since `hl` by default uses the default `bg` as its background. + ### Thin line for horizontal splits If you want, you can have a thin line instead of the inactive statusline to separate your windows, like the vertical window split separator, except in this case it would act as a horizontal window separator of sorts. You can do this through: diff --git a/lua/feline/generator.lua b/lua/feline/generator.lua index 99d72db..4dc652d 100644 --- a/lua/feline/generator.lua +++ b/lua/feline/generator.lua @@ -338,7 +338,7 @@ function M.generate_statusline(winid) sections[#sections+1] = parse_statusline_section(section, winid, statusline_type, i) end - statusline_str = table.concat(sections, string.format('%%#%s#%%=', defhl())) + statusline_str = table.concat(sections, '%=') end end