Refactor: simplify options (#24)
* Deprecate upper & lower option. These does not make much sense and `format` option can provide same results * Unify padding options * Add persistent notices * Make separators use left/right keys to specify left right instead of sequence * Rename format -> fmt * Rename condition -> cond * Rename disable_text -> icon_only * Unify color_error,warning,info,hint under diagnostics_color * Unify color_added,modified,removed hint under diff_color
This commit is contained in:
parent
62bfe80fb6
commit
2f801ed622
57
README.md
57
README.md
|
@ -99,8 +99,8 @@ require'lualine'.setup {
|
|||
options = {
|
||||
icons_enabled = true,
|
||||
theme = 'auto',
|
||||
component_separators = {'', ''},
|
||||
section_separators = {'', ''},
|
||||
component_separators = { left = '', right = ''},
|
||||
section_separators = { left = '', right = ''},
|
||||
disabled_filetypes = {}
|
||||
},
|
||||
sections = {
|
||||
|
@ -181,11 +181,14 @@ Lualine defines two kinds of separators:
|
|||
|
||||
```lua
|
||||
options = {
|
||||
section_separators = {'', ''},
|
||||
component_separators = {'', ''}
|
||||
section_separators = { left = '', right = ''},
|
||||
component_separators = { left = '', right = ''}
|
||||
}
|
||||
```
|
||||
|
||||
Here left means it'll be used for left sections (a, b, c) and right means
|
||||
it'll be used for right sections (x, y, z).
|
||||
|
||||
<details><summary>Disabling separators</summary>
|
||||
|
||||
```lua
|
||||
|
@ -278,12 +281,16 @@ but you cannot use local options as global.
|
|||
Global option used locally overwrites the global, for example:
|
||||
```lua
|
||||
require'lualine'.setup {
|
||||
options = {lower = true},
|
||||
sections = {lualine_a = {{'mode', lower = false}}, lualine_b = {'branch'}}
|
||||
options = {fmt = string.lower},
|
||||
sections = {lualine_a = {
|
||||
{'mode', fmt = function(str) return str:sub(1,1) end}},
|
||||
lualine_b = {'branch'}}
|
||||
}
|
||||
```
|
||||
|
||||
`mode` will be displayed with `lower = false` and `branch` will be displayed with `lower = true`
|
||||
`mode` will be formatted with the passed fa=unction so only first char will be
|
||||
shown . On the other hand branch will be formatted with global formatter
|
||||
`string.lower` so it will be showed in lower case.
|
||||
|
||||
#### Available options
|
||||
|
||||
|
@ -294,11 +301,9 @@ Global option used locally overwrites the global, for example:
|
|||
options = {
|
||||
icons_enabled = true, -- displays icons in alongside component
|
||||
padding = 1, -- adds padding to the left and right of components
|
||||
left_padding = 1, -- adds padding to the left of components
|
||||
right_padding =1, -- adds padding to the right of components
|
||||
upper = false, -- displays components in uppercase
|
||||
lower = false, -- displays components in lowercase
|
||||
format = nil -- format function, formats component's output
|
||||
-- padding can be specified to left or right separately like
|
||||
-- padding = { left = left_padding, right = right_padding }
|
||||
fmt = nil -- fmt function, formats component's output
|
||||
}
|
||||
```
|
||||
|
||||
|
@ -317,10 +322,12 @@ sections = {
|
|||
-- when a string is given it's treated as component_separator.
|
||||
-- When a table is given it's treated as section_separator.
|
||||
-- This options can be used to set colored separators
|
||||
-- arround component. Option need to be set like `separator = {'', ''}`.
|
||||
-- Where first element is left_separator and 2nd element is right separator.
|
||||
-- arround component. Option need to be set like
|
||||
-- `separator = { left = '', right = ''}`.
|
||||
-- Where left will be placed in left side of component
|
||||
-- and right will be placed in right side of component
|
||||
-- Passing empty string disables that separator
|
||||
condition = nil, -- condition function, component is loaded when function returns true
|
||||
cond = nil, -- condition function, component is loaded when function returns true
|
||||
-- custom color for component in format
|
||||
-- color = {fg = '#rrggbb', bg= '#rrggbb', gui='style'}
|
||||
-- or highlight group
|
||||
|
@ -358,10 +365,12 @@ sections = {
|
|||
-- displays diagnostics from defined severity
|
||||
sections = {'error', 'warn', 'info', 'hint'},
|
||||
-- all colors are in format #rrggbb
|
||||
color_error = nil, -- changes diagnostic's error foreground color
|
||||
color_warn = nil, -- changes diagnostic's warn foreground color
|
||||
color_info = nil, -- Changes diagnostic's info foreground color
|
||||
color_hint = nil, -- Changes diagnostic's hint foreground color
|
||||
diagnostics_color = {
|
||||
error = nil, -- changes diagnostic's error foreground color
|
||||
warn = nil, -- changes diagnostic's warn foreground color
|
||||
info = nil, -- Changes diagnostic's info foreground color
|
||||
hint = nil, -- Changes diagnostic's hint foreground color
|
||||
}
|
||||
symbols = {error = 'E', warn = 'W', info = 'I', hint = 'H'}
|
||||
update_in_insert = false, -- Update diagnostics in insert mode
|
||||
}
|
||||
|
@ -393,7 +402,7 @@ sections = {
|
|||
{
|
||||
'filetype',
|
||||
colored = true, -- displays filetype icon in color if set to `true
|
||||
disable_text = false -- Display only icon for filetype
|
||||
icon_only = false -- Display only icon for filetype
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -408,9 +417,11 @@ sections = {
|
|||
'diff',
|
||||
colored = true, -- displays diff status in color if set to true
|
||||
-- all colors are in format #rrggbb
|
||||
color_added = nil, -- changes diff's added foreground color
|
||||
color_modified = nil, -- changes diff's modified foreground color
|
||||
color_removed = nil, -- changes diff's removed foreground color
|
||||
diff_color = {
|
||||
added = nil, -- changes diff's added foreground color
|
||||
modified = nil, -- changes diff's modified foreground color
|
||||
removed = nil, -- changes diff's removed foreground color
|
||||
}
|
||||
symbols = {added = '+', modified = '~', removed = '-'} -- changes diff symbols
|
||||
source = nil, -- A function that works as a data source for diff.
|
||||
-- it must return a table like
|
||||
|
|
|
@ -83,8 +83,8 @@ Default config
|
|||
options = {
|
||||
icons_enabled = true,
|
||||
theme = 'auto',
|
||||
component_separators = {'', ''},
|
||||
section_separators = {'', ''},
|
||||
component_separators = { left = '', right = ''},
|
||||
section_separators = { left = '', right = ''},
|
||||
disabled_filetypes = {}
|
||||
},
|
||||
sections = {
|
||||
|
@ -169,12 +169,15 @@ Lualine defines two kinds of separators:
|
|||
|
||||
>
|
||||
options = {
|
||||
section_separators = {'', ''},
|
||||
component_separators = {'', ''}
|
||||
section_separators = { left = '', right = ''},
|
||||
component_separators = { left = '', right = ''}
|
||||
}
|
||||
<
|
||||
|
||||
|
||||
Here left means it’ll be used for left sections (a, b, c) and right means
|
||||
it’ll be used for right sections (x, y, z).
|
||||
|
||||
Disabling separators
|
||||
|
||||
>
|
||||
|
@ -273,14 +276,17 @@ locally overwrites the global, for example:
|
|||
|
||||
>
|
||||
require'lualine'.setup {
|
||||
options = {lower = true},
|
||||
sections = {lualine_a = {{'mode', lower = false}}, lualine_b = {'branch'}}
|
||||
options = {fmt = string.lower},
|
||||
sections = {lualine_a = {
|
||||
{'mode', fmt = function(str) return str:sub(1,1) end}},
|
||||
lualine_b = {'branch'}}
|
||||
}
|
||||
<
|
||||
|
||||
|
||||
`mode` will be displayed with `lower = false` and `branch` will be displayed
|
||||
with `lower = true`
|
||||
`mode` will be formatted with the passed fa=unction so only first char will be
|
||||
shown. On the other hand branch will be formatted with global formatter
|
||||
`string.lower` so it will be showed in lower case.
|
||||
|
||||
*lualine-Available-options*
|
||||
|
||||
|
@ -290,11 +296,9 @@ Global options ~
|
|||
options = {
|
||||
icons_enabled = true, -- displays icons in alongside component
|
||||
padding = 1, -- adds padding to the left and right of components
|
||||
left_padding = 1, -- adds padding to the left of components
|
||||
right_padding =1, -- adds padding to the right of components
|
||||
upper = false, -- displays components in uppercase
|
||||
lower = false, -- displays components in lowercase
|
||||
format = nil -- format function, formats component's output
|
||||
-- padding can be specified to left or right separately like
|
||||
-- padding = { left = left_padding, right = right_padding }
|
||||
fmt = nil -- fmt function, formats component's output
|
||||
}
|
||||
<
|
||||
|
||||
|
@ -311,10 +315,12 @@ Local options ~
|
|||
-- when a string is given it's treated as component_separator.
|
||||
-- When a table is given it's treated as section_separator.
|
||||
-- This options can be used to set colored separators
|
||||
-- arround component. Option need to be set like `separator = {'', ''}`.
|
||||
-- Where first element is left_separator and 2nd element is right separator.
|
||||
-- arround component. Option need to be set like
|
||||
-- `separator = { left = '', right = ''}`.
|
||||
-- Where left will be placed in left side of component
|
||||
-- and right will be placed in right side of component
|
||||
-- Passing empty string disables that separator
|
||||
condition = nil, -- condition function, component is loaded when function returns true
|
||||
cond = nil, -- condition function, component is loaded when function returns true
|
||||
-- custom color for component in format
|
||||
-- color = {fg = '#rrggbb', bg= '#rrggbb', gui='style'}
|
||||
-- or highlight group
|
||||
|
@ -350,10 +356,12 @@ Component specific local options ~
|
|||
-- displays diagnostics from defined severity
|
||||
sections = {'error', 'warn', 'info', 'hint'},
|
||||
-- all colors are in format #rrggbb
|
||||
color_error = nil, -- changes diagnostic's error foreground color
|
||||
color_warn = nil, -- changes diagnostic's warn foreground color
|
||||
color_info = nil, -- Changes diagnostic's info foreground color
|
||||
color_hint = nil, -- Changes diagnostic's hint foreground color
|
||||
diagnostics_color = {
|
||||
error = nil, -- changes diagnostic's error foreground color
|
||||
warn = nil, -- changes diagnostic's warn foreground color
|
||||
info = nil, -- Changes diagnostic's info foreground color
|
||||
hint = nil, -- Changes diagnostic's hint foreground color
|
||||
}
|
||||
symbols = {error = 'E', warn = 'W', info = 'I', hint = 'H'}
|
||||
update_in_insert = false, -- Update diagnostics in insert mode
|
||||
}
|
||||
|
@ -387,7 +395,7 @@ Component specific local options ~
|
|||
{
|
||||
'filetype',
|
||||
colored = true, -- displays filetype icon in color if set to `true
|
||||
disable_text = false -- Display only icon for filetype
|
||||
icon_only = false -- Display only icon for filetype
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -403,9 +411,11 @@ Component specific local options ~
|
|||
'diff',
|
||||
colored = true, -- displays diff status in color if set to true
|
||||
-- all colors are in format #rrggbb
|
||||
color_added = nil, -- changes diff's added foreground color
|
||||
color_modified = nil, -- changes diff's modified foreground color
|
||||
color_removed = nil, -- changes diff's removed foreground color
|
||||
diff_color = {
|
||||
added = nil, -- changes diff's added foreground color
|
||||
modified = nil, -- changes diff's modified foreground color
|
||||
removed = nil, -- changes diff's removed foreground color
|
||||
}
|
||||
symbols = {added = '+', modified = '~', removed = '-'} -- changes diff symbols
|
||||
source = nil, -- A function that works as a data source for diff.
|
||||
-- it must return a table like
|
||||
|
|
|
@ -35,18 +35,18 @@ require('lualine').setup {
|
|||
options = {
|
||||
theme = bubbles_theme,
|
||||
component_separators = '|',
|
||||
section_separators = { '', '' },
|
||||
section_separators = { left = '', right = '' },
|
||||
},
|
||||
sections = {
|
||||
lualine_a = {
|
||||
{ 'mode', separator = { '', '' }, right_padding = 2 },
|
||||
{ 'mode', separator = { left = '' }, right_padding = 2 },
|
||||
},
|
||||
lualine_b = { 'filename', 'branch' },
|
||||
lualine_c = { 'fileformat' },
|
||||
lualine_x = {},
|
||||
lualine_y = { 'filetype', 'progress' },
|
||||
lualine_z = {
|
||||
{ 'location', separator = { '', '' }, left_padding = 2 },
|
||||
{ 'location', separator = { right = '' }, left_padding = 2 },
|
||||
},
|
||||
},
|
||||
inactive_sections = {
|
||||
|
|
|
@ -83,7 +83,7 @@ ins_left {
|
|||
return '▊'
|
||||
end,
|
||||
color = { fg = colors.blue }, -- Sets highlighting of component
|
||||
left_padding = 0, -- We don't need space before this
|
||||
padding = { left = 0, right = 1 }, -- We don't need space before this
|
||||
}
|
||||
|
||||
ins_left {
|
||||
|
@ -116,18 +116,18 @@ ins_left {
|
|||
return ''
|
||||
end,
|
||||
color = 'LualineMode',
|
||||
left_padding = 0,
|
||||
padding = { right = 1 },
|
||||
}
|
||||
|
||||
ins_left {
|
||||
-- filesize component
|
||||
'filesize',
|
||||
condition = conditions.buffer_not_empty,
|
||||
cond = conditions.buffer_not_empty,
|
||||
}
|
||||
|
||||
ins_left {
|
||||
'filename',
|
||||
condition = conditions.buffer_not_empty,
|
||||
cond = conditions.buffer_not_empty,
|
||||
color = { fg = colors.magenta, gui = 'bold' },
|
||||
}
|
||||
|
||||
|
@ -139,9 +139,11 @@ ins_left {
|
|||
'diagnostics',
|
||||
sources = { 'nvim_lsp' },
|
||||
symbols = { error = ' ', warn = ' ', info = ' ' },
|
||||
diagnostics_color = {
|
||||
color_error = { fg = colors.red },
|
||||
color_warn = { fg = colors.yellow },
|
||||
color_info = { fg = colors.cyan },
|
||||
},
|
||||
}
|
||||
|
||||
-- Insert mid section. You can make any number of sections in neovim :)
|
||||
|
@ -176,14 +178,14 @@ ins_left {
|
|||
-- Add components to right sections
|
||||
ins_right {
|
||||
'o:encoding', -- option component same as &encoding in viml
|
||||
upper = true, -- I'm not sure why it's upper case either ;)
|
||||
condition = conditions.hide_in_width,
|
||||
fmt = string.upper, -- I'm not sure why it's upper case either ;)
|
||||
cond = conditions.hide_in_width,
|
||||
color = { fg = colors.green, gui = 'bold' },
|
||||
}
|
||||
|
||||
ins_right {
|
||||
'fileformat',
|
||||
upper = true,
|
||||
fmt = string.upper,
|
||||
icons_enabled = false, -- I think icons are cool but Eviline doesn't have them. sigh
|
||||
color = { fg = colors.green, gui = 'bold' },
|
||||
}
|
||||
|
@ -191,7 +193,7 @@ ins_right {
|
|||
ins_right {
|
||||
'branch',
|
||||
icon = '',
|
||||
condition = conditions.check_git_workspace,
|
||||
cond = conditions.check_git_workspace,
|
||||
color = { fg = colors.violet, gui = 'bold' },
|
||||
}
|
||||
|
||||
|
@ -199,10 +201,12 @@ ins_right {
|
|||
'diff',
|
||||
-- Is it me or the symbol for modified us really weird
|
||||
symbols = { added = ' ', modified = '柳 ', removed = ' ' },
|
||||
color_added = { fg = colors.green },
|
||||
color_modified = { fg = colors.orange },
|
||||
color_removed = { fg = colors.red },
|
||||
condition = conditions.hide_in_width,
|
||||
diff_color = {
|
||||
added = { fg = colors.green },
|
||||
modified = { fg = colors.orange },
|
||||
removed = { fg = colors.red },
|
||||
},
|
||||
cond = conditions.hide_in_width,
|
||||
}
|
||||
|
||||
ins_right {
|
||||
|
@ -210,7 +214,7 @@ ins_right {
|
|||
return '▊'
|
||||
end,
|
||||
color = { fg = colors.blue },
|
||||
right_padding = 0,
|
||||
padding = { left = 1 },
|
||||
}
|
||||
|
||||
-- Now don't forget to initialize lualine
|
||||
|
|
|
@ -5,6 +5,28 @@ local highlight = require 'lualine.highlight'
|
|||
-- Used to provide a unique id for each component
|
||||
local component_no = 1
|
||||
|
||||
local function check_deprecated_options(options)
|
||||
local function rename_notice(before, now)
|
||||
if options[before] then
|
||||
require('lualine.utils.notices').add_notice(string.format(
|
||||
[[
|
||||
### option.%s
|
||||
%s option has been renamed to `%s`. Please use `%s` instead in your config
|
||||
for %s component.
|
||||
]],
|
||||
before,
|
||||
before,
|
||||
now,
|
||||
now,
|
||||
options.component_name or 'function'
|
||||
))
|
||||
options[now] = options[before]
|
||||
options[before] = nil
|
||||
end
|
||||
end
|
||||
rename_notice('format', 'fmt')
|
||||
rename_notice('condition', 'cond')
|
||||
end
|
||||
local Component = {
|
||||
-- Creates a new component
|
||||
new = function(self, options, child)
|
||||
|
@ -15,6 +37,7 @@ local Component = {
|
|||
-- Operation that are required for creating new components but not for inheritence
|
||||
if options ~= nil then
|
||||
component_no = component_no + 1
|
||||
check_deprecated_options(new_component.options)
|
||||
if not options.component_name then
|
||||
new_component.options.component_name = tostring(component_no)
|
||||
end
|
||||
|
@ -29,9 +52,9 @@ local Component = {
|
|||
if self.options.separator == nil then
|
||||
if self.options.component_separators then
|
||||
if self.options.self.section < 'lualine_x' then
|
||||
self.options.separator = self.options.component_separators[1]
|
||||
self.options.separator = self.options.component_separators.left
|
||||
else
|
||||
self.options.separator = self.options.component_separators[2]
|
||||
self.options.separator = self.options.component_separators.right
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -63,8 +86,16 @@ local Component = {
|
|||
|
||||
-- Adds spaces to left and right of a component
|
||||
apply_padding = function(self)
|
||||
local l_padding = (self.options.left_padding or self.options.padding or 1)
|
||||
local r_padding = (self.options.right_padding or self.options.padding or 1)
|
||||
local padding = self.options.padding
|
||||
local l_padding, r_padding
|
||||
if padding == nil then
|
||||
padding = 1
|
||||
end
|
||||
if type(padding) == 'number' then
|
||||
l_padding, r_padding = padding, padding
|
||||
elseif type(padding) == 'table' then
|
||||
l_padding, r_padding = padding.left, padding.right
|
||||
end
|
||||
if l_padding then
|
||||
if self.status:find '%%#.*#' == 1 then
|
||||
-- When component has changed the highlight at begining
|
||||
|
@ -114,9 +145,9 @@ local Component = {
|
|||
if type(separator) == 'table' then
|
||||
if self.options.separator[2] == '' then
|
||||
if self.options.self.section < 'lualine_x' then
|
||||
separator = self.options.component_separators[1]
|
||||
separator = self.options.component_separators.left
|
||||
else
|
||||
separator = self.options.component_separators[2]
|
||||
separator = self.options.component_separators.right
|
||||
end
|
||||
else
|
||||
return
|
||||
|
@ -132,12 +163,12 @@ local Component = {
|
|||
if type(self.options.separator) ~= 'table' then
|
||||
return
|
||||
end
|
||||
if self.options.separator[1] ~= '' then
|
||||
self.status = string.format('%%s{%s}%s', self.options.separator[1], self.status)
|
||||
if self.options.separator.left ~= nil and self.options.separator.left ~= '' then
|
||||
self.status = string.format('%%s{%s}%s', self.options.separator.left, self.status)
|
||||
self.strip_previous_separator = true
|
||||
end
|
||||
if self.options.separator[2] ~= '' then
|
||||
self.status = string.format('%s%%S{%s}', self.status, self.options.separator[2])
|
||||
if self.options.separator.right ~= nil and self.options.separator.right ~= '' then
|
||||
self.status = string.format('%s%%S{%s}', self.status, self.options.separator.right)
|
||||
end
|
||||
end,
|
||||
|
||||
|
@ -162,12 +193,12 @@ local Component = {
|
|||
self.status = ''
|
||||
self.applied_separator = ''
|
||||
|
||||
if self.options.condition ~= nil and self.options.condition() ~= true then
|
||||
if self.options.cond ~= nil and self.options.cond() ~= true then
|
||||
return self.status
|
||||
end
|
||||
local status = self:update_status(is_focused)
|
||||
if self.options.format then
|
||||
status = self.options.format(status or '')
|
||||
if self.options.fmt then
|
||||
status = self.options.fmt(status or '')
|
||||
end
|
||||
if type(status) == 'string' and #status > 0 then
|
||||
self.status = status
|
||||
|
|
|
@ -9,6 +9,33 @@ local modules = lualine_require.lazy_require {
|
|||
|
||||
local Diagnostics = lualine_require.require('lualine.component'):new()
|
||||
|
||||
local function check_deprecated_options(options)
|
||||
if options.color_error or options.color_warn or options.color_info or options.color_hint then
|
||||
options.diagnostics_color = options.diagnostics_color or {}
|
||||
require('lualine.utils.notices').add_notice(string.format [[
|
||||
### diagnostics.options.colors
|
||||
Previously colors in diagnostics section was set with color_error, color_warning..
|
||||
separate options . They've been unified under diagnostics_color options.
|
||||
Now it should be something like:
|
||||
```lua
|
||||
{ 'diagnostics',
|
||||
sources = {'nvim_lsp'},
|
||||
diagnostics_color = {
|
||||
error = color_error,
|
||||
warning = color_warning,
|
||||
info = color_info,
|
||||
hint = color_hint,
|
||||
}
|
||||
}
|
||||
```
|
||||
]])
|
||||
options.diagnostics_color.error = options.color_error
|
||||
options.diagnostics_color.warning = options.color_warning
|
||||
options.diagnostics_color.info = options.color_info
|
||||
options.diagnostics_color.hint = options.color_hint
|
||||
end
|
||||
end
|
||||
|
||||
local default_symbols = {
|
||||
icons = {
|
||||
error = ' ', -- xf659
|
||||
|
@ -24,26 +51,28 @@ local default_options = {
|
|||
update_in_insert = false,
|
||||
sources = nil,
|
||||
sections = { 'error', 'warn', 'info', 'hint' },
|
||||
color_error = {
|
||||
diagnostic_color = {
|
||||
error = {
|
||||
fg = modules.utils.extract_highlight_colors('LspDiagnosticsDefaultError', 'fg')
|
||||
or modules.utils.extract_highlight_colors('DiffDelete', 'fg')
|
||||
or '#e32636',
|
||||
},
|
||||
color_warn = {
|
||||
warn = {
|
||||
fg = modules.utils.extract_highlight_colors('LspDiagnosticsDefaultWarning', 'fg')
|
||||
or modules.utils.extract_highlight_colors('DiffText', 'fg')
|
||||
or '#ffdf00',
|
||||
},
|
||||
color_info = {
|
||||
info = {
|
||||
fg = modules.utils.extract_highlight_colors('LspDiagnosticsDefaultInformation', 'fg')
|
||||
or modules.utils.extract_highlight_colors('Normal', 'fg')
|
||||
or '#ffffff',
|
||||
},
|
||||
color_hint = {
|
||||
hint = {
|
||||
fg = modules.utils.extract_highlight_colors('LspDiagnosticsDefaultHint', 'fg')
|
||||
or modules.utils.extract_highlight_colors('DiffChange', 'fg')
|
||||
or '#d7afaf',
|
||||
},
|
||||
},
|
||||
}
|
||||
-- Initializer
|
||||
Diagnostics.new = function(self, options, child)
|
||||
|
@ -51,6 +80,7 @@ Diagnostics.new = function(self, options, child)
|
|||
local new_diagnostics = self._parent:new(options, child or Diagnostics)
|
||||
-- Apply default options
|
||||
new_diagnostics.options = vim.tbl_deep_extend('keep', new_diagnostics.options or {}, default_options)
|
||||
check_deprecated_options(new_diagnostics.options)
|
||||
-- Apply default symbols
|
||||
new_diagnostics.symbols = vim.tbl_extend(
|
||||
'keep',
|
||||
|
@ -61,22 +91,22 @@ Diagnostics.new = function(self, options, child)
|
|||
if new_diagnostics.options.colored then
|
||||
new_diagnostics.highlight_groups = {
|
||||
error = modules.highlight.create_component_highlight_group(
|
||||
new_diagnostics.options.color_error,
|
||||
new_diagnostics.options.diagnostic_color.error,
|
||||
'diagnostics_error',
|
||||
new_diagnostics.options
|
||||
),
|
||||
warn = modules.highlight.create_component_highlight_group(
|
||||
new_diagnostics.options.color_warn,
|
||||
new_diagnostics.options.diagnostic_color.warn,
|
||||
'diagnostics_warn',
|
||||
new_diagnostics.options
|
||||
),
|
||||
info = modules.highlight.create_component_highlight_group(
|
||||
new_diagnostics.options.color_info,
|
||||
new_diagnostics.options.diagnostic_color.info,
|
||||
'diagnostics_info',
|
||||
new_diagnostics.options
|
||||
),
|
||||
hint = modules.highlight.create_component_highlight_group(
|
||||
new_diagnostics.options.color_hint,
|
||||
new_diagnostics.options.diagnostic_color.hint,
|
||||
'diagnostics_hint',
|
||||
new_diagnostics.options
|
||||
),
|
||||
|
|
|
@ -9,6 +9,30 @@ local modules = lualine_require.lazy_require {
|
|||
}
|
||||
local Diff = lualine_require.require('lualine.component'):new()
|
||||
|
||||
local function check_deprecated_options(options)
|
||||
if options.color_added or options.color_modified or options.color_removed then
|
||||
options.diagnostics_color = options.diagnostics_color or {}
|
||||
require('lualine.utils.notices').add_notice(string.format [[
|
||||
### diff.options.colors
|
||||
Previously colors in diff section was set with color_added, color_modified..
|
||||
separate options . They've been unified under diff_color option.
|
||||
Now it should be something like:
|
||||
```lua
|
||||
{ 'diff',
|
||||
diff_color = {
|
||||
added = color_added,
|
||||
modified = color_modified,
|
||||
removed = color_removed,
|
||||
}
|
||||
}
|
||||
```
|
||||
]])
|
||||
options.diff_color.added = options.color_added
|
||||
options.diff_color.modified = options.color_modified
|
||||
options.diff_color.removed = options.color_removed
|
||||
end
|
||||
end
|
||||
|
||||
-- Vars
|
||||
-- variable to store git diff stats
|
||||
Diff.git_diff = nil
|
||||
|
@ -23,36 +47,39 @@ local diff_cache = {} -- Stores last known value of diff of a buffer
|
|||
local default_options = {
|
||||
colored = true,
|
||||
symbols = { added = '+', modified = '~', removed = '-' },
|
||||
color_added = {
|
||||
diff_color = {
|
||||
added = {
|
||||
fg = modules.utils.extract_highlight_colors('DiffAdd', 'fg') or '#f0e130',
|
||||
},
|
||||
color_modified = {
|
||||
modified = {
|
||||
fg = modules.utils.extract_highlight_colors('DiffChange', 'fg') or '#ff0038',
|
||||
},
|
||||
color_removed = {
|
||||
removed = {
|
||||
fg = modules.utils.extract_highlight_colors('DiffDelete', 'fg') or '#ff0038',
|
||||
},
|
||||
},
|
||||
}
|
||||
|
||||
-- Initializer
|
||||
Diff.new = function(self, options, child)
|
||||
local new_instance = self._parent:new(options, child or Diff)
|
||||
new_instance.options = vim.tbl_deep_extend('keep', new_instance.options or {}, default_options)
|
||||
check_deprecated_options(new_instance.options)
|
||||
-- create highlights and save highlight_name in highlights table
|
||||
if new_instance.options.colored then
|
||||
new_instance.highlights = {
|
||||
added = modules.highlight.create_component_highlight_group(
|
||||
new_instance.options.color_added,
|
||||
new_instance.options.diff_color.added,
|
||||
'diff_added',
|
||||
new_instance.options
|
||||
),
|
||||
modified = modules.highlight.create_component_highlight_group(
|
||||
new_instance.options.color_modified,
|
||||
new_instance.options.diff_color.modified,
|
||||
'diff_modified',
|
||||
new_instance.options
|
||||
),
|
||||
removed = modules.highlight.create_component_highlight_group(
|
||||
new_instance.options.color_removed,
|
||||
new_instance.options.diff_color.removed,
|
||||
'diff_removed',
|
||||
new_instance.options
|
||||
),
|
||||
|
|
|
@ -7,14 +7,36 @@ local modules = lualine_require.lazy_require {
|
|||
}
|
||||
local FileType = lualine_require.require('lualine.component'):new()
|
||||
|
||||
local function check_deprecated_options(options)
|
||||
local function rename_notice(before, now)
|
||||
if options[before] then
|
||||
require('lualine.utils.notices').add_notice(string.format(
|
||||
[[
|
||||
### option.%s
|
||||
%s option has been renamed to `%s`. Please use `%s` instead in your config
|
||||
for filetype component.
|
||||
]],
|
||||
before,
|
||||
before,
|
||||
now,
|
||||
now
|
||||
))
|
||||
options[now] = options[before]
|
||||
options[before] = nil
|
||||
end
|
||||
end
|
||||
rename_notice('disable_text', 'icon_only')
|
||||
end
|
||||
|
||||
local default_options = {
|
||||
colored = true,
|
||||
disable_text = false,
|
||||
icon_only = false,
|
||||
}
|
||||
|
||||
function FileType:new(options, child)
|
||||
local new_instance = self._parent:new(options, child or FileType)
|
||||
new_instance.options = vim.tbl_deep_extend('keep', new_instance.options or {}, default_options)
|
||||
check_deprecated_options(new_instance.options)
|
||||
return new_instance
|
||||
end
|
||||
|
||||
|
@ -59,7 +81,7 @@ function FileType:apply_icon()
|
|||
return
|
||||
end
|
||||
|
||||
if self.options.disable_text then
|
||||
if self.options.icon_only then
|
||||
self.status = icon
|
||||
else
|
||||
self.status = icon .. ' ' .. self.status
|
||||
|
|
|
@ -4,8 +4,8 @@ local config = {
|
|||
options = {
|
||||
icons_enabled = true,
|
||||
theme = 'auto',
|
||||
component_separators = { '', '' },
|
||||
section_separators = { '', '' },
|
||||
component_separators = { left = '', right = '' },
|
||||
section_separators = { left = '', right = '' },
|
||||
disabled_filetypes = {},
|
||||
},
|
||||
sections = {
|
||||
|
@ -28,13 +28,25 @@ local config = {
|
|||
extensions = {},
|
||||
}
|
||||
|
||||
-- change separator format 'x' or {'x'} to {'x', 'x'}
|
||||
local function check_sep_format_deprication(sep)
|
||||
if type(sep) == 'table' and vim.tbl_islist(sep) then
|
||||
require('lualine.utils.notices').add_persistent_notice(string.format [[
|
||||
### option.separator
|
||||
Using list for configuring separators has been depricated. Please configure it
|
||||
with {left = left_sep, right = right_sep} like table.
|
||||
]])
|
||||
sep = { left = sep[1], right = sep[2] or sep[1] }
|
||||
end
|
||||
return sep
|
||||
end
|
||||
|
||||
-- change separator format 'x' to {left='x', right='x'}
|
||||
local function fix_separators(separators)
|
||||
if separators ~= nil then
|
||||
if type(separators) == 'string' then
|
||||
return { separators, separators }
|
||||
elseif type(separators) == 'table' and #separators == 1 then
|
||||
return { separators[1], separators[1] }
|
||||
return { left = separators, right = separators }
|
||||
else
|
||||
return check_sep_format_deprication(separators)
|
||||
end
|
||||
end
|
||||
return separators
|
||||
|
|
|
@ -10,8 +10,7 @@ local empty = {
|
|||
function()
|
||||
return ' '
|
||||
end,
|
||||
left_padding = 0,
|
||||
right_padding = 0,
|
||||
padding = 0,
|
||||
}
|
||||
|
||||
M.sections = {
|
||||
|
|
|
@ -7,8 +7,7 @@ local empty = {
|
|||
function()
|
||||
return ' '
|
||||
end,
|
||||
left_padding = 0,
|
||||
right_padding = 0,
|
||||
padding = 0,
|
||||
}
|
||||
|
||||
local M = {}
|
||||
|
|
|
@ -7,8 +7,7 @@ local empty = {
|
|||
function()
|
||||
return ' '
|
||||
end,
|
||||
left_padding = 0,
|
||||
right_padding = 0,
|
||||
padding = 0,
|
||||
}
|
||||
|
||||
local M = {}
|
||||
|
|
|
@ -19,8 +19,7 @@ local empty = {
|
|||
function()
|
||||
return ' '
|
||||
end,
|
||||
left_padding = 0,
|
||||
right_padding = 0,
|
||||
padding = 0,
|
||||
}
|
||||
|
||||
local M = {}
|
||||
|
|
|
@ -8,8 +8,7 @@ local empty = {
|
|||
function()
|
||||
return ' '
|
||||
end,
|
||||
left_padding = 0,
|
||||
right_padding = 0,
|
||||
padding = 0,
|
||||
}
|
||||
|
||||
local M = {}
|
||||
|
|
|
@ -71,6 +71,90 @@ component type '%s' isn't recognised. Check if spelling is correct.]],
|
|||
end
|
||||
end
|
||||
|
||||
local function option_deprecatation_notice(component)
|
||||
local types = {
|
||||
case = function()
|
||||
local kind = component.upper ~= nil and 'upper' or 'lower'
|
||||
modules.notice.add_notice(string.format(
|
||||
[[
|
||||
### option.%s
|
||||
|
||||
Option `%s` has been deprecated.
|
||||
Please use `fmt` option if you need to change case of a component.
|
||||
|
||||
You have some thing like this in your config:
|
||||
|
||||
```lua
|
||||
%s = true,
|
||||
```
|
||||
|
||||
You'll have to change it to this to retain old behavior:
|
||||
|
||||
```lua
|
||||
fmt = string.%s
|
||||
```
|
||||
]],
|
||||
kind,
|
||||
kind,
|
||||
kind,
|
||||
kind
|
||||
))
|
||||
end,
|
||||
padding = function()
|
||||
local kind = component.left_padding ~= nil and 'left_padding' or 'right_padding'
|
||||
modules.notice.add_notice(string.format(
|
||||
[[
|
||||
### option.%s
|
||||
|
||||
Option `%s` has been deprecated.
|
||||
Please use `padding` option to set left/right padding.
|
||||
|
||||
You have some thing like this in your config:
|
||||
|
||||
```lua
|
||||
%s = %d,
|
||||
```
|
||||
|
||||
You'll have to change it to this to retain old behavior:
|
||||
|
||||
```lua
|
||||
padding = { %s = %d }
|
||||
```
|
||||
if you've set both left_padding and right_padding for a component
|
||||
you'll need to have something like
|
||||
```lua
|
||||
padding = { left = x, right = y }
|
||||
```
|
||||
When you set `padding = x` it's same as `padding = {left = x, right = x}`
|
||||
]],
|
||||
kind,
|
||||
kind,
|
||||
kind,
|
||||
component[kind],
|
||||
kind == 'left_padding' and 'left' or 'right',
|
||||
component[kind]
|
||||
))
|
||||
if component.left_padding and component.right_padding then
|
||||
component.padding = { left = component.left_padding, right = component.right_padding }
|
||||
component.left_padding = nil
|
||||
component.right_padding = nil
|
||||
elseif component.left_padding then
|
||||
component.padding = { left = component.left_padding, right = 1 }
|
||||
component.left_padding = nil
|
||||
else
|
||||
component.padding = { left = 1, right = component.right_padding }
|
||||
component.right_padding = nil
|
||||
end
|
||||
end,
|
||||
}
|
||||
if component.upper ~= nil or component.lower ~= nil then
|
||||
types.case()
|
||||
end
|
||||
if component.left_padding ~= nil or component.right_padding ~= nil then
|
||||
types.padding()
|
||||
end
|
||||
end
|
||||
|
||||
local function load_sections(sections, options)
|
||||
for section_name, section in pairs(sections) do
|
||||
for index, component in pairs(section) do
|
||||
|
@ -81,6 +165,7 @@ local function load_sections(sections, options)
|
|||
component.self.section = section_name
|
||||
-- apply default args
|
||||
component = vim.tbl_extend('keep', component, options)
|
||||
option_deprecatation_notice(component)
|
||||
section[index] = component_loader(component)
|
||||
end
|
||||
end
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
-- To provide notices for user
|
||||
local M = {}
|
||||
local notices = {}
|
||||
local persistent_notices = {}
|
||||
|
||||
function M.add_notice(notice)
|
||||
if type(notice) == 'string' then
|
||||
|
@ -9,8 +10,17 @@ function M.add_notice(notice)
|
|||
table.insert(notices, notice)
|
||||
end
|
||||
|
||||
function M.add_persistent_notice(notice)
|
||||
if type(notice) == 'string' then
|
||||
notice = vim.split(notice, '\n')
|
||||
end
|
||||
if not vim.tbl_contains(persistent_notices, notice) then
|
||||
table.insert(persistent_notices, notice)
|
||||
end
|
||||
end
|
||||
|
||||
function M.notice_message_startup()
|
||||
if #notices > 0 then
|
||||
if #notices > 0 or #persistent_notices then
|
||||
vim.cmd 'command! -nargs=0 LualineNotices lua require"lualine.utils.notices".show_notices()'
|
||||
vim.schedule(function()
|
||||
vim.notify(
|
||||
|
@ -35,7 +45,8 @@ function M.show_notices()
|
|||
vim.cmd 'normal q'
|
||||
return
|
||||
end
|
||||
local notice = vim.tbl_flatten(notices)
|
||||
local notice = vim.tbl_flatten(persistent_notices)
|
||||
notice = vim.list_extend(notice, vim.tbl_flatten(notices))
|
||||
vim.fn.append(0, notice)
|
||||
vim.api.nvim_win_set_cursor(0, { 1, 0 })
|
||||
end
|
||||
|
|
|
@ -34,12 +34,12 @@ function M.draw_section(section, section_name, is_focused)
|
|||
if section_name < 'c' then
|
||||
if
|
||||
type(section[first_component_no].options.separator) ~= 'table'
|
||||
and section[1].options.section_separators[1] ~= ''
|
||||
and (section[1].options.section_separators.left ~= nil and section[1].options.section_separators.left ~= '')
|
||||
then
|
||||
status[component_no] = string.format(
|
||||
'%s%%S{%s}',
|
||||
status[component_no],
|
||||
section[1].options.section_separators[1]
|
||||
section[1].options.section_separators.left
|
||||
)
|
||||
end
|
||||
end
|
||||
|
@ -68,11 +68,11 @@ function M.draw_section(section, section_name, is_focused)
|
|||
section_name > 'x'
|
||||
and section[first_component_no]
|
||||
and type(section[first_component_no].options.separator) ~= 'table'
|
||||
and section[1].options.section_separators[2] ~= ''
|
||||
and (section[1].options.section_separators.right ~= nil and section[1].options.section_separators.right ~= '')
|
||||
then
|
||||
left_sparator_string = string.format(
|
||||
'%%s{%s}',
|
||||
section[first_component_no].options.ls_separator or section[1].options.section_separators[2]
|
||||
section[first_component_no].options.ls_separator or section[1].options.section_separators.right
|
||||
)
|
||||
end
|
||||
|
||||
|
|
|
@ -41,10 +41,10 @@ M.build_component_opts = function(opts)
|
|||
opts.icons_enabled = true
|
||||
end
|
||||
if not opts.component_separators then
|
||||
opts.component_separators = { '', '' }
|
||||
opts.component_separators = { left = '', right = '' }
|
||||
end
|
||||
if not opts.section_separators then
|
||||
opts.section_separators = { '', '' }
|
||||
opts.section_separators = { left = '', right = '' }
|
||||
end
|
||||
return opts
|
||||
end
|
||||
|
|
|
@ -54,7 +54,7 @@ describe('Component:', function()
|
|||
|
||||
it('can draw', function()
|
||||
local opts = build_component_opts {
|
||||
component_separators = { '', '' },
|
||||
component_separators = { left = '', right = '' },
|
||||
padding = 0,
|
||||
}
|
||||
assert_component(nil, opts, 'test')
|
||||
|
@ -89,7 +89,7 @@ describe('Component:', function()
|
|||
describe('Global options:', function()
|
||||
it('upper', function()
|
||||
local opts = build_component_opts {
|
||||
component_separators = { '', '' },
|
||||
component_separators = { left = '', right = '' },
|
||||
padding = 0,
|
||||
upper = true,
|
||||
}
|
||||
|
@ -101,7 +101,7 @@ describe('Component:', function()
|
|||
function()
|
||||
return 'TeSt'
|
||||
end,
|
||||
component_separators = { '', '' },
|
||||
component_separators = { left = '', right = '' },
|
||||
padding = 0,
|
||||
lower = true,
|
||||
}
|
||||
|
@ -110,25 +110,23 @@ describe('Component:', function()
|
|||
|
||||
it('left_padding', function()
|
||||
local opts = build_component_opts {
|
||||
component_separators = { '', '' },
|
||||
padding = 0,
|
||||
left_padding = 5,
|
||||
component_separators = { left = '', right = '' },
|
||||
padding = { left = 5 },
|
||||
}
|
||||
assert_component(nil, opts, ' test')
|
||||
end)
|
||||
|
||||
it('right_padding', function()
|
||||
local opts = build_component_opts {
|
||||
component_separators = { '', '' },
|
||||
padding = 0,
|
||||
right_padding = 5,
|
||||
component_separators = { left = '', right = '' },
|
||||
padding = { right = 5 },
|
||||
}
|
||||
assert_component(nil, opts, 'test ')
|
||||
end)
|
||||
|
||||
it('padding', function()
|
||||
local opts = build_component_opts {
|
||||
component_separators = { '', '' },
|
||||
component_separators = { left = '', right = '' },
|
||||
padding = 5,
|
||||
}
|
||||
assert_component(nil, opts, ' test ')
|
||||
|
@ -136,7 +134,7 @@ describe('Component:', function()
|
|||
|
||||
it('icon', function()
|
||||
local opts = build_component_opts {
|
||||
component_separators = { '', '' },
|
||||
component_separators = { left = '', right = '' },
|
||||
padding = 0,
|
||||
icon = '0',
|
||||
}
|
||||
|
@ -145,14 +143,14 @@ describe('Component:', function()
|
|||
|
||||
it('icons_enabled', function()
|
||||
local opts = build_component_opts {
|
||||
component_separators = { '', '' },
|
||||
component_separators = { left = '', right = '' },
|
||||
padding = 0,
|
||||
icons_enabled = true,
|
||||
icon = '0',
|
||||
}
|
||||
assert_component(nil, opts, '0 test')
|
||||
local opts2 = build_component_opts {
|
||||
component_separators = { '', '' },
|
||||
component_separators = { left = '', right = '' },
|
||||
padding = 0,
|
||||
icons_enabled = false,
|
||||
icon = '0',
|
||||
|
@ -162,37 +160,37 @@ describe('Component:', function()
|
|||
|
||||
it('separator', function()
|
||||
local opts = build_component_opts {
|
||||
component_separators = { '', '' },
|
||||
component_separators = { left = '', right = '' },
|
||||
padding = 0,
|
||||
separator = '|',
|
||||
}
|
||||
assert_component(nil, opts, 'test|')
|
||||
end)
|
||||
|
||||
it('format', function()
|
||||
it('fmt', function()
|
||||
local opts = build_component_opts {
|
||||
component_separators = { '', '' },
|
||||
component_separators = { left = '', right = '' },
|
||||
padding = 0,
|
||||
format = function(data)
|
||||
fmt = function(data)
|
||||
return data:sub(1, 1):upper() .. data:sub(2, #data)
|
||||
end,
|
||||
}
|
||||
assert_component(nil, opts, 'Test')
|
||||
end)
|
||||
|
||||
it('condition', function()
|
||||
it('cond', function()
|
||||
local opts = build_component_opts {
|
||||
component_separators = { '', '' },
|
||||
component_separators = { left = '', right = '' },
|
||||
padding = 0,
|
||||
condition = function()
|
||||
cond = function()
|
||||
return true
|
||||
end,
|
||||
}
|
||||
assert_component(nil, opts, 'test')
|
||||
local opts2 = build_component_opts {
|
||||
component_separators = { '', '' },
|
||||
component_separators = { left = '', right = '' },
|
||||
padding = 0,
|
||||
condition = function()
|
||||
cond = function()
|
||||
return false
|
||||
end,
|
||||
}
|
||||
|
@ -201,7 +199,7 @@ describe('Component:', function()
|
|||
|
||||
it('color', function()
|
||||
local opts = build_component_opts {
|
||||
component_separators = { '', '' },
|
||||
component_separators = { left = '', right = '' },
|
||||
padding = 0,
|
||||
color = 'MyHl',
|
||||
}
|
||||
|
@ -209,7 +207,7 @@ describe('Component:', function()
|
|||
local custom_link_hl_name = 'lualine_' .. comp.options.component_name .. '_no_mode'
|
||||
eq('%#' .. custom_link_hl_name .. '#test', comp:draw(opts.hl))
|
||||
local opts2 = build_component_opts {
|
||||
component_separators = { '', '' },
|
||||
component_separators = { left = '', right = '' },
|
||||
padding = 0,
|
||||
color = { bg = '#230055', fg = '#223344' },
|
||||
}
|
||||
|
@ -227,7 +225,7 @@ end)
|
|||
describe('Encoding component', function()
|
||||
it('works', function()
|
||||
local opts = build_component_opts {
|
||||
component_separators = { '', '' },
|
||||
component_separators = { left = '', right = '' },
|
||||
padding = 0,
|
||||
}
|
||||
assert_component('encoding', opts, '%{strlen(&fenc)?&fenc:&enc}')
|
||||
|
@ -237,7 +235,7 @@ end)
|
|||
describe('Fileformat component', function()
|
||||
it('works with icons', function()
|
||||
local opts = build_component_opts {
|
||||
component_separators = { '', '' },
|
||||
component_separators = { left = '', right = '' },
|
||||
padding = 0,
|
||||
}
|
||||
local fmt = vim.bo.fileformat
|
||||
|
@ -251,7 +249,7 @@ describe('Fileformat component', function()
|
|||
end)
|
||||
it('works without icons', function()
|
||||
local opts = build_component_opts {
|
||||
component_separators = { '', '' },
|
||||
component_separators = { left = '', right = '' },
|
||||
padding = 0,
|
||||
icons_enabled = false,
|
||||
}
|
||||
|
@ -273,7 +271,7 @@ describe('Filetype component', function()
|
|||
|
||||
it('does not add icon when library unavailable', function()
|
||||
local opts = build_component_opts {
|
||||
component_separators = { '', '' },
|
||||
component_separators = { left = '', right = '' },
|
||||
padding = 0,
|
||||
}
|
||||
assert_component('filetype', opts, 'lua')
|
||||
|
@ -294,10 +292,10 @@ describe('Filetype component', function()
|
|||
utils.extract_highlight_colors.returns '#000'
|
||||
|
||||
local opts = build_component_opts {
|
||||
component_separators = { '', '' },
|
||||
component_separators = { left = '', right = '' },
|
||||
padding = 0,
|
||||
colored = true,
|
||||
disable_text = false,
|
||||
icon_only = false,
|
||||
}
|
||||
assert_component('filetype', opts, '%#MyCompHl_normal#*%#lualine_c_normal# lua')
|
||||
assert.stub(utils.extract_highlight_colors).was_called_with('test_highlight_group', 'fg')
|
||||
|
@ -320,7 +318,7 @@ describe('Filetype component', function()
|
|||
hl.create_component_highlight_group.returns 'MyCompHl'
|
||||
utils.extract_highlight_colors.returns '#000'
|
||||
local opts = build_component_opts {
|
||||
component_separators = { '', '' },
|
||||
component_separators = { left = '', right = '' },
|
||||
padding = 0,
|
||||
colored = false,
|
||||
}
|
||||
|
@ -330,7 +328,7 @@ describe('Filetype component', function()
|
|||
package.loaded['nvim-web-devicons'] = nil
|
||||
end)
|
||||
|
||||
it('displays only icon when disable_text is true', function()
|
||||
it('displays only icon when icon_only is true', function()
|
||||
package.loaded['nvim-web-devicons'] = {
|
||||
get_icon = function()
|
||||
return '*', 'test_highlight_group'
|
||||
|
@ -338,10 +336,10 @@ describe('Filetype component', function()
|
|||
}
|
||||
|
||||
local opts = build_component_opts {
|
||||
component_separators = { '', '' },
|
||||
component_separators = { left = '', right = '' },
|
||||
padding = 0,
|
||||
colored = false,
|
||||
disable_text = true,
|
||||
icon_only = true,
|
||||
}
|
||||
assert_component('filetype', opts, '*')
|
||||
package.loaded['nvim-web-devicons'] = nil
|
||||
|
@ -353,7 +351,7 @@ describe('Hostname component', function()
|
|||
stub(vim.loop, 'os_gethostname')
|
||||
vim.loop.os_gethostname.returns 'localhost'
|
||||
local opts = build_component_opts {
|
||||
component_separators = { '', '' },
|
||||
component_separators = { left = '', right = '' },
|
||||
padding = 0,
|
||||
}
|
||||
assert_component('hostname', opts, 'localhost')
|
||||
|
@ -364,7 +362,7 @@ end)
|
|||
describe('Location component', function()
|
||||
it('works', function()
|
||||
local opts = build_component_opts {
|
||||
component_separators = { '', '' },
|
||||
component_separators = { left = '', right = '' },
|
||||
padding = 0,
|
||||
}
|
||||
assert_component('location', opts, '%3l:%-2c')
|
||||
|
@ -374,7 +372,7 @@ end)
|
|||
describe('Progress component', function()
|
||||
it('works', function()
|
||||
local opts = build_component_opts {
|
||||
component_separators = { '', '' },
|
||||
component_separators = { left = '', right = '' },
|
||||
padding = 0,
|
||||
}
|
||||
assert_component('progress', opts, '%3P')
|
||||
|
@ -386,7 +384,7 @@ describe('Mode component', function()
|
|||
stub(vim.api, 'nvim_get_mode')
|
||||
vim.api.nvim_get_mode.returns { mode = 'n', blocking = false }
|
||||
local opts = build_component_opts {
|
||||
component_separators = { '', '' },
|
||||
component_separators = { left = '', right = '' },
|
||||
padding = 0,
|
||||
}
|
||||
assert_component('mode', opts, 'NORMAL')
|
||||
|
|
|
@ -34,19 +34,19 @@ describe('config parsing', function()
|
|||
describe('separators', function()
|
||||
it('default', function()
|
||||
local config = config_module.apply_configuration {}
|
||||
eq(config.options.component_separators, { '', '' })
|
||||
eq(config.options.section_separators, { '', '' })
|
||||
eq(config.options.component_separators, { left = '', right = '' })
|
||||
eq(config.options.section_separators, { left = '', right = '' })
|
||||
end)
|
||||
it('double separators', function()
|
||||
local config = {
|
||||
options = {
|
||||
component_separators = { 'a', 'b' },
|
||||
section_separators = { 'c', 'd' },
|
||||
component_separators = { left = 'a', right = 'b' },
|
||||
section_separators = { left = 'c', right = 'd' },
|
||||
},
|
||||
}
|
||||
config = config_module.apply_configuration(config)
|
||||
eq(config.options.component_separators, { 'a', 'b' })
|
||||
eq(config.options.section_separators, { 'c', 'd' })
|
||||
eq(config.options.component_separators, { left = 'a', right = 'b' })
|
||||
eq(config.options.section_separators, { left = 'c', right = 'd' })
|
||||
end)
|
||||
|
||||
describe('single separator', function()
|
||||
|
@ -55,16 +55,16 @@ describe('config parsing', function()
|
|||
options = { component_separators = 'a', section_separators = 'b' },
|
||||
}
|
||||
config = config_module.apply_configuration(config)
|
||||
eq(config.options.component_separators, { 'a', 'a' })
|
||||
eq(config.options.section_separators, { 'b', 'b' })
|
||||
eq(config.options.component_separators, { left = 'a', right = 'a' })
|
||||
eq(config.options.section_separators, { left = 'b', right = 'b' })
|
||||
end)
|
||||
it('table', function()
|
||||
local config = {
|
||||
options = { component_separators = { 'a' }, section_separators = { 'b' } },
|
||||
}
|
||||
config = config_module.apply_configuration(config)
|
||||
eq(config.options.component_separators, { 'a', 'a' })
|
||||
eq(config.options.section_separators, { 'b', 'b' })
|
||||
eq(config.options.component_separators, { left = 'a', right = 'a' })
|
||||
eq(config.options.section_separators, { left = 'b', right = 'b' })
|
||||
end)
|
||||
end)
|
||||
it('no seprarators', function()
|
||||
|
|
|
@ -54,7 +54,7 @@ end)
|
|||
describe('Section genarator', function()
|
||||
local sec = require 'lualine.utils.section'
|
||||
it('can draw', function()
|
||||
local opts = build_component_opts { section_separators = { '', '' } }
|
||||
local opts = build_component_opts { section_separators = { left = '', right = '' } }
|
||||
local section = {
|
||||
require('lualine.components.special.function_component'):new(opts),
|
||||
require('lualine.components.special.function_component'):new(opts),
|
||||
|
@ -63,15 +63,15 @@ describe('Section genarator', function()
|
|||
end)
|
||||
|
||||
it('can remove separators from component with custom colors', function()
|
||||
local opts = build_component_opts { section_separators = { '', '' } }
|
||||
local opts = build_component_opts { section_separators = { left = '', right = '' } }
|
||||
local opts_colored = build_component_opts { color = 'MyColor' }
|
||||
local opts_colored2 = build_component_opts {
|
||||
color = { bg = '#223344' },
|
||||
section_separators = { '', '' },
|
||||
section_separators = { left = '', right = '' },
|
||||
}
|
||||
local opts_colored3 = build_component_opts {
|
||||
color = { fg = '#223344' },
|
||||
section_separators = { '', '' },
|
||||
section_separators = { left = '', right = '' },
|
||||
}
|
||||
require('lualine.highlight').create_highlight_groups(require 'lualine.themes.gruvbox')
|
||||
local section = {
|
||||
|
|
Loading…
Reference in New Issue