diff --git a/USAGE.md b/USAGE.md
index 2a311c4..cabbdcf 100644
--- a/USAGE.md
+++ b/USAGE.md
@@ -92,11 +92,11 @@ components.active[3][2] = {
### Component values
-You can use component values to customize each component to your liking. Most values that a component requires can also use a function. These functions can take either no arguments or exactly one argument, the window id (`winid`) of the window for which the statusline is being generated. However, the [`provider`](#component-providers) value is an exception because it can take more than one argument (more on that below).
+You can use component values to customize each component to your liking. Providing the values isn't necessary and you can omit all of the component values, in which case the defaults would be used instead. The component values can either be set to a fixed value or a function that generates the value everytime the statusline is being generated.
-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.
+Though you should keep in mind that if a component value is set to a function, the function can take no arguments. The [`provider`](#component-providers) value is an exception to this rule (more on that below). The return type of the function must also 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, in which case the defaults would be used instead. The different kinds of component values are discussed below.
+The different kinds of component values are discussed below.
#### Component providers
@@ -129,7 +129,7 @@ provider = {
Note that you can also use your [manually added providers](#setup-function) the same way as the default providers.
-The value of `provider` can also be set to a function. The function must return a string when called. The function may also optionally return an [`icon`](#component-icon) value alongside the string, which would represent the provider's default icon. The provider functions can take up to three arguments: `winid`, which is the window handler, `component`, which represents the component itself and can be used to access the component values from within the provider, and `opts`, which represents the provider options discussed above.
+The value of `provider` can also be set to a function. The function must return a string when called. The function may also optionally return an [`icon`](#component-icon) value alongside the string, which would represent the provider's default icon. The provider functions can take two arguments: `component`, which represents the component itself and can be used to access the component values from within the provider, and `opts`, which represents the provider options discussed above.
Here are a few examples of setting the provider to a function:
@@ -139,14 +139,9 @@ provider = function()
return tostring(#vim.api.nvim_list_wins())
end
--- Provider functions can take the window handler as the first argument
-provider = function(winid)
- return tostring(vim.api.nvim_win_get_buf(winid))
-end
-
--- Providers can also take the component itself as an argument to access the component values
--- using the second argument passed to the provider function
-provider = function(_, component)
+-- Providers can take the component itself as an argument to access the component values using the
+-- first argument passed to the provider function
+provider = function(component)
if component.icon then
return component.icon
else
@@ -155,10 +150,10 @@ provider = function(_, component)
end
```
-Functions that are added as [custom providers](#setup-function) can also take a third argument, `opts`, which represents the provider options given to the provider (if any). For example:
+Functions that are added as [custom providers](#setup-function) can also take a second argument, `opts`, which represents the provider options given to the provider (if any). For example:
```lua
-provider = function(_, _, opts)
+provider = function(_, opts)
if opts.return_two then
return 2
else
@@ -171,7 +166,7 @@ If you omit the provider value, it will be set to an empty string. A component w
#### 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:
+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. For example:
```lua
-- Enable if opened file has a valid size
@@ -180,8 +175,8 @@ enabled = function()
end
-- Enable if current window width is higher than 80
-enabled = function(winid)
- return vim.api.nvim_win_get_width(winid) > 80
+enabled = function()
+ return vim.api.nvim_win_get_width(0) > 80
end
```
@@ -193,8 +188,6 @@ The component's icon can be a table, string or function. By default, the icon in
There's also another value you can set if the value of `icon` is a table, which is `always_visible`. By default, the icon is not shown if the value returned by the provider is empty. If you want the icon to be shown even when the provider string is empty, you need to set `always_visible` to `true`.
-If the value of `icon` a function, it can take either the window handler as an argument, or it can take no arguments. For example:
-
```lua
-- Setting icon to a string
icon = ' + '
@@ -230,12 +223,11 @@ If it's a table, it'll automatically generate a highlight group for you based on
The `fg` and `bg` values are strings that represent the RGB hex or [name](#value-presets) of the foreground and background color of the highlight, respectively. (eg: `'#FFFFFF'`, `'white'`). If `fg` or `bg` is not provided, it uses the default foreground or background color provided in the `setup()` function, respectively.
-The `style` value is a string that determines the formatting style of the component's text (do
-`:help attr-list` in Neovim for more info). By default it is set to `'NONE'`
+The `style` value is a string that determines the formatting style of the component's text (do `:help attr-list` in Neovim for more info). By default it is set to `'NONE'`
The `name` value is a string that determines the name of highlight group created by Feline (eg: `'StatusComponentVimInsert'`). If a name is not provided, Feline automatically generates a unique name for the highlight group based on the other values, so you can also just omit the `name` and Feline will create new highlights for you when required. However, setting `name` may provide a performance improvement since Feline caches highlight names and doesn't take the time to generate a name if the name is already provided by the user.
-If the value of `hl` is a function, it can take either the window handler as an argument, or it can take no arguments. Note that if `hl` is a function that can return different values, the highlight is not redefined if the name stays the same. Feline only creates highlights when they don't exist, it never redefines existing highlights. So if `hl` is a function that can return different values for `fg`, `bg` or `style`, make sure to return a different value for `name` as well if you want the highlight to actually change.
+Note that if `hl` is a function that can return different values, the highlight is not redefined if the name stays the same. Feline only creates highlights when they don't exist, it never redefines existing highlights. So if `hl` is a function that can return different values for `fg`, `bg` or `style`, make sure to return a different value for `name` as well if you want the highlight to actually change.
Here are a few examples using the `hl` value:
@@ -259,11 +251,11 @@ end
-- As a function returning a string
hl = function()
- if require("feline.providers.vi_mode").get_vim_mode() == "NORMAL" then
- return "MyStatuslineNormal"
- else
- return "MyStatuslineOther"
- end
+ if require("feline.providers.vi_mode").get_vim_mode() == "NORMAL" then
+ return "MyStatuslineNormal"
+ else
+ return "MyStatuslineOther"
+ end
end
```
@@ -275,8 +267,6 @@ The value of `left_sep` and `right_sep` can just be set to a string that's displ
The value of `left_sep` and `right_sep` can also be a table or a function returning a table. Inside the table there can be three values, `str`, `hl` and `always_visible`. `str` represents the separator string and `hl` represents the separator highlight. The separator's highlight works just like the component's `hl` value. The only difference is that the separator's `hl` by default uses the parent's background color as its foreground color.
-If the separator is a function that returns a table, it can take either the window handler of the window for which the statusline is being generated for as an argument, or it can take no arguments.
-
By default, Feline doesn't show a separator if the value returned by the provider is empty. If you want the separator to be shown even when the component string is empty, you can set the `always_visible` value in the separator table to `true`. If unset or set to `false`, the separator is not shown if the component string is empty.
You can also set `left_sep` and `right_sep` to be a `table` containing multiple separator elements. It's useful if you want to have different highlights for different parts of the left/right separator of the same component, or if you want to always show certain parts of the separator regardless of whether the component string is empty, or if you just want to better organize the component's separator.
@@ -414,8 +404,8 @@ Now that you know about the components table and how Feline components work, you
```lua
custom_providers = {
- window_number = function(_, winid)
- return vim.api.nvim_win_get_number(winid)
+ window_number = function()
+ return tostring(vim.api.nvim_win_get_number(0))
end
}
```
@@ -424,8 +414,6 @@ custom_providers = {
- `separators` - A table containing custom [separator value presets](#value-presets).
- `default_hl` - A table defining the default highlights for the active and inactive statusline. It can contain two values inside of it, `active` and `inactive`. They define values of the `StatusLine` and `StatusLineNC` highlight groups, respectively. These two values are configured the same way as a component's `hl` value. For most users this configuration option won't be of any use, but it allows you to do some neat things like [using a thin line instead of the inactive statusline](#thin-line-for-horizontal-splits).
By default, both of these highlights use `colors.fg` as foreground color and `colors.bg` as background color, and have no styling option set.
-- `update_triggers` - A list of autocmds that trigger an update of the statusline in inactive windows.
- Default: `{'VimEnter', 'WinEnter', 'WinClosed', 'FileChangedShellPost'}`
- `force_inactive` - A table that determines which buffers should always have the inactive statusline, even when they are active. It can have 3 values inside of it, `filetypes`, `buftypes` and `bufnames`, all three of them are tables which contain Lua patterns to match against file type, buffer type and buffer name respectively.
Default:
@@ -564,13 +552,13 @@ The `file_info` provider has some special provider options that can be passed th
The git providers all require [gitsigns.nvim](https://github.com/lewis6991/gitsigns.nvim/), make sure you have it installed when you use those providers, otherwise they'll have no output.
-The git provider also provides a utility function `require('feline.providers.git').git_info_exists(winid)` (where `winid` is the window handler) for checking if any git information exists in the window through this utility function.
+The git provider also provides a utility function `require('feline.providers.git').git_info_exists()` for checking if any git information exists.
### Diagnostics
The diagnostics and LSP providers all require the Neovim built-in LSP to be configured and at least one LSP client to be attached to the current buffer, else they'll have no output.
-The diagnostics provider also provides a utility function `require('feline.providers.lsp').diagnostics_exist(type, winid)` (where `type` represents the type of diagnostic and `winid` is the window handler) for checking if any diagnostics of the provided type exists in the window. The values of `type` must be one of `'Error'`, `'Warning'`, `'Hint'` or `'Information'`.
+The diagnostics provider also provides a utility function `require('feline.providers.lsp').diagnostics_exist(type)` for checking if any diagnostics of the provided type exists. The values of `type` must be one of `'Error'`, `'Warning'`, `'Hint'` or `'Information'`.
## Value presets
@@ -632,6 +620,26 @@ Below is a list of all the default value names and their values:
## Tips and tricks
+### Get current window or buffer
+
+When the statusline for a window is being generated, Neovim temporarily sets the current window and buffer to the window and buffer for which the statusline is being generated.
+
+This is important to note when you set a component value to a function. Inside a component value that's set to a function, functions like `vim.api.nvim_get_current_win()` and `vim.api.nvim_get_current_buf()` will return the statusline window and buffer instead of the actual current window and buffer number. In order to access the actual current window or buffer, you have to use `vim.g.actual_curbuf` or `vim.g.actual_curwin` (respectively) inside the function instead. For example:
+
+```
+-- Provider function that shows current window number
+provider = function()
+ return vim.g.actual_curwin
+end
+
+-- Provider function that shows name of current buffer
+provider = function()
+ return vim.api.nvim_buf_get_name(tonumber(vim.g.actual_curbuf))
+end
+```
+
+Note that the values of both `vim.g.actual_curwin` and `vim.g.actual_curbuf` are strings, not numbers. So if you want to use them as a number, use `tonumber()` to convert the string to a number first, as shown in the second example.
+
### Reset highlight
If, for some reason, you want to clear all highlights that Feline sets (useful if you want to reload your entire Neovim config which may mess up highlights), you can do:
diff --git a/benchmark/statusline.lua b/benchmark/statusline.lua
index 1028baf..8ebaf72 100644
--- a/benchmark/statusline.lua
+++ b/benchmark/statusline.lua
@@ -17,7 +17,11 @@ end
-- Start benchmark
local benchmark = require('plenary.benchmark')
-local statusline_generator = require('feline').statusline
+local gen = require('feline.generator')
+
+local function statusline_generator()
+ gen.generate_statusline(true)
+end
benchmark("Feline statusline generation benchmark", {
runs = 10000,
diff --git a/lua/feline/defaults.lua b/lua/feline/defaults.lua
index f36b706..4988bf6 100644
--- a/lua/feline/defaults.lua
+++ b/lua/feline/defaults.lua
@@ -76,11 +76,4 @@ M.force_inactive = {
M.disable = {}
-M.update_triggers = {
- 'VimEnter',
- 'WinEnter',
- 'WinClosed',
- 'FileChangedShellPost'
-}
-
return M
diff --git a/lua/feline/generator.lua b/lua/feline/generator.lua
index c9b6ee9..b65ff2b 100644
--- a/lua/feline/generator.lua
+++ b/lua/feline/generator.lua
@@ -30,13 +30,11 @@ local function is_forced_inactive()
(force_inactive.bufnames and find_pattern_match(force_inactive.bufnames, bufname))
end
--- Check if buffer contained in window is configured to have statusline disabled
-local function is_disabled(winid)
- local bufnr = api.nvim_win_get_buf(winid)
-
- local buftype = bo[bufnr].buftype
- local filetype = bo[bufnr].filetype
- local bufname = api.nvim_buf_get_name(bufnr)
+-- Check if buffer is configured to have statusline disabled
+local function is_disabled()
+ local buftype = bo.buftype
+ local filetype = bo.filetype
+ local bufname = api.nvim_buf_get_name(0)
return (disable.filetypes and find_pattern_match(disable.filetypes, filetype)) or
(disable.buftypes and find_pattern_match(disable.buftypes, buftype)) or
@@ -136,7 +134,7 @@ local function get_hlname(hl, parent_hl)
end
-- Generates StatusLine and StatusLineNC highlights based on the user configuration
-local function generate_defhl(winid)
+local function generate_defhl()
for statusline_type, hlname in pairs({active = 'StatusLine', inactive = 'StatusLineNC'}) do
-- If default hl for the current statusline type is not defined, just set it to an empty
-- table so that it can be populated by parse_hl later on
@@ -146,7 +144,7 @@ local function generate_defhl(winid)
-- Only re-evaluate and add the highlight if it's a function or when it's not cached
if type(default_hl[statusline_type]) == 'function' or not M.highlights[hlname] then
- local hl = parse_hl(evaluate_if_function(default_hl[statusline_type], winid))
+ local hl = parse_hl(evaluate_if_function(default_hl[statusline_type]))
add_hl(hlname, hl.fg, hl.bg, hl.style)
end
end
@@ -155,10 +153,10 @@ end
-- Parse component seperator to return parsed string
-- By default, foreground color of separator is background color of parent
-- and background color is set to default background color
-local function parse_sep(sep, parent_bg, is_component_empty, winid)
+local function parse_sep(sep, parent_bg, is_component_empty)
if sep == nil then return '' end
- sep = evaluate_if_function(sep, winid)
+ sep = evaluate_if_function(sep)
local hl
local str
@@ -171,8 +169,8 @@ local function parse_sep(sep, parent_bg, is_component_empty, winid)
else
if is_component_empty and not sep.always_visible then return '' end
- str = evaluate_if_function(sep.str, winid) or ''
- hl = evaluate_if_function(sep.hl, winid) or {fg = parent_bg, bg = colors.bg}
+ str = evaluate_if_function(sep.str) or ''
+ hl = evaluate_if_function(sep.hl) or {fg = parent_bg, bg = colors.bg}
end
if separators[str] then str = separators[str] end
@@ -181,7 +179,7 @@ local function parse_sep(sep, parent_bg, is_component_empty, winid)
end
-- Either parse a single separator or a list of separators returning the parsed string
-local function parse_sep_list(sep_list, parent_bg, is_component_empty, winid)
+local function parse_sep_list(sep_list, parent_bg, is_component_empty)
if sep_list == nil then return '' end
if (type(sep_list) == 'table' and sep_list[1] and (
@@ -195,23 +193,22 @@ local function parse_sep_list(sep_list, parent_bg, is_component_empty, winid)
sep_strs[#sep_strs+1] = parse_sep(
v,
parent_bg,
- is_component_empty,
- winid
+ is_component_empty
)
end
return table.concat(sep_strs)
else
- return parse_sep(sep_list, parent_bg, is_component_empty, winid)
+ return parse_sep(sep_list, parent_bg, is_component_empty)
end
end
-- Parse component icon and return parsed string
-- By default, icon inherits component highlights
-local function parse_icon(icon, parent_hl, is_component_empty, winid)
+local function parse_icon(icon, parent_hl, is_component_empty)
if icon == nil then return '' end
- icon = evaluate_if_function(icon, winid)
+ icon = evaluate_if_function(icon)
local hl
local str
@@ -224,26 +221,26 @@ local function parse_icon(icon, parent_hl, is_component_empty, winid)
else
if is_component_empty and not icon.always_visible then return '' end
- str = evaluate_if_function(icon.str, winid) or ''
- hl = evaluate_if_function(icon.hl, winid) or parent_hl
+ str = evaluate_if_function(icon.str) or ''
+ hl = evaluate_if_function(icon.hl) or parent_hl
end
return string.format('%%#%s#%s', get_hlname(hl, parent_hl), str)
end
-- Parse component provider to return the provider string and default icon
-local function parse_provider(provider, winid, component)
+local function parse_provider(provider, component)
local icon
-- If provider is a string and its name matches the name of a registered provider, use it
if type(provider) == 'string' and providers[provider] then
- provider, icon = providers[provider](winid, component, {})
+ provider, icon = providers[provider](component, {})
-- If provider is a function, just evaluate it normally
elseif type(provider) == 'function' then
- provider, icon = provider(winid, component)
+ provider, icon = provider(component)
-- If provider is a table, get the provider name and opts and evaluate the provider
elseif type(provider) == 'table' then
- provider, icon = providers[provider.name](winid, component, provider.opts or {})
+ provider, icon = providers[provider.name](component, provider.opts or {})
end
if type(provider) ~= 'string' then
@@ -257,16 +254,16 @@ local function parse_provider(provider, winid, component)
end
-- Parses a component to return the component string
-local function parse_component(component, winid)
+local function parse_component(component)
local enabled
if component.enabled then enabled = component.enabled else enabled = true end
- enabled = evaluate_if_function(enabled, winid)
+ enabled = evaluate_if_function(enabled)
if not enabled then return '' end
- local hl = evaluate_if_function(component.hl, winid) or {}
+ local hl = evaluate_if_function(component.hl) or {}
local hlname
-- If highlight is a string, then accept it as an external highlight group and
@@ -283,7 +280,7 @@ local function parse_component(component, winid)
local str, icon
if component.provider then
- str, icon = parse_provider(component.provider, winid, component)
+ str, icon = parse_provider(component.provider, component)
else
str = ''
end
@@ -293,22 +290,19 @@ local function parse_component(component, winid)
local left_sep_str = parse_sep_list(
component.left_sep,
hl.bg,
- is_component_empty,
- winid
+ is_component_empty
)
local right_sep_str = parse_sep_list(
component.right_sep,
hl.bg,
- is_component_empty,
- winid
+ is_component_empty
)
icon = parse_icon(
component.icon or icon,
hl,
- is_component_empty,
- winid
+ is_component_empty
)
return string.format(
@@ -322,63 +316,57 @@ local function parse_component(component, winid)
end
-- Generate statusline by parsing all components and return a string
-function M.generate_statusline(winid)
+function M.generate_statusline(is_active)
-- Generate default highlights for the statusline
- generate_defhl(winid)
+ generate_defhl()
- local statusline_str = ''
-
- if components_table and not is_disabled(winid) then
- local statusline_type
+ if not components_table or is_disabled() then
+ return ''
+ end
- if winid == api.nvim_get_current_win() and not is_forced_inactive() then
- statusline_type='active'
- else
- statusline_type='inactive'
- end
+ local statusline_type
- local sections = components_table[statusline_type]
+ if is_active and not is_forced_inactive() then
+ statusline_type='active'
+ else
+ statusline_type='inactive'
+ end
- if sections then
- -- Concatenate all components strings of each section to get a string for each section
- local section_strs = {}
+ local sections = components_table[statusline_type]
- for i, section in ipairs(sections) do
- local component_strs = {}
+ if not sections then
+ return ''
+ end
- for j, component in ipairs(section) do
- -- Handle any errors that happen while parsing the components
- -- and point to the location of the component in case of any erros
- local ok, result = pcall(parse_component, component, winid)
+ -- Concatenate all components strings of each section to get a string for each section
+ local section_strs = {}
- if not ok then
- api.nvim_err_writeln(string.format(
- "Feline: error while processing component number %d on section %d " ..
- "of type '%s': %s",
- j, i, statusline_type, result
- ))
+ for i, section in ipairs(sections) do
+ local component_strs = {}
- result = ''
- end
+ for j, component in ipairs(section) do
+ -- Handle any errors that happen while parsing the components
+ -- and point to the location of the component in case of any erros
+ local ok, result = pcall(parse_component, component)
- component_strs[j] = result
- end
+ if not ok then
+ api.nvim_err_writeln(string.format(
+ "Feline: error while processing component number %d on section %d " ..
+ "of type '%s': %s",
+ j, i, statusline_type, result
+ ))
- section_strs[i] = table.concat(component_strs)
+ result = ''
end
- -- Then concatenate all the sections to get the statusline string
- statusline_str = table.concat(section_strs, '%=')
+ component_strs[j] = result
end
- end
- -- Never return an empty string since setting statusline to an empty string will make it
- -- use the global statusline value (same as active statusline) for inactive windows
- if statusline_str == '' then
- return ' '
- else
- return statusline_str
+ section_strs[i] = table.concat(component_strs)
end
+
+ -- Then concatenate all the sections to get the statusline string and return it
+ return table.concat(section_strs, '%=')
end
return M
diff --git a/lua/feline/init.lua b/lua/feline/init.lua
index eea1fb8..5063b1e 100644
--- a/lua/feline/init.lua
+++ b/lua/feline/init.lua
@@ -3,7 +3,8 @@ local fn = vim.fn
local api = vim.api
local cmd = api.nvim_command
-local create_augroup = require('feline.utils').create_augroup
+local utils = require('feline.utils')
+local gen = utils.lazy_require('feline.generator')
local M = {}
@@ -26,32 +27,13 @@ local function parse_config(config_dict, config_name, expected_type, default_val
end
end
--- Update the statusline of inactive windows on the current tabpage
-function M.update_inactive_windows()
- local current_win = api.nvim_get_current_win()
-
- for _, winid in ipairs(api.nvim_tabpage_list_wins(0)) do
- if api.nvim_win_get_config(winid).relative == '' and winid ~= current_win
- then
- vim.wo[winid].statusline = M.statusline(winid)
- end
- end
-
- -- Reset local statusline of current window to use the global statusline for it
- vim.wo[current_win].statusline = nil
-end
-
-- Clear all highlights created by Feline and remove them from cache
function M.reset_highlights()
- local gen = require('feline.generator')
-
for hl, _ in pairs(gen.highlights) do
cmd('highlight clear ' .. hl)
end
gen.highlights = {}
-
- M.update_inactive_windows()
end
-- Setup Feline using the provided configuration options
@@ -84,11 +66,6 @@ function M.setup(config)
M.force_inactive = parse_config(config, 'force_inactive', 'table', defaults.force_inactive)
M.disable = parse_config(config, 'disable', 'table', defaults.disable)
- M.update_triggers = defaults.update_triggers
-
- for _, trigger in ipairs(parse_config(config, 'update_triggers', 'table', {})) do
- M.update_triggers[#M.update_triggers+1] = trigger
- end
M.providers = require('feline.providers')
@@ -120,14 +97,9 @@ function M.setup(config)
-- Ensures custom quickfix statusline isn't loaded
g.qf_disable_statusline = true
- vim.o.statusline = '%!v:lua.require\'feline\'.statusline()'
+ vim.o.statusline = '%{%v:lua.require\'feline\'.statusline()%}'
- create_augroup({
- {
- table.concat(M.update_triggers, ','),
- '*',
- 'lua require("feline").update_inactive_windows()'
- },
+ utils.create_augroup({
{
'SessionLoadPost,ColorScheme',
'*',
@@ -136,8 +108,8 @@ function M.setup(config)
}, 'feline')
end
-function M.statusline(winid)
- return require('feline.generator').generate_statusline(winid or api.nvim_get_current_win())
+function M.statusline()
+ return gen.generate_statusline(api.nvim_get_current_win() == tonumber(g.actual_curwin))
end
return M
diff --git a/lua/feline/providers/cursor.lua b/lua/feline/providers/cursor.lua
index e7e1f80..a6adc0d 100644
--- a/lua/feline/providers/cursor.lua
+++ b/lua/feline/providers/cursor.lua
@@ -2,13 +2,15 @@ local api = vim.api
local M = {}
-function M.position(winid)
- return string.format('%3d:%-2d', unpack(api.nvim_win_get_cursor(winid)))
+local scroll_bar_blocks = {'▁', '▂', '▃', '▄', '▅', '▆', '▇', '█'}
+
+function M.position()
+ return string.format('%3d:%-2d', unpack(api.nvim_win_get_cursor(0)))
end
-function M.line_percentage(winid)
- local curr_line = api.nvim_win_get_cursor(winid)[1]
- local lines = api.nvim_buf_line_count(api.nvim_win_get_buf(winid))
+function M.line_percentage()
+ local curr_line = api.nvim_win_get_cursor(0)[1]
+ local lines = api.nvim_buf_line_count(0)
if curr_line == 1 then
return "Top"
@@ -19,16 +21,11 @@ function M.line_percentage(winid)
end
end
-function M.scroll_bar(winid)
- local blocks = {'▁', '▂', '▃', '▄', '▅', '▆', '▇', '█'}
- local width = 2
-
- local curr_line = api.nvim_win_get_cursor(winid)[1]
- local lines = api.nvim_buf_line_count(api.nvim_win_get_buf(winid))
-
- local index = math.floor(curr_line / lines * (#blocks - 1)) + 1
+function M.scroll_bar()
+ local curr_line = api.nvim_win_get_cursor(0)[1]
+ local lines = api.nvim_buf_line_count(0)
- return string.rep(blocks[index], width)
+ return string.rep(scroll_bar_blocks[math.floor(curr_line / lines * 7) + 1], 2)
end
return M
diff --git a/lua/feline/providers/file.lua b/lua/feline/providers/file.lua
index d2ee54c..b256009 100644
--- a/lua/feline/providers/file.lua
+++ b/lua/feline/providers/file.lua
@@ -70,8 +70,8 @@ local function get_unique_filename(filename, shorten)
return string.reverse(string.sub(filename, 1, index))
end
-function M.file_info(winid, component, opts)
- local filename = api.nvim_buf_get_name(api.nvim_win_get_buf(winid))
+function M.file_info(component, opts)
+ local filename = api.nvim_buf_get_name(0)
local type = opts.type or 'base-only'
if type == 'short-path' then
@@ -110,15 +110,13 @@ function M.file_info(winid, component, opts)
if filename == '' then filename = 'unnamed' end
- local bufnr = api.nvim_win_get_buf(winid)
-
- if bo[bufnr].readonly then
+ if bo.readonly then
readonly_str = opts.file_readonly_icon or '🔒'
else
readonly_str = ''
end
- if bo[bufnr].modified then
+ if bo.modified then
modified_str = opts.file_modified_icon or '●'
if modified_str ~= '' then modified_str = modified_str .. ' ' end
@@ -126,14 +124,14 @@ function M.file_info(winid, component, opts)
modified_str = ''
end
- return ' ' .. readonly_str .. filename .. ' ' .. modified_str, icon
+ return string.format(' %s%s %s', readonly_str, filename, modified_str), icon
end
-function M.file_size(winid)
+function M.file_size()
local suffix = {'b', 'k', 'M', 'G', 'T', 'P', 'E'}
local index = 1
- local fsize = fn.getfsize(api.nvim_buf_get_name(api.nvim_win_get_buf(winid)))
+ local fsize = fn.getfsize(api.nvim_buf_get_name(0))
if fsize < 0 then fsize = 0 end
@@ -142,17 +140,15 @@ function M.file_size(winid)
index = index + 1
end
- return string.format(index == 1 and '%g' or '%.2f', fsize) .. suffix[index]
+ return string.format(index == 1 and '%g%s' or '%.2f%s', fsize, suffix[index])
end
-function M.file_type(winid)
- return bo[api.nvim_win_get_buf(winid)].filetype:upper()
+function M.file_type()
+ return bo.filetype:upper()
end
-function M.file_encoding(winid)
- local bufnr = api.nvim_win_get_buf(winid)
- local enc = (bo[bufnr].fenc ~= '' and bo[bufnr].fenc) or vim.o.enc
- return enc:upper()
+function M.file_encoding()
+ return ((bo.fenc ~= '' and bo.fenc) or vim.o.enc):upper()
end
return M
diff --git a/lua/feline/providers/git.lua b/lua/feline/providers/git.lua
index 0a613a6..6b07253 100644
--- a/lua/feline/providers/git.lua
+++ b/lua/feline/providers/git.lua
@@ -1,43 +1,38 @@
+local b = vim.b
local g = vim.g
-local api = vim.api
local M = {}
-function M.git_branch(winid)
- local ok, head = pcall(api.nvim_buf_get_var, api.nvim_win_get_buf(winid), 'gitsigns_head')
-
- if not ok then head = g.gitsigns_head or '' end
- return head, ' '
+function M.git_branch()
+ return b.gitsigns_head or g.gitsigns_head or '', ' '
end
-- Common function used by the git providers
-local function git_diff(winid, type)
- local ok, gsd = pcall(api.nvim_buf_get_var, api.nvim_win_get_buf(winid), 'gitsigns_status_dict')
+local function git_diff(type)
+ local gsd = b.gitsigns_status_dict
- if ok and gsd[type] and gsd[type] > 0 then
+ if gsd and gsd[type] and gsd[type] > 0 then
return tostring(gsd[type])
end
return ''
end
-function M.git_diff_added(winid)
- return git_diff(winid, 'added'), ' '
+function M.git_diff_added()
+ return git_diff('added'), ' '
end
-function M.git_diff_removed(winid)
- return git_diff(winid, 'removed'), ' '
+function M.git_diff_removed()
+ return git_diff('removed'), ' '
end
-function M.git_diff_changed(winid)
- return git_diff(winid, 'changed'), ' 柳'
+function M.git_diff_changed()
+ return git_diff('changed'), ' 柳'
end
-- Utility function to check if git provider information is available
-function M.git_info_exists(winid)
- return g.gitsigns_head or
- pcall(api.nvim_buf_get_var, api.nvim_win_get_buf(winid), 'gitsigns_head') or
- pcall(api.nvim_buf_get_var, api.nvim_win_get_buf(winid), 'gitsigns_status_dict')
+function M.git_info_exists()
+ return g.gitsigns_head or b.gitsigns_head or b.gitsigns_status_dict
end
return M
diff --git a/lua/feline/providers/lsp.lua b/lua/feline/providers/lsp.lua
index d99630a..c288a8c 100644
--- a/lua/feline/providers/lsp.lua
+++ b/lua/feline/providers/lsp.lua
@@ -1,41 +1,33 @@
local M = {}
-local api = vim.api
local lsp = vim.lsp
-function M.is_lsp_attached(bufnr)
- bufnr = bufnr or api.nvim_get_current_buf()
-
- return next(lsp.buf_get_clients(bufnr)) ~= nil
+function M.is_lsp_attached()
+ return next(lsp.buf_get_clients(0)) ~= nil
end
-function M.get_diagnostics_count(severity, bufnr)
- bufnr = bufnr or api.nvim_get_current_buf()
-
- local active_clients = lsp.buf_get_clients(bufnr)
+function M.get_diagnostics_count(severity)
+ local active_clients = lsp.buf_get_clients(0)
- if not active_clients then return nil end
+ if not active_clients then return 0 end
local count = 0
for _, client in pairs(active_clients) do
- count = count + lsp.diagnostic.get_count(bufnr, severity, client.id)
+ count = count + lsp.diagnostic.get_count(0, severity, client.id)
end
return count
end
-function M.diagnostics_exist(severity, bufnr)
- bufnr = bufnr or api.nvim_get_current_buf()
-
- local diagnostics_count = M.get_diagnostics_count(severity, bufnr)
- return diagnostics_count and diagnostics_count > 0
+function M.diagnostics_exist(severity)
+ return M.get_diagnostics_count(severity) > 0
end
-function M.lsp_client_names(winid)
+function M.lsp_client_names()
local clients = {}
- for _, client in pairs(lsp.buf_get_clients(api.nvim_win_get_buf(winid))) do
+ for _, client in pairs(lsp.buf_get_clients(0)) do
clients[#clients+1] = client.name
end
@@ -43,27 +35,26 @@ function M.lsp_client_names(winid)
end
-- Common function used by the diagnostics providers
-local function diagnostics(winid, severity)
- local count = M.get_diagnostics_count(severity, api.nvim_win_get_buf(winid))
+local function diagnostics(severity)
+ local count = M.get_diagnostics_count(severity)
- if not count or count == 0 then return '' end
- return tostring(count)
+ return count ~= 0 and tostring(count) or ''
end
-function M.diagnostic_errors(winid)
- return diagnostics(winid, 'Error'), ' '
+function M.diagnostic_errors()
+ return diagnostics('Error'), ' '
end
-function M.diagnostic_warnings(winid)
- return diagnostics(winid, 'Warning'), ' '
+function M.diagnostic_warnings()
+ return diagnostics('Warning'), ' '
end
-function M.diagnostic_hints(winid)
- return diagnostics(winid, 'Hint'), ' '
+function M.diagnostic_hints()
+ return diagnostics('Hint'), ' '
end
-function M.diagnostic_info(winid)
- return diagnostics(winid, 'Information'), ' '
+function M.diagnostic_info()
+ return diagnostics('Information'), ' '
end
return M
diff --git a/lua/feline/providers/vi_mode.lua b/lua/feline/providers/vi_mode.lua
index 28d4f38..49d70ed 100644
--- a/lua/feline/providers/vi_mode.lua
+++ b/lua/feline/providers/vi_mode.lua
@@ -54,7 +54,7 @@ function M.get_mode_highlight_name()
return 'StatusComponentVim' .. title_case(M.get_vim_mode())
end
-function M.vi_mode(_, component)
+function M.vi_mode(component)
if component.icon == '' then
return M.get_vim_mode()
elseif component.icon == nil then