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

Commit

Permalink
add truncate_hide option
Browse files Browse the repository at this point in the history
  • Loading branch information
famiu committed Sep 26, 2021
1 parent 4173f99 commit b25c672
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 1 deletion.
10 changes: 10 additions & 0 deletions USAGE.md
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,16 @@ local my_component = {
}
```

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

#### Hiding 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`.

If it's set to `true` and the component doesn't have a `short_provider` value, it'll be removed entirely during truncation. If the component does have a `short_provider` value, it'll be removed only if the statusline still doesn't fit within the window even after every component with a `short_provider` is using the `short_provider`.

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:
Expand Down
20 changes: 19 additions & 1 deletion lua/feline/generator.lua
Original file line number Diff line number Diff line change
Expand Up @@ -386,12 +386,14 @@ function M.generate_statusline(winid)

-- If statusline length is larger than the window width, sort the components in ascending
-- order of priority and then truncate the components one by one using by their
-- short_provider until the statusline fits within the window
-- short_provider or hiding them entirely until the statusline fits within the window
if statusline_length > win_width then
table.sort(all_components, function(a, b)
return (a.value.priority or 0) < (b.value.priority or 0)
end)

-- If short_provider exists, use it, else hide the component if the truncate_hide
-- component value is set to true
for _, component_info in ipairs(all_components) do
if component_info.value.short_provider then
-- Get new parsed value using the short provider and calculate the length
Expand All @@ -405,10 +407,26 @@ function M.generate_statusline(winid)
statusline_length = statusline_length - length_difference
component_info.parsed_value = new_parsed_value
end
elseif component_info.value.truncate_hide then
statusline_length = statusline_length - component_info.parsed_value.len
component_info.parsed_value = {str = '', len = 0}
end

if statusline_length <= win_width then break end
end

-- If statusline still doesn't fit, start removing all components with truncate_hide
-- set to true regardless of whether they have short_provider or not
if statusline_length > win_width then
for _, component_info in ipairs(all_components) do
if component_info.value.truncate_hide then
statusline_length = statusline_length - component_info.parsed_value.len
component_info.parsed_value = {str = '', len = 0}
end

if statusline_length <= win_width then break end
end
end
end

-- Now use the section number and component number to put the components strings in their
Expand Down

0 comments on commit b25c672

Please sign in to comment.