Merge pull request #126 from hoob3rt/extensions
This commit is contained in:
commit
6e64822f50
|
@ -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)
|
26
README.md
26
README.md
|
@ -2,11 +2,6 @@
|
|||
![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)
|
||||
|
||||
![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.
|
||||
|
||||
`lualine.nvim` requires neovim 0.5
|
||||
|
@ -65,7 +60,7 @@ Lualine has sections as shown below.
|
|||
|
||||
```
|
||||
+-------------------------------------------------+
|
||||
| A | B | C X | Y | Z |
|
||||
| A | B | C X | Y | Z |
|
||||
+-------------------------------------------------+
|
||||
```
|
||||
|
||||
|
@ -274,11 +269,12 @@ lualine.sections.lualine_b = {
|
|||
|
||||
</details>
|
||||
|
||||
### Using tabline as statusline
|
||||
You can use lualine to display components in tabline .
|
||||
<details>
|
||||
<summary><b>Using tabline as statusline (statusline on top)</b></summary>
|
||||
You can use lualine to display components in tabline.
|
||||
The sections, configurations and highlights are same as statusline.
|
||||
|
||||
```
|
||||
```lua
|
||||
lualine.tabline = {
|
||||
lualine_a = { },
|
||||
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
|
||||
instead of lualine.sections & lualine.inactive_sections and setting them to empty
|
||||
```
|
||||
```lua
|
||||
lualine.tabline = {
|
||||
......
|
||||
}
|
||||
lualine.sections = {}
|
||||
lualine.inactive_sections = {}
|
||||
```
|
||||
</details>
|
||||
|
||||
### 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)
|
||||
|
@ -309,7 +306,14 @@ By default no plugin extension are loaded to improve performance. If you are usi
|
|||
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
|
||||
|
||||
|
|
|
@ -37,7 +37,7 @@ M.inactive_sections = {
|
|||
|
||||
M.tabline = {}
|
||||
|
||||
M.extensions = { }
|
||||
M.extensions = {}
|
||||
|
||||
local function apply_configuration(config_table)
|
||||
if not config_table then return end
|
||||
|
@ -65,7 +65,6 @@ local function apply_configuration(config_table)
|
|||
if config_table.extensions then M.extensions = config_table.extensions end
|
||||
end
|
||||
|
||||
|
||||
local function check_single_separator()
|
||||
local compoennt_separator = M.options.component_separators
|
||||
local section_separator = M.options.section_separators
|
||||
|
@ -154,37 +153,32 @@ local function component_loader(component)
|
|||
end
|
||||
end
|
||||
|
||||
|
||||
local function load_components()
|
||||
local function load_sections(sections)
|
||||
for section_name, section in pairs(sections) do
|
||||
for index, component in pairs(section) do
|
||||
if type(component) == 'string' or type(component) == 'function' then
|
||||
component = {component}
|
||||
end
|
||||
component.self = {}
|
||||
component.self.section = section_name
|
||||
component_loader(component)
|
||||
section[index] = component
|
||||
local function load_sections(sections)
|
||||
for section_name, section in pairs(sections) do
|
||||
for index, component in pairs(section) do
|
||||
if type(component) == 'string' or type(component) == 'function' then
|
||||
component = {component}
|
||||
end
|
||||
component.self = {}
|
||||
component.self.section = section_name
|
||||
component_loader(component)
|
||||
section[index] = component
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
local function load_components()
|
||||
load_sections(M.sections)
|
||||
load_sections(M.inactive_sections)
|
||||
load_sections(M.tabline)
|
||||
end
|
||||
|
||||
local function load_extensions()
|
||||
for _, extension in pairs(M.extensions) do
|
||||
if type(extension) == 'string' then
|
||||
require('lualine.extensions.' .. extension).load_extension()
|
||||
end
|
||||
if type(extension) == 'table' then
|
||||
extension.load_extension()
|
||||
end
|
||||
if type(extension) == 'function' then
|
||||
extension()
|
||||
end
|
||||
for index, extension in pairs(M.extensions) do
|
||||
local local_extension = require('lualine.extensions.' .. extension)
|
||||
load_sections(local_extension.sections)
|
||||
load_sections(local_extension.inactive_sections)
|
||||
M.extensions[index] = local_extension
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -210,6 +204,7 @@ local function lualine_set_theme()
|
|||
theme_set = M.options.theme
|
||||
end
|
||||
|
||||
|
||||
local function statusline(sections, is_focused)
|
||||
if M.options.theme ~= theme_set then
|
||||
_G.lualine_set_theme()
|
||||
|
@ -279,11 +274,35 @@ local function statusline(sections, is_focused)
|
|||
return table.concat(status)
|
||||
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 extension_sections = get_extension_sections()
|
||||
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
|
||||
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
|
||||
|
||||
|
|
|
@ -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
|
|
@ -2,19 +2,17 @@
|
|||
-- MIT license, see LICENSE for more details.
|
||||
|
||||
local function fzf_statusline()
|
||||
vim.cmd([[hi clear fzf1]])
|
||||
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#]])
|
||||
|
||||
return 'FZF'
|
||||
end
|
||||
|
||||
local function load_extension()
|
||||
_G.fzf_statusline = fzf_statusline
|
||||
vim.cmd(([[autocmd! User FzfStatusLine setlocal statusline=%!v:lua.fzf_statusline()]]))
|
||||
end
|
||||
local M = {}
|
||||
|
||||
return {
|
||||
load_extension = load_extension
|
||||
M.sections = {
|
||||
lualine_a = { fzf_statusline },
|
||||
}
|
||||
|
||||
M.inactive_sections = M.sections
|
||||
|
||||
M.filetypes = { 'fzf' }
|
||||
|
||||
return M
|
||||
|
|
|
@ -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
|
Loading…
Reference in New Issue