feat: add tabline support (#92)

This commit is contained in:
Shadman 2021-03-06 21:03:00 +06:00 committed by GitHub
parent 9c9212c5b6
commit 332f488e24
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 123 additions and 41 deletions

View File

@ -274,6 +274,33 @@ lualine.sections.lualine_b = {
</details> </details>
### Using tabline as statusline
You can use lualine to display components in tabline .
The sections, configurations and highlights are same as statusline.
```
lualine.tabline = {
lualine_a = { },
lualine_b = { 'branch' },
lualine_c = { 'filename' },
lualine_x = { },
lualine_y = { },
lualine_z = { },
}
```
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
```
lualine.tabline = {
......
}
lualine.sections = {}
lualine.inactive_sections = {}
```
### 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)

View File

@ -37,10 +37,11 @@ CONTENTS *lualine_contents*
1.3.4. Changing components.................|lualine_changing_components| 1.3.4. Changing components.................|lualine_changing_components|
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. Using tabline as statusline...............|lualine_using_tabline|
1.3.8 Config examples.........................|lualine_config_examples| 1.3.8. Loading plugin extensions.....|lualine_loading_plugin_extensions|
1.3.8.1. Packer.nvim......|lualine_config_example_using_packer.nvim| 1.3.9 Config examples.........................|lualine_config_examples|
1.3.8.2 VIML example.......|lualine_full_config_example_inside_viml| 1.3.9.1. Packer.nvim......|lualine_config_example_using_packer.nvim|
1.3.9.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|
@ -346,13 +347,13 @@ List of options are given below.
Changes diff's symbol characters. You can set some symbols partly. Changes diff's symbol characters. You can set some symbols partly.
Color in #rrggbb format Color in #rrggbb format
> >
{ {
'diff', 'diff',
-- set the added symbol and use defaults for modified and removed. -- set the added symbol and use defaults for modified and removed.
symbols = { symbols = {
added = 'A', added = 'A',
}, },
} }
< <
Example:~ Example:~
@ -376,7 +377,34 @@ Example:~
end end
} }
} }
-------------------------------------------------------------------------------
USING TABLINE AS STATUSLINE *lualine_using_tabline*
You can use lualine to display components in tabline .
The sections, configurations and highlights are same as statusline.
>
lualine.tabline = {
lualine_a = { },
lualine_b = { 'branch' },
lualine_c = { 'filename' },
lualine_x = { },
lualine_y = { },
lualine_z = { },
}
< <
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
>
lualine.tabline = {
......
}
lualine.sections = {}
lualine.inactive_sections = {}
<
-------------------------------------------------------------------------------- --------------------------------------------------------------------------------
LOADING PLUGIN EXTENSIONS *lualine_loading_plugin_extensions* LOADING PLUGIN EXTENSIONS *lualine_loading_plugin_extensions*
@ -441,30 +469,30 @@ FULL CONFIG EXAMPLE INSIDE VIML *lualine_full_config_example_inside_viml*
vimrc config vimrc config
> >
let g:lualine = { let g:lualine = {
\'options' : { \'options' : {
\ 'theme' : 'gruvbox', \ 'theme' : 'gruvbox',
\ 'section_separators' : ['', ''], \ 'section_separators' : ['', ''],
\ 'component_separators' : ['', ''], \ 'component_separators' : ['', ''],
\ 'icons_enabled' : v:true, \ 'icons_enabled' : v:true,
\}, \},
\'sections' : { \'sections' : {
\ 'lualine_a' : [ ['mode', {'upper': v:true,},], ], \ 'lualine_a' : [ ['mode', {'upper': v:true,},], ],
\ 'lualine_b' : [ ['branch', {'icon': '',}, ], ], \ 'lualine_b' : [ ['branch', {'icon': '',}, ], ],
\ 'lualine_c' : [ ['filename', {'file_status': v:true,},], ], \ 'lualine_c' : [ ['filename', {'file_status': v: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' : { \'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' ], \'extensions' : [ 'fzf' ],
\} \}
lua require("lualine").status() lua require("lualine").status()
< <

View File

@ -19,4 +19,5 @@ lualine_screenshots lualine.txt /*lualine_screenshots*
lualine_setting_theme lualine.txt /*lualine_setting_theme* lualine_setting_theme lualine.txt /*lualine_setting_theme*
lualine_starting_lualine lualine.txt /*lualine_starting_lualine* lualine_starting_lualine lualine.txt /*lualine_starting_lualine*
lualine_usage_and_customization lualine.txt /*lualine_usage_and_customization* lualine_usage_and_customization lualine.txt /*lualine_usage_and_customization*
lualine_using_tabline lualine.txt /*lualine_using_tabline*
lualine_vim-plug lualine.txt /*lualine_vim-plug* lualine_vim-plug lualine.txt /*lualine_vim-plug*

View File

@ -35,6 +35,8 @@ M.inactive_sections = {
lualine_z = { } lualine_z = { }
} }
M.tabline = {}
M.extensions = { } M.extensions = { }
local function apply_configuration(config_table) local function apply_configuration(config_table)
@ -59,6 +61,7 @@ local function apply_configuration(config_table)
parse_sections('options') parse_sections('options')
parse_sections('sections') parse_sections('sections')
parse_sections('inactive_sections') parse_sections('inactive_sections')
parse_sections('tabline')
if config_table.extensions then M.extensions = config_table.extensions end if config_table.extensions then M.extensions = config_table.extensions end
end end
@ -168,6 +171,7 @@ local function load_components()
end end
load_sections(M.sections) load_sections(M.sections)
load_sections(M.inactive_sections) load_sections(M.inactive_sections)
load_sections(M.tabline)
end end
local function load_extensions() local function load_extensions()
@ -283,27 +287,49 @@ local function status_dispatch()
end end
end end
local function exec_autocommands() local function tabline()
return statusline(M.tabline, true)
end
local function setup_theme()
lualine_set_theme()
_G.lualine_set_theme = lualine_set_theme _G.lualine_set_theme = lualine_set_theme
_G.lualine_statusline = status_dispatch
vim.api.nvim_exec([[ vim.api.nvim_exec([[
augroup lualine augroup lualine
autocmd! autocmd!
autocmd ColorScheme * call v:lua.lualine_set_theme() autocmd ColorScheme * call v:lua.lualine_set_theme()
autocmd WinLeave,BufLeave * lua vim.wo.statusline=lualine_statusline()
autocmd WinEnter,BufEnter * setlocal statusline=%!v:lua.lualine_statusline()
augroup END augroup END
]], false) ]], false)
end end
local function set_tabline()
if next(M.tabline) ~= nil then
_G.lualine_tabline = tabline
vim.o.tabline = '%!v:lua.lualine_tabline()'
vim.o.showtabline = 2
end
end
local function set_statusline()
if next(M.sections) ~= nil or next(M.inactive_sections) ~= nil then
_G.lualine_statusline = status_dispatch
vim.o.statusline = '%!v:lua.lualine_statusline()'
vim.api.nvim_exec([[
autocmd lualine WinLeave,BufLeave * lua vim.wo.statusline=lualine_statusline()
autocmd lualine WinEnter,BufEnter * setlocal statusline=%!v:lua.lualine_statusline()
]], false)
end
end
function M.status(config) function M.status(config)
apply_configuration(vim.g.lualine) apply_configuration(vim.g.lualine)
apply_configuration(config) apply_configuration(config)
check_single_separator() check_single_separator()
lualine_set_theme() setup_theme()
exec_autocommands()
load_components() load_components()
load_extensions() load_extensions()
set_statusline()
set_tabline()
end end
return M return M