Feat: add configuration in viml and status function (#114)

This commit is contained in:
Shadman 2021-03-02 18:58:34 +06:00 committed by GitHub
parent e4723362c4
commit 8624f7c14e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 169 additions and 143 deletions

112
README.md
View File

@ -58,6 +58,9 @@ use {
``` ```
## Usage and customization ## Usage and customization
Lualine can be configured with both lua and vimscript.
Click [here](#lua-config-example) if you want to see a config example in lua and [here](#vimscript-config-example) if you want to see a config example in vimscript.
Lualine has sections as shown below. Lualine has sections as shown below.
``` ```
@ -69,8 +72,6 @@ Lualine has sections as shown below.
Each sections holds it's components e.g. current vim's mode. Each sections holds it's components e.g. current vim's mode.
Colorscheme of sections is mirrored, meaning section `A` will have the same colorscheme as section `Z` etc. Colorscheme of sections is mirrored, meaning section `A` will have the same colorscheme as section `Z` etc.
Configuration is currently limited to lua, please use lua block or a separate lua file to configure lualine.
### Starting lualine ### Starting lualine
```lua ```lua
local lualine = require('lualine') local lualine = require('lualine')
@ -265,7 +266,7 @@ lualine.sections.lualine_b = {
format = function(name) format = function(name)
-- Capitalize first charecter of filename to capital. -- Capitalize first charecter of filename to capital.
local path, fname = name:match('(.*/)(.*)') local path, fname = name:match('(.*/)(.*)')
if not path then path = ''; fname = name end if not path then path = ''; fname = name end
return path .. fname:sub(1, 1):upper() .. fname:sub(2, #fname) return path .. fname:sub(1, 1):upper() .. fname:sub(2, #fname)
end end
} }
@ -284,7 +285,7 @@ lualine.extensions = { 'fzf' }
All available extensions are listed in [EXTENSIONS.md](./EXTENSIONS.md) All available extensions are listed in [EXTENSIONS.md](./EXTENSIONS.md)
### Full config example using [packer.nvim](https://github.com/wbthomason/packer.nvim) ### Lua config example
<details> <details>
<summary><b>packer config</b></summary> <summary><b>packer config</b></summary>
@ -294,69 +295,68 @@ All available extensions are listed in [EXTENSIONS.md](./EXTENSIONS.md)
'hoob3rt/lualine.nvim', 'hoob3rt/lualine.nvim',
requires = {'kyazdani42/nvim-web-devicons', opt = true}, requires = {'kyazdani42/nvim-web-devicons', opt = true},
config = function() config = function()
local lualine = require('lualine') require('lualine').status{
lualine.options = { options = {
theme = 'gruvbox', theme = 'gruvbox',
section_separators = {'', ''}, section_separators = {'', ''},
component_separators = {'', ''}, component_separators = {'', ''},
icons_enabled = true, icons_enabled = true,
},
sections = {
lualine_a = { {'mode', upper = true} },
lualine_b = { {'branch', icon = ''} },
lualine_c = { {'filename', file_status = true} },
lualine_x = { 'encoding', 'fileformat', 'filetype' },
lualine_y = { 'progress' },
lualine_z = { 'location' },
},
inactive_sections = {
lualine_a = { },
lualine_b = { },
lualine_c = { 'filename' },
lualine_x = { 'location' },
lualine_y = { },
lualine_z = { }
},
extensions = { 'fzf' }
} }
lualine.sections = {
lualine_a = { 'mode' },
lualine_b = { 'branch' },
lualine_c = { 'filename' },
lualine_x = { 'encoding', 'fileformat', 'filetype' },
lualine_y = { 'progress' },
lualine_z = { 'location' },
}
lualine.inactive_sections = {
lualine_a = { },
lualine_b = { },
lualine_c = { 'filename' },
lualine_x = { 'location' },
lualine_y = { },
lualine_z = { }
}
lualine.extensions = { 'fzf' }
lualine.status()
end end
} }
``` ```
</details> </details>
### Full config example inside `.vimrc`/`init.vim` ### Vimscript config example
<details> <details>
<summary><b>vimrc config</b></summary> <summary><b>vimrc config</b></summary>
```vim ```vim
lua << EOF let g:lualine = {
local lualine = require('lualine') \'options' : {
lualine.options = { \ 'theme' : 'gruvbox',
theme = 'gruvbox', \ 'section_separators' : ['', ''],
section_separators = {'', ''}, \ 'component_separators' : ['', ''],
component_separators = {'', ''}, \ 'icons_enabled' : v:true,
icons_enabled = true, \},
} \'sections' : {
lualine.sections = { \ 'lualine_a' : [ ['mode', {'upper': v:true,},], ],
lualine_a = { 'mode' }, \ 'lualine_b' : [ ['branch', {'icon': '',}, ], ],
lualine_b = { 'branch' }, \ 'lualine_c' : [ ['filename', {'file_status': v:true,},], ],
lualine_c = { 'filename' }, \ 'lualine_x' : [ 'encoding', 'fileformat', 'filetype' ],
lualine_x = { 'encoding', 'fileformat', 'filetype' }, \ 'lualine_y' : [ 'progress' ],
lualine_y = { 'progress' }, \ 'lualine_z' : [ 'location' ],
lualine_z = { 'location' }, \},
} \'inactive_sections' : {
lualine.inactive_sections = { \ 'lualine_a' : [ ],
lualine_a = { }, \ 'lualine_b' : [ ],
lualine_b = { }, \ 'lualine_c' : [ 'filename' ],
lualine_c = { 'filename' }, \ 'lualine_x' : [ 'location' ],
lualine_x = { 'location' }, \ 'lualine_y' : [ ],
lualine_y = { }, \ 'lualine_z' : [ ],
lualine_z = { } \},
} \'extensions' : [ 'fzf' ],
lualine.extensions = { 'fzf' } \}
lualine.status() lua require("lualine").status()
EOF
``` ```
</details> </details>

View File

@ -1,5 +1,5 @@
*lualine.txt* A blazing fast and easy to configure statusline *lualine.txt* A blazing fast and easy to configure statusline
*lualine_nvim* *lualine* *lualine_nvim* *lualine*
Author: hoob3rt (https://github.com/hoob3rt) Author: hoob3rt (https://github.com/hoob3rt)
License: MIT License License: MIT License
@ -38,14 +38,14 @@ CONTENTS *lualine_contents*
1.3.5. Building Custom components............|lualine_custom_components| 1.3.5. Building Custom components............|lualine_custom_components|
1.3.6. Custom options...........................|lualine_custom_options| 1.3.6. Custom options...........................|lualine_custom_options|
1.3.7. Loading plugin extensions.....|lualine_loading_plugin_extensions| 1.3.7. Loading plugin extensions.....|lualine_loading_plugin_extensions|
1.3.8 Config examples.........................|lualine_config_examples| 1.3.8 Config examples.........................|lualine_config_examples|
1.3.8.1. Packer.nvim......|lualine_config_example_using_packer.nvim| 1.3.8.1. Packer.nvim......|lualine_config_example_using_packer.nvim|
1.3.8.2 VIML example.......|lualine_full_config_example_inside_viml| 1.3.8.2 VIML example.......|lualine_full_config_example_inside_viml|
1.4. Contributing.....................................|lualine_contributing| 1.4. Contributing.....................................|lualine_contributing|
1.5. Screenshots.......................................|lualine_screenshots| 1.5. Screenshots.......................................|lualine_screenshots|
================================================================================ ================================================================================
PERFORMANCE COMPARISM *lualine_performance_comparism* PERFORMANCE COMPARISM *lualine_performance_comparism*
Unlike other statusline plugins lualine loads only defined components, nothing else. Unlike other statusline plugins lualine loads only defined components, nothing else.
@ -62,7 +62,7 @@ installed
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
INSTALLATION *lualine_installation* INSTALLATION *lualine_installation*
VIM-PLUG *lualine_vim-plug* VIM-PLUG *lualine_vim-plug*
> >
Plug 'hoob3rt/lualine.nvim' Plug 'hoob3rt/lualine.nvim'
" If you want to have icons in your statusline choose one of these " If you want to have icons in your statusline choose one of these
@ -70,7 +70,7 @@ VIM-PLUG *lualine_vim-plug*
Plug 'ryanoasis/vim-devicons' Plug 'ryanoasis/vim-devicons'
< <
PACKER.NVIM *lualine_packer.nvim* PACKER.NVIM *lualine_packer.nvim*
> >
use { use {
'hoob3rt/lualine.nvim', 'hoob3rt/lualine.nvim',
@ -111,7 +111,7 @@ All available themes are listed in THEMES.md (./THEMES.md)
Please create a pr if you managed to port a popular theme before me, here is Please create a pr if you managed to port a popular theme before me, here is
how to do it (./CONTRIBUTING.md). how to do it (./CONTRIBUTING.md).
CHANGING SEPARATOR IN SECTION *lualine_changing_separator* CHANGING SEPARATOR IN SECTION *lualine_changing_separator*
Lualine defines two kinds of seperators. One is for sections and other is Lualine defines two kinds of seperators. One is for sections and other is
for components. Default section seperators are '', '' and component for components. Default section seperators are '', '' and component
@ -157,10 +157,10 @@ Lualine defaults~
Available components~ Available components~
general~ general~
* branch (git branch) * branch (git branch)
* diagnostics (diagnostics count from your prefered source) * diagnostics (diagnostics count from your prefered source)
* encoding (file encoding) * encoding (file encoding)
* fileformat (file format) * fileformat (file format)
* filename * filename
* filetype * filetype
* location (location in file in line:column format) * location (location in file in line:column format)
@ -170,7 +170,7 @@ Available components~
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
BUILDING YOUR COMPONENTS *lualine_custom_components* BUILDING YOUR COMPONENTS *lualine_custom_components*
Using custom functions as lualine component~ Using custom functions as lualine component~
@ -301,13 +301,13 @@ List of options are given below.
changes diagnostic's symbol characters. You can set one or more symbols changes diagnostic's symbol characters. You can set one or more symbols
for each level. for each level.
> >
{ {
'diagnostics', 'diagnostics',
symbols = { symbols = {
-- set the error symbol and use defaults for warn and info. -- set the error symbol and use defaults for warn and info.
error = '!!', error = '!!',
}, },
} }
< <
• filename~ • filename~
@ -371,7 +371,7 @@ Example:~
format = function(name) format = function(name)
-- Capitalize first charecter of filename to capital. -- Capitalize first charecter of filename to capital.
local path, fname = name:match('(.*/)(.*)') local path, fname = name:match('(.*/)(.*)')
if not path then path = ''; fname = name end if not path then path = ''; fname = name end
return path .. fname:sub(1, 1):upper() .. fname:sub(2, #fname) return path .. fname:sub(1, 1):upper() .. fname:sub(2, #fname)
end end
} }
@ -393,7 +393,7 @@ using a plugin which is supported you can load it this way:
All available extensions are listed in EXTENSIONS.md (./EXTENSIONS.md) All available extensions are listed in EXTENSIONS.md (./EXTENSIONS.md)
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
CONGIG EXAMPLES *lualine_config_examples* CONGIG EXAMPLES *lualine_config_examples*
FULL CONFIG EXAMPLE USING PACKER.NVIM *lualine_config_example_using_packer.nvim* FULL CONFIG EXAMPLE USING PACKER.NVIM *lualine_config_example_using_packer.nvim*
@ -404,31 +404,31 @@ packer config
'hoob3rt/lualine.nvim', 'hoob3rt/lualine.nvim',
requires = {'kyazdani42/nvim-web-devicons', opt = true}, requires = {'kyazdani42/nvim-web-devicons', opt = true},
config = function() config = function()
local lualine = require('lualine') require('lualine').status{
lualine.options = { options = {
theme = 'gruvbox', theme = 'gruvbox',
section_separators = {'', ''}, section_separators = {'', ''},
component_separators = {'', ''}, component_separators = {'', ''},
icons_enabled = true, icons_enabled = true,
} },
lualine.sections = { sections = {
lualine_a = { 'mode' }, lualine_a = { {'mode', upper = true} },
lualine_b = { 'branch' }, lualine_b = { {'branch', icon = ''} },
lualine_c = { 'filename' }, lualine_c = { {'filename', file_status = true} },
lualine_x = { 'encoding', 'fileformat', 'filetype' }, lualine_x = { 'encoding', 'fileformat', 'filetype' },
lualine_y = { 'progress' }, lualine_y = { 'progress' },
lualine_z = { 'location' }, lualine_z = { 'location' },
},
inactive_sections = {
lualine_a = { },
lualine_b = { },
lualine_c = { 'filename' },
lualine_x = { 'location' },
lualine_y = { },
lualine_z = { }
},
extensions = { 'fzf' }
} }
lualine.inactive_sections = {
lualine_a = { },
lualine_b = { },
lualine_c = { 'filename' },
lualine_x = { 'location' },
lualine_y = { },
lualine_z = { }
}
lualine.extensions = { 'fzf' }
lualine.status()
end end
} }
< <
@ -440,33 +440,32 @@ FULL CONFIG EXAMPLE INSIDE VIML *lualine_full_config_example_inside_viml*
vimrc config vimrc config
> >
lua << EOF let g:lualine = {
local lualine = require('lualine') \'options' : {
lualine.options = { \ 'theme' : 'gruvbox',
theme = 'gruvbox', \ 'section_separators' : ['', ''],
section_separators = {'', ''}, \ 'component_separators' : ['', ''],
component_separators = {'', ''}, \ 'icons_enabled' : v:true,
icons_enabled = true, \},
} \'sections' : {
lualine.sections = { \ 'lualine_a' : [ ['mode', {'upper': v:true,},], ],
lualine_a = { 'mode' }, \ 'lualine_b' : [ ['branch', {'icon': '',}, ], ],
lualine_b = { 'branch' }, \ 'lualine_c' : [ ['filename', {'file_status': v:true,},], ],
lualine_c = { 'filename' }, \ 'lualine_x' : [ 'encoding', 'fileformat', 'filetype' ],
lualine_x = { 'encoding', 'fileformat', 'filetype' }, \ 'lualine_y' : [ 'progress' ],
lualine_y = { 'progress' }, \ 'lualine_z' : [ 'location' ],
lualine_z = { 'location' }, \},
} \'inactive_sections' : {
lualine.inactive_sections = { \ 'lualine_a' : [ ],
lualine_a = { }, \ 'lualine_b' : [ ],
lualine_b = { }, \ 'lualine_c' : [ 'filename' ],
lualine_c = { 'filename' }, \ 'lualine_x' : [ 'location' ],
lualine_x = { 'location' }, \ 'lualine_y' : [ ],
lualine_y = { }, \ 'lualine_z' : [ ],
lualine_z = { } \},
} \'extensions' : [ 'fzf' ],
lualine.extensions = { 'fzf' } \}
lualine.status() lua require("lualine").status()
EOF
< <
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------

View File

@ -35,8 +35,33 @@ M.inactive_sections = {
lualine_z = { } 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 function check_single_separator()
local compoennt_separator = M.options.component_separators local compoennt_separator = M.options.component_separators
@ -271,7 +296,9 @@ local function exec_autocommands()
]], false) ]], false)
end end
function M.status() function M.status(config)
apply_configuration(vim.g.lualine)
apply_configuration(config)
check_single_separator() check_single_separator()
lualine_set_theme() lualine_set_theme()
exec_autocommands() exec_autocommands()

