From d6758af65bc82109aab81efe3aec5bf70e5173b4 Mon Sep 17 00:00:00 2001 From: shadmansaleh Date: Tue, 6 Apr 2021 19:31:45 +0600 Subject: [PATCH 01/10] Feat: Add condition option --- README.md | 1 + doc/lualine.txt | 7 ++++++- lua/lualine/component.lua | 3 +++ 3 files changed, 10 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 8f97511..49f9830 100644 --- a/README.md +++ b/README.md @@ -200,6 +200,7 @@ right_padding | 1 | Adds padding to the right of components | all upper | false | Changes components to be uppercase | all lower | false | Changes components to be lowercase | all format | nil | Takes a function . The funtion gets the result of component as argument and it's return value is displayed. So this function can parse and format the output as user wants. | all +condition | nil | Takes a function. The component is loaded if the function returns true otherwise not. It can be used to load some comoonents on specific cases. | all ##### Global options example ```lua options = {icons_enabled = true} diff --git a/doc/lualine.txt b/doc/lualine.txt index 8271887..128779e 100644 --- a/doc/lualine.txt +++ b/doc/lualine.txt @@ -263,7 +263,12 @@ option (default_value) • icon (differs for each component) displays an icon infront of a component - • color (nil) + • condition (nil) + Takes a function. The component is loaded if the function + returns true otherwise not. It can be used to load some + comoonents on specific cases. + + • color (Theme colors) color option can be used to set custom color to a component Color format: `lua color = {fg = '#rrggbb', bg= '#rrggbb', gui='style'}` diff --git a/lua/lualine/component.lua b/lua/lualine/component.lua index 4ea5b54..2047527 100644 --- a/lua/lualine/component.lua +++ b/lua/lualine/component.lua @@ -118,6 +118,9 @@ local Component = { -- Driver code of the class draw = function(self, default_highlight) self.status = '' + if self.options.condition ~= nil and self.options.condition() ~= true then + return self.status + end local status = self:update_status() if self.options.format then status = self.options.format(status or '') end if type(status) == 'string' and #status > 0 then From 7c6d1f9074405d0e925dd25d84551ddeb47637e5 Mon Sep 17 00:00:00 2001 From: shadmansaleh Date: Tue, 6 Apr 2021 20:03:41 +0600 Subject: [PATCH 02/10] Update options section of docs . --- README.md | 69 +++++++++++++------ doc/lualine.txt | 179 ++++++++++++++++++++++++++++++------------------ 2 files changed, 160 insertions(+), 88 deletions(-) diff --git a/README.md b/README.md index 49f9830..84bb14a 100644 --- a/README.md +++ b/README.md @@ -185,35 +185,58 @@ sections = {lualine_a = {'g:coc_status', 'bo:filetype'}} ### Available options: +Options can change the way a component behave. +There are two kinds of options some that work on every kind of component. +Even the ones you create like custom function component . And some that only +work on specific component. +Detailed list of available options are given below. + #### Global options +These options are available for all components. -Global options change behaviour of all suported components. -All of these options can also be specifically set to all supported components, full example below. - -##### Available global options -Option | Default | Behaviour | Supported components -:------: | :------: | :----------: | :-----: +Option | Default | Behaviour | Supported components +:------: | :------: | :------: | :--------: icons_enabled | true | Displays icons on components You should have nerd-fonts supported fonts to see icons properly. | branch, fileformat, filetype, location, diagnostics -padding | 1 | Adds padding to the left and right of components | all -left_padding | 1 | Adds padding to the left of components | all -right_padding | 1 | Adds padding to the right of components | all -upper | false | Changes components to be uppercase | all -lower | false | Changes components to be lowercase | all -format | nil | Takes a function . The funtion gets the result of component as argument and it's return value is displayed. So this function can parse and format the output as user wants. | all -condition | nil | Takes a function. The component is loaded if the function returns true otherwise not. It can be used to load some comoonents on specific cases. | all -##### Global options example +icon | Differs for each component | Displays an icon in front of the component | All +padding | 1 | Adds padding to the left and right of components | All +left_padding | 1 | Adds padding to the left of components | All +right_padding | 1 | Adds padding to the right of components | All +separator | (component_separators) | which separator to use at end of component | all +upper | false | Changes components to be uppercase | All +lower | false | Changes components to be lowercase | All +format | nil | Takes a function . The funtion gets the result of component as argument and it's return value is displayed. So this function can parse and format the output as user wants. | All +condition | nil | Takes a function. The component is loaded if the function returns true otherwise not. It can be used to load some comoonents on specific cases. | All +color | nil | Sets custom color for the component in this format

