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

Commit

Permalink
Merge pull request #240 from feline-nvim/develop
Browse files Browse the repository at this point in the history
v1.1.1
  • Loading branch information
famiu authored Mar 18, 2022
2 parents d8093d2 + b13f25e commit 1bd5158
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 18 deletions.
4 changes: 2 additions & 2 deletions USAGE.md
Original file line number Diff line number Diff line change
Expand Up @@ -204,9 +204,9 @@ Two components inside the `active` or `inactive` table cannot share the same nam

#### Truncation

Feline has an automatic smart truncation system where components can be automatically truncated if the statusline doesn't fit within the window. It can be useful if you want to make better use of screen space. It also allows you to better manage which providers are truncated, how they are truncated and in which order they are truncated.
Feline has an automatic smart truncation system where components can be automatically truncated if the statusline doesn't fit within the available space. It can be useful if you want to make better use of screen space. It also allows you to better manage which providers are truncated, how they are truncated and in which order they are truncated.

**NOTE:** Truncation currently only works with the master branch of Neovim. If you're using a stable release, truncation will not work and all configurations related to it will be silently ignored.
**NOTE:** Truncation only works on Neovim 0.6 and above. If you're using an earlier release, truncation will not work and all configurations related to it will be silently ignored.

There are a few component values associated with truncation which are described below.

Expand Down
18 changes: 9 additions & 9 deletions doc/feline.txt
Original file line number Diff line number Diff line change
Expand Up @@ -301,17 +301,17 @@ Truncation Feline has an automatic smart truncation
system where components can be
automatically truncated if the
statusline doesn’t fit within the
window. It can be useful if you want to
make better use of screen space. It also
allows you to better manage which
providers are truncated, how they are
truncated and in which order they are
truncated.
available space. It can be useful if you
want to make better use of screen space.
It also allows you to better manage
which providers are truncated, how they
are truncated and in which order they
are truncated.


**NOTE:** Truncation currently only works with the master branch of Neovim. If
you’re using a stable release, truncation will not work and all
configurations related to it will be silently ignored.
**NOTE:** Truncation only works on Neovim 0.6 and above. If you’re using an
earlier release, truncation will not work and all configurations related to it
will be silently ignored.

There are a few component values associated with truncation which are described
below.
Expand Down
28 changes: 21 additions & 7 deletions lua/feline/generator.lua
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
local bo = vim.bo
local api = vim.api
local opt = vim.opt

local feline = require('feline')
local utils = require('feline.utils')
Expand Down Expand Up @@ -345,7 +346,7 @@ local function parse_provider(provider, component, is_short, winid, section_nr,
component_nr
),
},
}, 'feline', true)
}, 'felineProviders', true)
end
end

Expand Down Expand Up @@ -545,10 +546,18 @@ function M.generate_statusline(is_active)
end
end

local window_width = api.nvim_win_get_width(0)
local maxwidth

-- If statusline width is greater than the window width, begin the truncation process
if statusline_width > window_width then
-- If statusline is global, use entire Neovim window width for maxwidth
-- Otherwise just use width of current window
if opt.laststatus:get() == 3 then
maxwidth = opt.columns:get()
else
maxwidth = api.nvim_win_get_width(0)
end

-- If statusline width is greater than maxwidth, begin the truncation process
if statusline_width > maxwidth then
-- First, sort the component indices in ascending order of the priority of the components
-- that the indices refer to
table.sort(component_indices, function(first, second)
Expand Down Expand Up @@ -594,15 +603,15 @@ function M.generate_statusline(is_active)
end
end

if statusline_width <= window_width then
if statusline_width <= maxwidth then
break
end
end
end

-- If statusline still doesn't fit within window, remove components with truncate_hide set to
-- true until it does
if statusline_width > window_width then
if statusline_width > maxwidth then
for _, indices in ipairs(component_indices) do
local section, number = indices[1], indices[2]
local component = sections[section][number]
Expand All @@ -618,7 +627,7 @@ function M.generate_statusline(is_active)
end
end

if statusline_width <= window_width then
if statusline_width <= maxwidth then
break
end
end
Expand All @@ -643,6 +652,11 @@ function M.clear_state()
provider_cache = {}
short_provider_cache = {}
provider_autocmd = {}
-- Clear provider update autocmds
if vim.fn.exists('#felineProviders') ~= 0 then
api.nvim_command('autocmd! felineProviders')
api.nvim_command('augroup! felineProviders')
end
end

return M

0 comments on commit 1bd5158

Please sign in to comment.