Merge pull request #126 from hoob3rt/extensions

This commit is contained in:
Hubert Pelczarski 2021-03-16 00:06:06 +01:00 committed by GitHub
commit 6e64822f50
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 99 additions and 54 deletions

View File

@ -1,5 +0,0 @@
# Available extensions
### [fzf.vim](https://github.com/junegunn/fzf.vim)
![fzf](https://user-images.githubusercontent.com/41551030/103468293-e7b7ad80-4d57-11eb-9d16-a150f9dac4b7.png)

View File

@ -2,11 +2,6 @@
![code size](https://img.shields.io/github/languages/code-size/hoob3rt/lualine.nvim?style=flat-square) ![code size](https://img.shields.io/github/languages/code-size/hoob3rt/lualine.nvim?style=flat-square)
![license](https://img.shields.io/github/license/hoob3rt/lualine.nvim?style=flat-square) ![license](https://img.shields.io/github/license/hoob3rt/lualine.nvim?style=flat-square)
![last commit](https://img.shields.io/github/last-commit/hoob3rt/lualine.nvim?style=flat-square)
![contributions](https://img.shields.io/github/contributors/hoob3rt/lualine.nvim?style=flat-square)
![issues](https://img.shields.io/github/issues-raw/hoob3rt/lualine.nvim?style=flat-square)
![prs](https://img.shields.io/github/issues-pr-raw/hoob3rt/lualine.nvim?style=flat-square)
A blazing fast and easy to configure neovim statusline written in pure lua. A blazing fast and easy to configure neovim statusline written in pure lua.
`lualine.nvim` requires neovim 0.5 `lualine.nvim` requires neovim 0.5
@ -274,11 +269,12 @@ lualine.sections.lualine_b = {
</details> </details>
### Using tabline as statusline <details>
<summary><b>Using tabline as statusline (statusline on top)</b></summary>
You can use lualine to display components in tabline. You can use lualine to display components in tabline.
The sections, configurations and highlights are same as statusline. The sections, configurations and highlights are same as statusline.
``` ```lua
lualine.tabline = { lualine.tabline = {
lualine_a = { }, lualine_a = { },
lualine_b = { 'branch' }, lualine_b = { 'branch' },
@ -293,13 +289,14 @@ This will show branch and filename component in top of neovim inside tabline .
You can also completely move your statuline to tabline by configuring lualine.tabline You can also completely move your statuline to tabline by configuring lualine.tabline
instead of lualine.sections & lualine.inactive_sections and setting them to empty instead of lualine.sections & lualine.inactive_sections and setting them to empty
``` ```lua
lualine.tabline = { lualine.tabline = {
...... ......
} }
lualine.sections = {} lualine.sections = {}
lualine.inactive_sections = {} lualine.inactive_sections = {}
``` ```
</details>
### Loading plugin extensions ### Loading plugin extensions
Lualine extensions change statusline appearance for a window/buffer with a plugin loaded e.g. [junegunn/fzf.vim](https://github.com/junegunn/fzf.vim) Lualine extensions change statusline appearance for a window/buffer with a plugin loaded e.g. [junegunn/fzf.vim](https://github.com/junegunn/fzf.vim)
@ -309,7 +306,14 @@ By default no plugin extension are loaded to improve performance. If you are usi
lualine.extensions = { 'fzf' } lualine.extensions = { 'fzf' }
``` ```
All available extensions are listed in [EXTENSIONS.md](./EXTENSIONS.md) <details>
<summary><b>Available extensions</b></summary>
* fugitive
* fzf
* nerdtree
</details>
### Lua config example ### Lua config example

View File

@ -65,7 +65,6 @@ local function apply_configuration(config_table)
if config_table.extensions then M.extensions = config_table.extensions end if config_table.extensions then M.extensions = config_table.extensions end
end end
local function check_single_separator() local function check_single_separator()
local compoennt_separator = M.options.component_separators local compoennt_separator = M.options.component_separators
local section_separator = M.options.section_separators local section_separator = M.options.section_separators
@ -154,8 +153,6 @@ local function component_loader(component)
end end
end end
local function load_components()
local function load_sections(sections) local function load_sections(sections)
for section_name, section in pairs(sections) do for section_name, section in pairs(sections) do
for index, component in pairs(section) do for index, component in pairs(section) do
@ -169,22 +166,19 @@ local function load_components()
end end
end end
end end
local function load_components()
load_sections(M.sections) load_sections(M.sections)
load_sections(M.inactive_sections) load_sections(M.inactive_sections)
load_sections(M.tabline) load_sections(M.tabline)
end end
local function load_extensions() local function load_extensions()
for _, extension in pairs(M.extensions) do for index, extension in pairs(M.extensions) do
if type(extension) == 'string' then local local_extension = require('lualine.extensions.' .. extension)
require('lualine.extensions.' .. extension).load_extension() load_sections(local_extension.sections)
end load_sections(local_extension.inactive_sections)
if type(extension) == 'table' then M.extensions[index] = local_extension
extension.load_extension()
end
if type(extension) == 'function' then
extension()
end
end end
end end
@ -210,6 +204,7 @@ local function lualine_set_theme()
theme_set = M.options.theme theme_set = M.options.theme
end end
local function statusline(sections, is_focused) local function statusline(sections, is_focused)
if M.options.theme ~= theme_set then if M.options.theme ~= theme_set then
_G.lualine_set_theme() _G.lualine_set_theme()
@ -279,11 +274,35 @@ local function statusline(sections, is_focused)
return table.concat(status) return table.concat(status)
end end
-- check if any extension matches the filetype and return proper sections
local function get_extension_sections()
local sections, inactive_sections = nil, nil
for _, extension in ipairs(M.extensions) do
for _, filetype in ipairs(extension.filetypes) do
if vim.bo.filetype == filetype then
sections = extension.sections
inactive_sections = extension.inactive_sections
break
end
end
end
return {sections = sections, inactive_sections = inactive_sections}
end
local function status_dispatch() local function status_dispatch()
local extension_sections = get_extension_sections()
if vim.g.statusline_winid == vim.fn.win_getid() then if vim.g.statusline_winid == vim.fn.win_getid() then
return statusline(M.sections, true) local sections = extension_sections.sections
if sections == nil then
sections = M.sections
end
return statusline(sections, true)
else else
return statusline(M.inactive_sections, false) local inactive_sections = extension_sections.inactive_sections
if inactive_sections == nil then
inactive_sections = M.inactive_sections
end
return statusline(inactive_sections, false)
end end
end end

View File

@ -0,0 +1,15 @@
-- Copyright (c) 2020-2021 hoob3rt
-- MIT license, see LICENSE for more details.
local M = {}
M.sections = {
lualine_a = { 'FugitiveHead' },
lualine_z = { 'location' },
}
M.inactive_sections = M.sections
M.filetypes = { 'fugitive' }
return M

View File

@ -2,19 +2,17 @@
-- MIT license, see LICENSE for more details. -- MIT license, see LICENSE for more details.
local function fzf_statusline() local function fzf_statusline()
vim.cmd([[hi clear fzf1]]) return 'FZF'
vim.cmd([[hi link fzf1 lualine_a_normal]])
vim.cmd([[hi clear fzf2]])
vim.cmd([[hi link fzf2 lualine_c_normal]])
return ([[%#fzf1# FZF %#fzf2#]])
end end
local function load_extension() local M = {}
_G.fzf_statusline = fzf_statusline
vim.cmd(([[autocmd! User FzfStatusLine setlocal statusline=%!v:lua.fzf_statusline()]]))
end
return { M.sections = {
load_extension = load_extension lualine_a = { fzf_statusline },
} }
M.inactive_sections = M.sections
M.filetypes = { 'fzf' }
return M

View File

@ -0,0 +1,14 @@
-- Copyright (c) 2020-2021 hoob3rt
-- MIT license, see LICENSE for more details.
local M = {}
M.sections = {
lualine_a = { vim.fn.getcwd },
}
M.inactive_sections = M.sections
M.filetypes = { 'nerdtree' }
return M