`color = {fg = '#rrggbb', bg= '#rrggbb', gui='style'}`

The fields of color table are optional and default to theme | All + +#### Using global options +Global options can be set in two ways. One is as part of options table in setup. + ```lua -options = {icons_enabled = true} +require'lualine'.setup{ + options = { + icons_enabled = true, + padding = 2, + } +} +``` +When set this way these values work as default for all component. +These defaults can be overwritten by setting option as part of component +configuration like following. + +```lua +lualine_a = { + -- Displays only first char of mode name + {'mode', format=function(mode_name) return mode_name:sub(1,1) end}, + -- Disables icon for branch component + {'branch', icons_enabled=false}, +}, +lualine_c = { + -- Displays filename only when window is wider then 80 + {'filename', condition=function() return vim.fn.winwidth(0) > 80 end}, +} ``` #### Component specific options -As mentioned above, all global options can be applied to specific components. -However there are some options which are component-only (you cannot set them as globals) -Option | Default | Behaviour -:------: | :------: | :----: -icon | Differs for each component | Displays an icon in front of the component -color | nil | Sets custom color for the component in this format

`color = {fg = '#rrggbb', bg= '#rrggbb', gui='style'}`

The fields of color table are optional and default to theme - In addition, some components have unique options. * `diagnostics` component options @@ -246,6 +269,8 @@ color_removed | `DiffDelete` foreground color | changes diff's removed section f symbols | `{added = '+', modified = '~', removed = '-'}` | changes diff's symbols | table containing on or more symbols | +Component specific options can only be set with component configs. + ##### Component options example ```lua sections = { diff --git a/doc/lualine.txt b/doc/lualine.txt index 128779e..c58cbc3 100644 --- a/doc/lualine.txt +++ b/doc/lualine.txt @@ -163,7 +163,7 @@ Available components~ * fileformat (file format) * filename * filetype - * hostname + * hostname * location (location in file in line:column format) * mode (vim mode) * progress (%progress in file) @@ -208,11 +208,17 @@ CUSTOM OPTIONS FOR COMPONENTS *lualine_custom_options* Options for components~ ====================== -Global options~ ----------------------- +Available options:~ -Global options change behaviour of all suported components. -All of these options can also be specifically set to all supported components. +Options can change the way a component behave. +There are two kinds of options some that work on every kind of component. +Even the ones you create like custom function component . And some that only +work on specific component. +Detailed list of available options are given below. + +Global options~ + +These options are available for all components. option (default_value) ------ --------------- @@ -222,6 +228,10 @@ option (default_value) You should have nerd-fonts supported fonts to see icons properly. Supported components: branch, fileformat, filetype, location, diagnostics + • icon (depends on component) + displays an icon infront of a component + Supported components: all + • padding (1) spaces on left and right Supported components: all @@ -234,6 +244,10 @@ option (default_value) spaces on right Supported components: all + • separator (component_separators) + which separator to use at end of component + Supported components: all + • upper (false) Displayed in upper case Supported components: all @@ -275,6 +289,38 @@ option (default_value) the members of color table are optional and default to theme +Using global options~ + +Global options can be set in two ways. One is as part of options table in setup. + +> + require'lualine'.setup{ + options = { + icons_enabled = true, + padding = 2, + } + } +< +When set this way these values work as default for all component. +These defaults can be overwritten by setting option as part of component +configuration like following. + +> + lualine_a = { + -- Displays only first char of mode name + {'mode', format=function(mode_name) return mode_name:sub(1,1) end}, + -- Disables icon for branch component + {'branch', icons_enabled=false}, + }, + lualine_c = { + -- Displays filename only when window is wider then 80 + {'filename', condition=function() return vim.fn.winwidth(0) > 80 end}, + } +< + + +Component specific options~ + In addition, some components have unique options. • diagnostics~ @@ -352,25 +398,26 @@ In addition, some components have unique options. changes diff's symbols Color in `#rrggbb` format < +Component specific options can only be set with component configs. Example:~ > sections = { lualine_b = { - {'branch', icon = '', upper = true, color = {fg = '#00aa22'}}, { - 'filename', - full_name = true, - shorten = true, - format = function(name) - -- Capitalize first charecter of filename to capital. - local path, fname = name:match('(.*/)(.*)') - if not path then - path = ''; - fname = name - end - return path .. fname:sub(1, 1):upper() .. fname:sub(2, #fname) - end - } + {'branch', icon = '', upper = true, color = {fg = '#00aa22'}}, { + 'filename', + full_name = true, + shorten = true, + format = function(name) + -- Capitalize first charecter of filename to capital. + local path, fname = name:match('(.*/)(.*)') + if not path then + path = ''; + fname = name + end + return path .. fname:sub(1, 1):upper() .. fname:sub(2, #fname) + end + } } } ------------------------------------------------------------------------------- @@ -431,29 +478,29 @@ Lua config example requires = {'kyazdani42/nvim-web-devicons', opt = true}, config = function() require('lualine').setup{ - options = { - theme = 'gruvbox', - section_separators = {'', ''}, - component_separators = {'', ''}, - 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' } + options = { + theme = 'gruvbox', + section_separators = {'', ''}, + component_separators = {'', ''}, + 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' } } end } @@ -462,30 +509,30 @@ Lua config example Vimscript config example > let g:lualine = { - \'options' : { - \ 'theme' : 'gruvbox', - \ 'section_separators' : ['', ''], - \ 'component_separators' : ['', ''], - \ 'icons_enabled' : v:true, - \}, - \'sections' : { - \ 'lualine_a' : [ ['mode', {'upper': v:true,},], ], - \ 'lualine_b' : [ ['branch', {'icon': '',}, ], ], - \ 'lualine_c' : [ ['filename', {'file_status': v: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' ], - \} + \'options' : { + \ 'theme' : 'gruvbox', + \ 'section_separators' : ['', ''], + \ 'component_separators' : ['', ''], + \ 'icons_enabled' : v:true, + \}, + \'sections' : { + \ 'lualine_a' : [ ['mode', {'upper': v:true,},], ], + \ 'lualine_b' : [ ['branch', {'icon': '',}, ], ], + \ 'lualine_c' : [ ['filename', {'file_status': v: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' ], + \} lua require("lualine").setup() < ------------------------------------------------------------------------------- From 9e957e341e76d8cd4ca9d4e79e9e5f75a9b3dff5 Mon Sep 17 00:00:00 2001 From: shadmansaleh Date: Wed, 7 Apr 2021 00:05:14 +0600 Subject: [PATCH 03/10] Feat: Allow color option to accept highlight group --- README.md | 2 +- doc/lualine.txt | 8 ++++++-- lua/lualine/component.lua | 6 +++++- 3 files changed, 12 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 84bb14a..40770e2 100644 --- a/README.md +++ b/README.md @@ -206,7 +206,7 @@ upper | false | Changes components to be uppercase | All lower | false | Changes components to be lowercase | All format | nil | Takes a function . The funtion gets the result of component as argument and it's return value is displayed. So this function can parse and format the output as user wants. | All condition | nil | Takes a function. The component is loaded if the function returns true otherwise not. It can be used to load some comoonents on specific cases. | All -color | nil | Sets custom color for the component in this format