View File

@ -142,7 +142,7 @@ end
-- @param left_section_data :(string) section before separator -- @param left_section_data :(string) section before separator
-- @param right_section_data:(string) section after separator -- @param right_section_data:(string) section after separator
-- @param reverse :(string) Whether it's a left separator or right separator -- @param reverse :(string) Whether it's a left separator or right separator
-- '▶️' and '◀️' needs reverse colors so this parameter needs to be set true. -- '▶️' and '◀️' needs reverse colors so this parameter needs to be set true.
-- @return: (string) formated highlight group name -- @return: (string) formated highlight group name
function M.get_transitional_highlights(left_section_data, right_section_data, reverse ) function M.get_transitional_highlights(left_section_data, right_section_data, reverse )
local left_highlight_name, right_highlight_name local left_highlight_name, right_highlight_name
@ -168,16 +168,16 @@ function M.get_transitional_highlights(left_section_data, right_section_data, re
right_highlight_name = 'lualine_c_normal' right_highlight_name = 'lualine_c_normal'
end end
end end
-- When both left and right highlights are same nothing to transition to -- When both left and right highlights are same nothing to transition to
if left_highlight_name == right_highlight_name then return end if left_highlight_name == right_highlight_name then return end
-- construct the name of hightlight group -- construct the name of hightlight group
local highlight_name local highlight_name
if left_highlight_name:find('lualine_') == 1 then if left_highlight_name:find('lualine_') == 1 then
highlight_name = left_highlight_name .. '_to_' .. right_highlight_name highlight_name = left_highlight_name .. '_to_' .. right_highlight_name
else else
highlight_name = 'lualine_' .. left_highlight_name .. '_to_' .. right_highlight_name highlight_name = 'lualine_' .. left_highlight_name .. '_to_' .. right_highlight_name
end end
if not utils.highlight_exists(highlight_name) then if not utils.highlight_exists(highlight_name) then
-- Create the highlight_group if needed -- Create the highlight_group if needed
@ -188,12 +188,12 @@ function M.get_transitional_highlights(left_section_data, right_section_data, re
local bg = utils.extract_highlight_colors(right_highlight_name, 'guibg') local bg = utils.extract_highlight_colors(right_highlight_name, 'guibg')
if not fg then fg = 'none' end if not fg then fg = 'none' end
if not bg then bg = 'none' end if not bg then bg = 'none' end
-- swap the bg and fg when reverse is true. As in that case highlight will -- swap the bg and fg when reverse is true. As in that case highlight will
-- be placed before section -- be placed before section
if reverse then fg, bg = bg, fg end if reverse then fg, bg = bg, fg end
highlight(highlight_name, fg, bg) highlight(highlight_name, fg, bg)
end end
-- Create highlights and setup to survive colorscheme changes -- Create highlights and setup to survive colorscheme changes
set_transitional_highlights() set_transitional_highlights()
utils.expand_set_theme(set_transitional_highlights) utils.expand_set_theme(set_transitional_highlights)
end end