Skip to content
This repository was archived by the owner on Sep 20, 2023. It is now read-only.

feat: add smart component truncation #110

Merged
merged 2 commits into from
Sep 28, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
56 changes: 56 additions & 0 deletions USAGE.md
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,62 @@ 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.

#### Component short provider

Feline has an automatic smart truncation system where components can be automatically truncated if the statusline doesn't fit within the window. In order to make use of this truncation system, you have to define the `short_provider` component value.

`short_provider` works just like the `provider` value, but is activated only when the component is being truncated due to the statusline not fitting within the window. `short_provider` is independent from the `provider` value so it can be a different provider altogether, or it can be a shortened version of the same provider or the same provider but with a different `opts` value. For example:

```lua
-- In this component, short provider uses same provider but with different opts
local file_info_component = {
provider = {
name = 'file_info',
opts = {
type = 'full-path'
}
},
short_provider = {
name = 'file_info',
opts = {
type = 'short-path'
}
}
}

-- Short provider can also be an independent value / function
local my_component = {
provider = 'loooooooooooooooong',
short_provider = 'short'
}
```

Feline doesn't set `short_provider` to any component by default, so it must be provided manually.

#### Hide components during truncation

If you wish to allow Feline to hide a component entirely if necessary during truncation, you may set the `truncate_hide` component value to `true`. By default, `truncate_hide` is `false` for every component.

#### Component priority

When components are being truncated by Feline, you can choose to give some components a higher priority over the other components. The `priority` component value just takes a number. By default, the priority of a component is `0`. Components are truncated in ascending order of priority. So components with lower priority are truncated first, while components with higher priority are truncated later on. For example:

```lua
-- This component has the default priority
local my_component = {
provider = 'loooooooooooooooong',
short_provider = 'short'
}
-- This component has a higher priority, so it will be truncated after the previous component
local high_priority_component = {
provider = 'long provider with high priority',
short_provider = 'short',
priority = 1
}
```

Priority can also be set to a negative number, which can be used to make a component be truncated earlier than the ones with default priority.

#### 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:
Expand Down
Loading