From c19724fbaa070faeb33e28106841ad5a74339795 Mon Sep 17 00:00:00 2001 From: hoob3rt Date: Thu, 11 Mar 2021 00:07:38 +0100 Subject: [PATCH 01/14] feat: made extensions consistent with statusline --- lua/lualine.lua | 93 +++++++++++++++++++++++++++++++++++-------------- 1 file changed, 66 insertions(+), 27 deletions(-) diff --git a/lua/lualine.lua b/lua/lualine.lua index dfa4d16..2e2d1bc 100644 --- a/lua/lualine.lua +++ b/lua/lualine.lua @@ -35,8 +35,32 @@ M.inactive_sections = { lualine_z = { } } -M.extensions = { -} +M.extensions = {} + +local function apply_configuration(config_table) + if not config_table then return end + local function parse_sections(section_group_name) + if not config_table[section_group_name] then return end + for section_name, section in pairs(config_table[section_group_name]) do + M[section_group_name][section_name] = config_table[section_group_name][section_name] + if type(section) == 'table' then + for _, component in pairs(section) do + if type(component) == 'table' and type(component[2]) == 'table' then + local options = component[2] + component[2] = nil + for key, val in pairs(options) do + component[key] = val + end + end + end + end + end + end + parse_sections('options') + parse_sections('sections') + parse_sections('inactive_sections') + if config_table.extensions then M.extensions = config_table.extensions end +end local function check_single_separator() local compoennt_separator = M.options.component_separators @@ -126,36 +150,31 @@ 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) 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 @@ -181,7 +200,27 @@ local function lualine_set_theme() theme_set = M.options.theme end -local function statusline(sections, is_focused) +local function statusline(is_focused) + local sections = nil + for _, extension in ipairs(M.extensions) do + for _, filetype in ipairs(extension.filetypes) do + if vim.bo.filetype == filetype then + if is_focused then + sections = extension.sections + else + sections = extension.inactive_sections + end + break + end + end + end + if sections == nil then + if is_focused then + sections = M.sections + else + sections = M.inactive_sections + end + end if M.options.theme ~= theme_set then _G.lualine_set_theme() end @@ -252,9 +291,9 @@ end local function status_dispatch() if vim.g.statusline_winid == vim.fn.win_getid() then - return statusline(M.sections, true) + return statusline(true) else - return statusline(M.inactive_sections, false) + return statusline(false) end end From 64a378d670bf571f46922617a4d330308ca40f3e Mon Sep 17 00:00:00 2001 From: hoob3rt Date: Thu, 11 Mar 2021 00:14:37 +0100 Subject: [PATCH 02/14] feat: added fugitive extension --- lua/lualine/extensions/fugitive.lua | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 lua/lualine/extensions/fugitive.lua diff --git a/lua/lualine/extensions/fugitive.lua b/lua/lualine/extensions/fugitive.lua new file mode 100644 index 0000000..1b26f91 --- /dev/null +++ b/lua/lualine/extensions/fugitive.lua @@ -0,0 +1,16 @@ +-- Copyright (c) 2020-2021 hoob3rt +-- MIT license, see LICENSE for more details. + +local M = {} + +M.sections = { + lualine_a = { 'FugitiveHead' }, +} + +M.inactive_sections = { + lualine_a = { 'FugitiveHead' }, +} + +M.filetypes = { 'fugitive' } + +return M From da46b69e3af132706ad8f796ddb105a2a80f1062 Mon Sep 17 00:00:00 2001 From: hoob3rt Date: Thu, 11 Mar 2021 00:30:04 +0100 Subject: [PATCH 03/14] feat: added nerdtree extension --- lua/lualine.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lua/lualine.lua b/lua/lualine.lua index e1fca49..a9bbe32 100644 --- a/lua/lualine.lua +++ b/lua/lualine.lua @@ -37,7 +37,7 @@ M.inactive_sections = { M.tabline = {} -M.extensions = {} +M.extensions = {'nerdtree'} local function apply_configuration(config_table) if not config_table then return end From add3045cdc389b87f808aa60c0439a8a4fb55352 Mon Sep 17 00:00:00 2001 From: hoob3rt Date: Thu, 11 Mar 2021 00:31:57 +0100 Subject: [PATCH 04/14] Revert "feat: added nerdtree extension" This reverts commit da46b69e3af132706ad8f796ddb105a2a80f1062. --- lua/lualine.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lua/lualine.lua b/lua/lualine.lua index a9bbe32..e1fca49 100644 --- a/lua/lualine.lua +++ b/lua/lualine.lua @@ -37,7 +37,7 @@ M.inactive_sections = { M.tabline = {} -M.extensions = {'nerdtree'} +M.extensions = {} local function apply_configuration(config_table) if not config_table then return end From 303edcfe968af3ddda66e2cfe21cb21b468c4c24 Mon Sep 17 00:00:00 2001 From: hoob3rt Date: Thu, 11 Mar 2021 00:32:13 +0100 Subject: [PATCH 05/14] feat: added nerdtree extension --- lua/lualine/extensions/nerdtree.lua | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) create mode 100644 lua/lualine/extensions/nerdtree.lua diff --git a/lua/lualine/extensions/nerdtree.lua b/lua/lualine/extensions/nerdtree.lua new file mode 100644 index 0000000..884659e --- /dev/null +++ b/lua/lualine/extensions/nerdtree.lua @@ -0,0 +1,16 @@ +-- Copyright (c) 2020-2021 hoob3rt +-- MIT license, see LICENSE for more details. + +local M = {} + +M.sections = { + lualine_a = { vim.fn.getcwd }, +} + +M.inactive_sections = { + lualine_a = { vim.fn.getcwd }, +} + +M.filetypes = { 'nerdtree' } + +return M From 0be459c0f3a19e67c609c2079db0766bbd5d2bc1 Mon Sep 17 00:00:00 2001 From: hoob3rt Date: Thu, 11 Mar 2021 00:35:08 +0100 Subject: [PATCH 06/14] docs: mmade tabline a details section --- README.md | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 3d702ec..d2e52a7 100644 --- a/README.md +++ b/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 @@ -274,8 +269,9 @@ lualine.sections.lualine_b = { -### Using tabline as statusline -You can use lualine to display components in tabline . +
+Using tabline as statusline (statusline on top) +You can use lualine to display components in tabline. The sections, configurations and highlights are same as statusline. ``` @@ -300,6 +296,7 @@ lualine.tabline = { lualine.sections = {} lualine.inactive_sections = {} ``` + ### 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) From ddad28dca5b06531167fdc806c3877169d4fec2c Mon Sep 17 00:00:00 2001 From: hoob3rt Date: Thu, 11 Mar 2021 00:36:10 +0100 Subject: [PATCH 07/14] docs: fixed typo in README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index d2e52a7..0456636 100644 --- a/README.md +++ b/README.md @@ -296,7 +296,7 @@ lualine.tabline = { lualine.sections = {} lualine.inactive_sections = {} ``` - +
### 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) From 4bf5e247ff2c374f1a5f631192fc830c0961741c Mon Sep 17 00:00:00 2001 From: hoob3rt Date: Thu, 11 Mar 2021 00:37:39 +0100 Subject: [PATCH 08/14] docs: fixed code highlight in README.md --- README.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index 0456636..cb1813b 100644 --- a/README.md +++ b/README.md @@ -60,7 +60,7 @@ Lualine has sections as shown below. ``` +-------------------------------------------------+ -| A | B | C X | Y | Z | +| A | B | C X | Y | Z | +-------------------------------------------------+ ``` @@ -274,7 +274,7 @@ lualine.sections.lualine_b = { 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' }, @@ -289,7 +289,7 @@ 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 = { ...... } From ccca56d05706fe8376f25d1e00c82816fc7d35e1 Mon Sep 17 00:00:00 2001 From: hoob3rt Date: Sat, 13 Mar 2021 00:52:28 +0100 Subject: [PATCH 09/14] feat: updated fzf extension to new api --- lua/lualine/extensions/fzf.lua | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/lua/lualine/extensions/fzf.lua b/lua/lualine/extensions/fzf.lua index d1ebbda..73f5835 100644 --- a/lua/lualine/extensions/fzf.lua +++ b/lua/lualine/extensions/fzf.lua @@ -2,19 +2,19 @@ -- 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 = { + lualine_a = { fzf_statusline }, +} + +M.filetypes = { 'fzf' } + +return M From bbcd9e43be82413fb7bea5cfdfeb7867b93fbcba Mon Sep 17 00:00:00 2001 From: hoob3rt Date: Sat, 13 Mar 2021 01:21:37 +0100 Subject: [PATCH 10/14] fix: added tabline handling to extensions --- lua/lualine.lua | 58 +++++++++++++++++++++++++++++-------------------- 1 file changed, 34 insertions(+), 24 deletions(-) diff --git a/lua/lualine.lua b/lua/lualine.lua index e1fca49..ef1fe69 100644 --- a/lua/lualine.lua +++ b/lua/lualine.lua @@ -204,27 +204,8 @@ local function lualine_set_theme() theme_set = M.options.theme end -local function statusline(is_focused) - local sections = nil - for _, extension in ipairs(M.extensions) do - for _, filetype in ipairs(extension.filetypes) do - if vim.bo.filetype == filetype then - if is_focused then - sections = extension.sections - else - sections = extension.inactive_sections - end - break - end - end - end - if sections == nil then - if is_focused then - sections = M.sections - else - sections = M.inactive_sections - end - end + +local function statusline(sections, is_focused) if M.options.theme ~= theme_set then _G.lualine_set_theme() end @@ -293,16 +274,45 @@ local function statusline(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(true) + local sections = extension_sections.sections + if sections == nil then + sections = M.sections + end + return statusline(sections, true) else - return statusline(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 local function tabline() - return statusline(M.tabline, true) + local extension_sections = get_extension_sections() + local sections = extension_sections.sections + if sections == nil then + sections = M.tabline + end + return statusline(sections, true) end local function setup_theme() From 5ca719a5a7e3dd51ab467324933b3e638caada81 Mon Sep 17 00:00:00 2001 From: hoob3rt Date: Tue, 16 Mar 2021 00:00:45 +0100 Subject: [PATCH 11/14] docs: added available extensions to README.md --- EXTENSIONS.md | 5 ----- README.md | 9 ++++++++- 2 files changed, 8 insertions(+), 6 deletions(-) delete mode 100644 EXTENSIONS.md diff --git a/EXTENSIONS.md b/EXTENSIONS.md deleted file mode 100644 index 4d0acce..0000000 --- a/EXTENSIONS.md +++ /dev/null @@ -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) diff --git a/README.md b/README.md index cb1813b..0e327bc 100644 --- a/README.md +++ b/README.md @@ -306,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) +
+Available components + +* fugitive +* fzf +* nerdtree + +
### Lua config example From a1ffa2a39eb5b049c8dc546b1c04d86da4a56b2f Mon Sep 17 00:00:00 2001 From: hoob3rt Date: Tue, 16 Mar 2021 00:01:04 +0100 Subject: [PATCH 12/14] fix: removed extensions from tabline --- lua/lualine.lua | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/lua/lualine.lua b/lua/lualine.lua index ef1fe69..ae35331 100644 --- a/lua/lualine.lua +++ b/lua/lualine.lua @@ -307,12 +307,7 @@ local function status_dispatch() end local function tabline() - local extension_sections = get_extension_sections() - local sections = extension_sections.sections - if sections == nil then - sections = M.tabline - end - return statusline(sections, true) + return statusline(M.tabline, true) end local function setup_theme() From 2f53c50e3946ce67d9644aa49d35909285b994e2 Mon Sep 17 00:00:00 2001 From: hoob3rt Date: Tue, 16 Mar 2021 00:02:22 +0100 Subject: [PATCH 13/14] docs: fixed typo in README.md --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index 0e327bc..272efe2 100644 --- a/README.md +++ b/README.md @@ -307,7 +307,7 @@ lualine.extensions = { 'fzf' } ```
-Available components +Available extensions * fugitive * fzf From 74323eb08b357ad01b89605dca938c2f9602d928 Mon Sep 17 00:00:00 2001 From: hoob3rt Date: Tue, 16 Mar 2021 00:05:41 +0100 Subject: [PATCH 14/14] refactor: simplified extension sections --- lua/lualine/extensions/fugitive.lua | 5 ++--- lua/lualine/extensions/fzf.lua | 4 +--- lua/lualine/extensions/nerdtree.lua | 4 +--- 3 files changed, 4 insertions(+), 9 deletions(-) diff --git a/lua/lualine/extensions/fugitive.lua b/lua/lualine/extensions/fugitive.lua index 1b26f91..32a28ea 100644 --- a/lua/lualine/extensions/fugitive.lua +++ b/lua/lualine/extensions/fugitive.lua @@ -5,11 +5,10 @@ local M = {} M.sections = { lualine_a = { 'FugitiveHead' }, + lualine_z = { 'location' }, } -M.inactive_sections = { - lualine_a = { 'FugitiveHead' }, -} +M.inactive_sections = M.sections M.filetypes = { 'fugitive' } diff --git a/lua/lualine/extensions/fzf.lua b/lua/lualine/extensions/fzf.lua index 73f5835..19a176f 100644 --- a/lua/lualine/extensions/fzf.lua +++ b/lua/lualine/extensions/fzf.lua @@ -11,9 +11,7 @@ M.sections = { lualine_a = { fzf_statusline }, } -M.inactive_sections = { - lualine_a = { fzf_statusline }, -} +M.inactive_sections = M.sections M.filetypes = { 'fzf' } diff --git a/lua/lualine/extensions/nerdtree.lua b/lua/lualine/extensions/nerdtree.lua index 884659e..2fd9f68 100644 --- a/lua/lualine/extensions/nerdtree.lua +++ b/lua/lualine/extensions/nerdtree.lua @@ -7,9 +7,7 @@ M.sections = { lualine_a = { vim.fn.getcwd }, } -M.inactive_sections = { - lualine_a = { vim.fn.getcwd }, -} +M.inactive_sections = M.sections M.filetypes = { 'nerdtree' }