`color = {fg = '#rrggbb', bg= '#rrggbb', gui='style'}`

The fields of color table are optional and default to theme | All +color | nil | Sets custom color for the component in this format

`color = {fg = '#rrggbb', bg= '#rrggbb', gui='style'}`

The fields of color table are optional and default to theme

Color option can also be a string containing highlight group name `color = "WarningMsg"`. One neat trick set the color to highlight group name then change that highlight with :hi command to change color of that component at runtime. | All #### Using global options Global options can be set in two ways. One is as part of options table in setup. diff --git a/doc/lualine.txt b/doc/lualine.txt index c58cbc3..6674ce6 100644 --- a/doc/lualine.txt +++ b/doc/lualine.txt @@ -287,7 +287,11 @@ option (default_value) Color format: `lua color = {fg = '#rrggbb', bg= '#rrggbb', gui='style'}` the members of color table are optional and default to theme - + Color option can also be a string containing highlight group name > + color = "WarningMsg"` +< One neat trick set the color to highlight group name then change + that highlight with :hi command to change color of that component + at runtime. Using global options~ @@ -536,4 +540,4 @@ Vimscript config example lua require("lualine").setup() < ------------------------------------------------------------------------------- -vim:tw=80:sw=4:ts=8:noet:ft=help:norl:noet: +vim:tw=80:sw=4:ts=8:noet:ft=help:norl:et: diff --git a/lua/lualine/component.lua b/lua/lualine/component.lua index 2047527..47c236c 100644 --- a/lua/lualine/component.lua +++ b/lua/lualine/component.lua @@ -37,11 +37,13 @@ local Component = { create_option_highlights = function(self) -- set custom highlights - if self.options.color then + if type(self.options.color) == 'table' then self.options.color_highlight = highlight.create_component_highlight_group( self.options.color, self.options.component_name, self.options) + elseif type(self.options.color) == 'string' then + self.options.color_highlight_link = self.options.color end end, @@ -80,6 +82,8 @@ local Component = { if self.options.color_highlight then self.status = highlight.component_format_highlight( self.options.color_highlight) .. self.status + elseif self.options.color_highlight_link then + self.status = '%#' .. self.options.color_highlight_link ..'#'.. self.status end self.status = self.status .. default_highlight end, From f2d9d146716fb20048287b21fdfa8e3506cf9495 Mon Sep 17 00:00:00 2001 From: shadmansaleh Date: Wed, 7 Apr 2021 19:38:08 +0600 Subject: [PATCH 04/10] Doc: Add evil_lualine config and screenshot --- README.md | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/README.md b/README.md index 40770e2..cddd86f 100644 --- a/README.md +++ b/README.md @@ -24,6 +24,13 @@ Here is a preview of how lualine can look like. Screenshots of all available themes are listed in [THEMES.md](./THEMES.md) +For those who want to break the norms. You can create custom looks in lualine . + +**Example** : + +- [evil_lualine](https://gist.github.com/shadmansaleh/cd526bc166237a5cbd51429cc1f6291b) +![evil_lualine_image](https://user-images.githubusercontent.com/13149513/113875129-4453ba00-97d8-11eb-8f21-94a9ef565db3.png) + ## Performance compared to other plugins Unlike other statusline plugins lualine loads only defined components, nothing else. From 67d09890514ecbaed3df1d9be1f7ca438eabef14 Mon Sep 17 00:00:00 2001 From: shadmansaleh Date: Wed, 7 Apr 2021 21:25:02 +0600 Subject: [PATCH 05/10] Doc: Mention lightline theme converter --- CONTRIBUTING.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index df9f020..43762d5 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -12,6 +12,11 @@ please use lua-format before creating a pr :smile: * refer to example below to see how themes are defined * take 4 screenshots showing a different vim modes (normal, insert, visual, replace) * add your theme with screenshots attached to [THEMES.md](./THEMES.md) while maintaining alphabetical order +* If the colorscheme you're trying to add already support lightline. You can use +[lightline2lualine theme converter](https://gist.github.com/shadmansaleh/000871c9a608a012721c6acc6d7a19b9) to easily port the theme to lualine. + +**Note to colorscheme authors** : If you want to support lualine. You can put your +lualine theme at lua/lualine/themes/{your_colorscheme}.lua in you repo.
theme example From 82f68c42df9d11e52edb52c86113d0eba5be798d Mon Sep 17 00:00:00 2001 From: shadmansaleh Date: Thu, 8 Apr 2021 08:43:06 +0600 Subject: [PATCH 06/10] Enhance: Cterm colors only loaded when termguicolors = false --- lua/lualine/highlight.lua | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/lua/lualine/highlight.lua b/lua/lualine/highlight.lua index 80f5290..9ae4982 100644 --- a/lua/lualine/highlight.lua +++ b/lua/lualine/highlight.lua @@ -5,16 +5,21 @@ local utils_colors = require 'lualine.utils.cterm_colors' local utils = require 'lualine.utils.utils' local section_highlight_map = {x = 'c', y = 'b', z = 'a'} local active_theme = nil +local cterm_colors = false function M.highlight(name, foreground, background, gui, reload) local command = {'highlight', name} if foreground and foreground ~= 'none' then - table.insert(command, 'ctermfg=' .. utils_colors.get_cterm_color(foreground)) table.insert(command, 'guifg=' .. foreground) + if cterm_colors then + table.insert(command, 'ctermfg=' .. utils_colors.get_cterm_color(foreground)) + end end if background and background ~= 'none' then - table.insert(command, 'ctermbg=' .. utils_colors.get_cterm_color(background)) table.insert(command, 'guibg=' .. background) + if cterm_colors then + table.insert(command, 'ctermbg=' .. utils_colors.get_cterm_color(background)) + end end if gui then table.insert(command, 'cterm=' .. gui) @@ -29,6 +34,7 @@ end function M.create_highlight_groups(theme) utils.clear_highlights() active_theme = theme + cterm_colors = not vim.o.termguicolors for mode, sections in pairs(theme) do for section, colorscheme in pairs(sections) do local highlight_group_name = {'lualine', section, mode} From 287e5def31773f12f0f70bb2dcbdc9622e51b3ea Mon Sep 17 00:00:00 2001 From: shadmansaleh Date: Fri, 9 Apr 2021 17:34:22 +0600 Subject: [PATCH 07/10] Enhance: Stop modifying global state. v:lua.require is used insted of exposing function as global variable. --- lua/lualine/init.lua | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/lua/lualine/init.lua b/lua/lualine/init.lua index 13d30b1..d60df74 100644 --- a/lua/lualine/init.lua +++ b/lua/lualine/init.lua @@ -251,19 +251,17 @@ end local function set_tabline() if next(config.tabline) ~= nil then - _G.lualine_tabline = tabline - vim.o.tabline = '%!v:lua.lualine_tabline()' + vim.o.tabline = "%!v:lua.require'lualine'.tabline()" vim.o.showtabline = 2 end end local function set_statusline() if next(config.sections) ~= nil or next(config.inactive_sections) ~= nil then - _G.lualine_statusline = status_dispatch - vim.o.statusline = '%!v:lua.lualine_statusline()' + vim.o.statusline = "%!v:lua.require'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() + autocmd lualine WinLeave,BufLeave * lua vim.wo.statusline=require'lualine'.statusline() + autocmd lualine WinEnter,BufEnter * set statusline< ]], false) end end @@ -279,4 +277,8 @@ local function setup(user_config) set_tabline() end -return {setup = setup} +return { + setup = setup, + statusline = status_dispatch, + tabline = tabline, +} From 77c4c4748254cd6087c6cc1e8be72485d278eb48 Mon Sep 17 00:00:00 2001 From: shadmansaleh Date: Mon, 12 Apr 2021 12:14:43 +0600 Subject: [PATCH 08/10] Enhance: Cleanup eval_lua component and document it --- README.md | 18 ++++++++++++++++- doc/lualine.txt | 20 ++++++++++++++++--- .../special/eval_func_component.lua | 15 +++----------- 3 files changed, 37 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index cddd86f..0d15869 100644 --- a/README.md +++ b/README.md @@ -177,7 +177,7 @@ sections = {lualine_a = {'FugitiveHead'}}
Using variables as lualine component -You can use variables from vim and lua globals as a lualine component +You can use variables from vim a lualine component Variables from g:, v:, t:, w:, b:, o, go:, vo:, to:, wo:, bo: scopes can be used. Scopes ending with o are options usualy accessed with `&` in vimscript @@ -187,6 +187,22 @@ sections = {lualine_a = {'g:coc_status', 'bo:filetype'}}
+
+Using lua expressions as lualine component + +You can use any valid lua expression as a component . This allows global +variables to be used as a component too. Even require statements can be used to access values returned by specific scripts. +One liner functions can be inlined by utilizeing this . + +For exmaple this will show day of the week. +And 2nd one will display current value of global variabke data. + +```lua +sections = {lualine_c = {"os.data('%a')", 'data'}} +``` + +
+
Options for components diff --git a/doc/lualine.txt b/doc/lualine.txt index 6674ce6..c7c28b4 100644 --- a/doc/lualine.txt +++ b/doc/lualine.txt @@ -193,13 +193,27 @@ You can use vim functions as a lualine component Using variables as lualine component~ -You can use variables from vim and lua globals as a lualine component -Variables from g:, v:, t:, w:, b:, o, go:, vo:, to:, wo:, bo: scopes -can be used. Scopes ending with o are options usualy accessed with `&` in vimscript +You can use variables from vim. Variables from g:, v:, t:, +w:, b:, o, go:, vo:, to:, wo:, bo: scopes can be used. +Scopes ending with o are options usualy accessed with `&` in +vimscript > sections = {lualine_a = {'g:coc_status', 'bo:filetype'}} < +Using lua expressions as lualine component~ + +You can use any valid lua expression as a component . This +allows global variables to be used as a component too. Even +require statements can be used to access values returned by +specific scripts. One liner functions can be inlined by +utilizeing this . + +For exmaple this will show day of the week. And 2nd one +will display current value of global variabke data. +> + sections = {lualine_c = {"os.data('%a')", 'data'}} +< -------------------------------------------------------------------------------- CUSTOM OPTIONS FOR COMPONENTS *lualine_custom_options* diff --git a/lua/lualine/components/special/eval_func_component.lua b/lua/lualine/components/special/eval_func_component.lua index 93e1234..0cae2c4 100644 --- a/lua/lualine/components/special/eval_func_component.lua +++ b/lua/lualine/components/special/eval_func_component.lua @@ -2,22 +2,13 @@ local EvalFuncComponent = require('lualine.component'):new() EvalFuncComponent.update_status = function(self) local component = self.options[1] - local ok, status = EvalFuncComponent.evallua(component) + local ok, status = pcall(EvalFuncComponent.eval_lua, component) if not ok then status = EvalFuncComponent.vim_function(component) end return status end -EvalFuncComponent.evallua = function(code) - if loadstring(string.format('return %s ~= nil', code)) and - loadstring(string.format([[return %s ~= nil]], code))() then - -- lua veriable component - return true, loadstring(string.format( - [[ - local ok, return_val = pcall(tostring, %s) - if ok then return return_val end - return '']], code))() - end - return false, '' +EvalFuncComponent.eval_lua = function(code) + return tostring(loadstring('return '..code)()) end EvalFuncComponent.vim_function = function(name) From 5647a845bb6edc674f26bc8a7710aad716b49e42 Mon Sep 17 00:00:00 2001 From: shadmansaleh Date: Mon, 12 Apr 2021 12:25:21 +0600 Subject: [PATCH 09/10] Doc: Document theme tweeking --- README.md | 22 ++++++++++++++++++++++ doc/lualine.txt | 19 +++++++++++++++++++ 2 files changed, 41 insertions(+) diff --git a/README.md b/README.md index 0d15869..f0db0ee 100644 --- a/README.md +++ b/README.md @@ -88,6 +88,28 @@ 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 how to do it](./CONTRIBUTING.md). +
+Tweeking themes + +You like a theme but would like to tweek some colors. +You can do that in your config easily. + +Example: +```lua +local custom_gruvbox = require'lualine.themes.gruvbox' + +-- Chnage the background of lualine_c section for normal mode +custom_gruvbox.normal.c.bg = '#112233' -- rgb colors are supported + +require'lualine'.setup{ + options = { theme = custom_gruvbox }, + ... +} +``` +You can checkout structure of a lualine theme [here](https://github.com/hoob3rt/lualine.nvim/blob/master/CONTRIBUTING.md#adding-a-theme) + +
+ ### Changing separators Lualine defines two kinds of seperators. One is for sections and other is for components. Default section seperators are '', '' and component separators are '', ''. They require powerline patched fonts. But you can easily change yours to something else like below diff --git a/doc/lualine.txt b/doc/lualine.txt index c7c28b4..81a626f 100644 --- a/doc/lualine.txt +++ b/doc/lualine.txt @@ -111,6 +111,25 @@ 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 how to do it (./CONTRIBUTING.md). +Tweeking themes~ + +You like a theme but would like to tweek some colors. +You can do that in your config easily. + +Example: +> + local custom_gruvbox = require'lualine.themes.gruvbox' + + -- Chnage the background of lualine_c section for normal mode + custom_gruvbox.normal.c.bg = '#112233' -- rgb colors are supported + + require'lualine'.setup{ + options = { theme = custom_gruvbox }, + ... + } +< +You can checkout structure of a lualine theme [here](https://github.com/hoob3rt/lualine.nvim/blob/master/CONTRIBUTING.md#adding-a-theme) + CHANGING SEPARATOR IN SECTION *lualine_changing_separator* Lualine defines two kinds of seperators. One is for sections and other is From 838cd66bc03171098e3171480f55999169798c91 Mon Sep 17 00:00:00 2001 From: shadmansaleh Date: Mon, 12 Apr 2021 12:58:54 +0600 Subject: [PATCH 10/10] GenHelpTags --- doc/tags | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/doc/tags b/doc/tags index b37c93a..b852ebf 100644 --- a/doc/tags +++ b/doc/tags @@ -14,7 +14,7 @@ lualine_loading_plugin_extensions lualine.txt /*lualine_loading_plugin_extension lualine_lualine.nvim lualine.txt /*lualine_lualine.nvim* lualine_nvim lualine.txt /*lualine_nvim* lualine_packer.nvim lualine.txt /*lualine_packer.nvim* -lualine_performance_comparism lualine.txt /*lualine_performance_comparism* +lualine_performance_comparison lualine.txt /*lualine_performance_comparison* lualine_screenshots lualine.txt /*lualine_screenshots* lualine_setting_theme lualine.txt /*lualine_setting_theme* lualine_starting_lualine lualine.txt /*lualine_starting_lualine*