chore: Use paranthesis for function calls. No paran can trip new lua users

This commit is contained in:
shadmansaleh 2022-01-02 17:38:39 +06:00
parent a11f6d15d4
commit b18b7ee8ac
39 changed files with 317 additions and 317 deletions

View File

@ -1,4 +1,4 @@
indent_type = "Spaces"
indent_width = 2
quote_style = "AutoPreferSingle"
no_call_parentheses = true
no_call_parentheses = false

View File

@ -31,7 +31,7 @@ local bubbles_theme = {
},
}
require('lualine').setup {
require('lualine').setup({
options = {
theme = bubbles_theme,
component_separators = '|',
@ -59,4 +59,4 @@ require('lualine').setup {
},
tabline = {},
extensions = {},
}
})

View File

@ -1,7 +1,7 @@
-- Eviline config for lualine
-- Author: shadmansaleh
-- Credit: glepnir
local lualine = require 'lualine'
local lualine = require('lualine')
-- Color table for highlights
-- stylua: ignore
@ -21,13 +21,13 @@ local colors = {
local conditions = {
buffer_not_empty = function()
return vim.fn.empty(vim.fn.expand '%:t') ~= 1
return vim.fn.empty(vim.fn.expand('%:t')) ~= 1
end,
hide_in_width = function()
return vim.fn.winwidth(0) > 80
end,
check_git_workspace = function()
local filepath = vim.fn.expand '%:p:h'
local filepath = vim.fn.expand('%:p:h')
local gitdir = vim.fn.finddir('.git', filepath .. ';')
return gitdir and #gitdir > 0 and #gitdir < #filepath
end,
@ -78,15 +78,15 @@ local function ins_right(component)
table.insert(config.sections.lualine_x, component)
end
ins_left {
ins_left({
function()
return ''
end,
color = { fg = colors.blue }, -- Sets highlighting of component
padding = { left = 0, right = 1 }, -- We don't need space before this
}
})
ins_left {
ins_left({
-- mode component
function()
-- auto change color according to neovims mode
@ -117,25 +117,25 @@ ins_left {
end,
color = 'LualineMode',
padding = { right = 1 },
}
})
ins_left {
ins_left({
-- filesize component
'filesize',
cond = conditions.buffer_not_empty,
}
})
ins_left {
ins_left({
'filename',
cond = conditions.buffer_not_empty,
color = { fg = colors.magenta, gui = 'bold' },
}
})
ins_left { 'location' }
ins_left({ 'location' })
ins_left { 'progress', color = { fg = colors.fg, gui = 'bold' } }
ins_left({ 'progress', color = { fg = colors.fg, gui = 'bold' } })
ins_left {
ins_left({
'diagnostics',
sources = { 'nvim_diagnostic' },
symbols = { error = '', warn = '', info = '' },
@ -144,17 +144,17 @@ ins_left {
color_warn = { fg = colors.yellow },
color_info = { fg = colors.cyan },
},
}
})
-- Insert mid section. You can make any number of sections in neovim :)
-- for lualine it's any number greater then 2
ins_left {
ins_left({
function()
return '%='
end,
}
})
ins_left {
ins_left({
-- Lsp server name .
function()
local msg = 'No Active Lsp'
@ -173,30 +173,30 @@ ins_left {
end,
icon = ' LSP:',
color = { fg = '#ffffff', gui = 'bold' },
}
})
-- Add components to right sections
ins_right {
ins_right({
'o:encoding', -- option component same as &encoding in viml
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 {
ins_right({
'fileformat',
fmt = string.upper,
icons_enabled = false, -- I think icons are cool but Eviline doesn't have them. sigh
color = { fg = colors.green, gui = 'bold' },
}
})
ins_right {
ins_right({
'branch',
icon = '',
color = { fg = colors.violet, gui = 'bold' },
}
})
ins_right {
ins_right({
'diff',
-- Is it me or the symbol for modified us really weird
symbols = { added = '', modified = '', removed = '' },
@ -206,15 +206,15 @@ ins_right {
removed = { fg = colors.red },
},
cond = conditions.hide_in_width,
}
})
ins_right {
ins_right({
function()
return ''
end,
color = { fg = colors.blue },
padding = { left = 1 },
}
})
-- Now don't forget to initialize lualine
lualine.setup(config)

View File

@ -51,11 +51,11 @@ local function search_result()
if vim.v.hlsearch == 0 then
return ''
end
local last_search = vim.fn.getreg '/'
local last_search = vim.fn.getreg('/')
if not last_search or last_search == '' then
return ''
end
local searchcount = vim.fn.searchcount { maxcount = 9999 }
local searchcount = vim.fn.searchcount({ maxcount = 9999 })
return last_search .. '(' .. searchcount.current .. '/' .. searchcount.total .. ')'
end
@ -68,13 +68,13 @@ local function modified()
return ''
end
require('lualine').setup {
require('lualine').setup({
options = {
theme = theme,
component_separators = '',
section_separators = { left = '', right = '' },
},
sections = process_sections {
sections = process_sections({
lualine_a = { 'mode' },
lualine_b = {
'branch',
@ -116,9 +116,9 @@ require('lualine').setup {
lualine_x = {},
lualine_y = { search_result, 'filetype' },
lualine_z = { '%l:%c', '%p%%/%L' },
},
}),
inactive_sections = {
lualine_c = { '%f %y %m' },
lualine_x = {},
},
}
})

View File

@ -1,14 +1,14 @@
-- Copyright (c) 2020-2021 hoob3rt
-- MIT license, see LICENSE for more details.
local lualine_require = require 'lualine_require'
local modules = lualine_require.lazy_require {
local lualine_require = require('lualine_require')
local modules = lualine_require.lazy_require({
highlight = 'lualine.highlight',
loader = 'lualine.utils.loader',
utils_section = 'lualine.utils.section',
utils = 'lualine.utils.utils',
utils_notices = 'lualine.utils.notices',
config_module = 'lualine.config',
}
})
local config -- Stores cureently applied config
local new_config = true -- Stores config that will be applied
@ -119,7 +119,7 @@ local function apply_transitional_separators(status)
copied_pos = str_checked
elseif next_char == '%' then
str_checked = str_checked + 2 -- Skip the following % too
elseif next_char == '=' and last_hl and (last_hl:find '^lualine_a' or last_hl:find '^lualine_b') then
elseif next_char == '=' and last_hl and (last_hl:find('^lualine_a') or last_hl:find('^lualine_b')) then
-- TODO: Fix this properly
-- This check for lualine_a and lualine_b is dumb. It doesn't garantee
-- c or x section isn't present. Worst case sinario after this patch
@ -158,7 +158,7 @@ local function statusline(sections, is_focused)
if #section_data > 0 then
if not applied_midsection_divider and section_name > 'c' then
applied_midsection_divider = true
section_data = modules.highlight.format_highlight 'lualine_c' .. '%=' .. section_data
section_data = modules.highlight.format_highlight('lualine_c') .. '%=' .. section_data
end
if not applied_trunc and section_name > 'b' then
applied_trunc = true
@ -170,7 +170,7 @@ local function statusline(sections, is_focused)
end
if applied_midsection_divider == false and config.options.always_divide_middle ~= false then
-- When non of section x,y,z is present
table.insert(status, modules.highlight.format_highlight 'lualine_c' .. '%=')
table.insert(status, modules.highlight.format_highlight('lualine_c') .. '%=')
end
return apply_transitional_separators(table.concat(status))
end
@ -244,13 +244,13 @@ local function setup_theme()
return theme
end
end
notify_theme_error 'auto'
return modules.loader.load_theme 'gruvbox'
notify_theme_error('auto')
return modules.loader.load_theme('gruvbox')
end
local theme = get_theme_from_config()
modules.highlight.create_highlight_groups(theme)
vim.cmd [[autocmd lualine ColorScheme * lua require'lualine'.setup()
autocmd lualine OptionSet background lua require'lualine'.setup()]]
vim.cmd([[autocmd lualine ColorScheme * lua require'lualine'.setup()
autocmd lualine OptionSet background lua require'lualine'.setup()]])
end
--- Sets &tabline option to lualine
@ -268,7 +268,7 @@ end
--- adds auto command to redraw lualine on VimResized event
local function set_statusline()
if next(config.sections) ~= nil or next(config.inactive_sections) ~= nil then
vim.cmd 'autocmd lualine VimResized * redrawstatus'
vim.cmd('autocmd lualine VimResized * redrawstatus')
else
vim.go.statusline = ''
vim.go.laststatus = 0
@ -281,7 +281,7 @@ local function reset_lualine()
-- When notices module is not loaded there are no notices to clear.
modules.utils_notices.clear_notices()
end
vim.cmd [[augroup lualine | exe "autocmd!" | augroup END]]
vim.cmd([[augroup lualine | exe "autocmd!" | augroup END]])
setup_theme()
-- load components & extensions
modules.loader.load_all(config)

View File

@ -1,7 +1,7 @@
-- Copyright (c) 2020-2021 shadmansaleh
-- MIT license, see LICENSE for more details.
local require = require('lualine_require').require
local highlight = require 'lualine.highlight'
local highlight = require('lualine.highlight')
local M = require('lualine.utils.class'):extend()
-- Used to provide a unique id for each component
@ -72,7 +72,7 @@ function M:apply_padding()
l_padding, r_padding = padding.left, padding.right
end
if l_padding then
if self.status:find '%%#.*#' == 1 then
if self.status:find('%%#.*#') == 1 then
-- When component has changed the highlight at begining
-- we will add the padding after the highlight
local pre_highlight = vim.fn.matchlist(self.status, [[\(%#.\{-\}#\)]])[2]
@ -91,7 +91,7 @@ function M:apply_highlights(default_highlight)
if self.options.color_highlight then
self.status = highlight.component_format_highlight(self.options.color_highlight) .. self.status
end
if type(self.options.separator) ~= 'table' and self.status:find '%%#' then
if type(self.options.separator) ~= 'table' and self.status:find('%%#') then
-- Apply default highlight only when we aren't applying trans sep and
-- the component has changed it's hl. since we won't be applying
-- regular sep in those cases so ending with default hl isn't neccessay
@ -101,7 +101,7 @@ function M:apply_highlights(default_highlight)
end
-- Prepend default hl when the component doesn't start with hl otherwise
-- color in previous component can cause side effect
if not self.status:find '^%%#' then
if not self.status:find('^%%#') then
self.status = default_highlight .. self.status
end
end

View File

@ -1,7 +1,7 @@
local M = {}
local require = require('lualine_require').require
local utils = require 'lualine.utils.utils'
local utils = require('lualine.utils.utils')
-- vars
local current_git_branch = ''
@ -23,7 +23,7 @@ local function get_git_head(head_file)
if f_head then
local HEAD = f_head:read()
f_head:close()
local branch = HEAD:match 'ref: refs/heads/(.+)$'
local branch = HEAD:match('ref: refs/heads/(.+)$')
if branch then
current_git_branch = branch
else
@ -61,7 +61,7 @@ end
---@return string
function M.find_git_dir(dir_path)
-- get file dir so we can search from that dir
local file_dir = dir_path or vim.fn.expand '%:p:h'
local file_dir = dir_path or vim.fn.expand('%:p:h')
local root_dir = file_dir
local git_dir
-- Search upward for .git file or folder
@ -80,12 +80,12 @@ function M.find_git_dir(dir_path)
local file = io.open(git_path)
if file then
git_dir = file:read()
git_dir = git_dir and git_dir:match 'gitdir: (.+)$'
git_dir = git_dir and git_dir:match('gitdir: (.+)$')
file:close()
end
-- submodule / relative file path
if git_dir and git_dir:sub(1, 1) ~= sep and not git_dir:match '^%a:.*$' then
git_dir = git_path:match '(.*).git' .. git_dir
if git_dir and git_dir:sub(1, 1) ~= sep and not git_dir:match('^%a:.*$') then
git_dir = git_path:match('(.*).git') .. git_dir
end
end
if git_dir then

View File

@ -2,7 +2,7 @@
-- MIT license, see LICENSE for more details.
local M = require('lualine.component'):extend()
local require = require('lualine_require').require
local git_branch = require 'lualine.components.branch.git_branch'
local git_branch = require('lualine.components.branch.git_branch')
-- Initilizer
M.init = function(self, options)

View File

@ -1,4 +1,4 @@
local highlight = require 'lualine.highlight'
local highlight = require('lualine.highlight')
local Buffer = require('lualine.utils.class'):extend()
---intialize a new buffer from opts
@ -26,13 +26,13 @@ function Buffer:get_props()
if not status then
dev, _ = '', ''
elseif self.filetype == 'TelescopePrompt' then
dev, _ = require('nvim-web-devicons').get_icon 'telescope'
dev, _ = require('nvim-web-devicons').get_icon('telescope')
elseif self.filetype == 'fugitive' then
dev, _ = require('nvim-web-devicons').get_icon 'git'
dev, _ = require('nvim-web-devicons').get_icon('git')
elseif self.filetype == 'vimwiki' then
dev, _ = require('nvim-web-devicons').get_icon 'markdown'
dev, _ = require('nvim-web-devicons').get_icon('markdown')
elseif self.buftype == 'terminal' then
dev, _ = require('nvim-web-devicons').get_icon 'zsh'
dev, _ = require('nvim-web-devicons').get_icon('zsh')
elseif vim.fn.isdirectory(self.file) == 1 then
dev, _ = '', nil
else

View File

@ -1,9 +1,9 @@
-- Copyright (c) 2020-2021 shadmansaleh
-- MIT license, see LICENSE for more details.
local require = require('lualine_require').require
local Buffer = require 'lualine.components.buffers.buffer'
local Buffer = require('lualine.components.buffers.buffer')
local M = require('lualine.component'):extend()
local highlight = require 'lualine.highlight'
local highlight = require('lualine.highlight')
local default_options = {
show_filename_only = true,
@ -65,9 +65,9 @@ end
function M:update_status()
local data = {}
local buffers = {}
for b = 1, vim.fn.bufnr '$' do
for b = 1, vim.fn.bufnr('$') do
if vim.fn.buflisted(b) ~= 0 and vim.api.nvim_buf_get_option(b, 'buftype') ~= 'quickfix' then
buffers[#buffers + 1] = Buffer { bufnr = b, options = self.options, highlights = self.highlights }
buffers[#buffers + 1] = Buffer({ bufnr = b, options = self.options, highlights = self.highlights })
end
end
local current_bufnr = vim.fn.bufnr()
@ -110,7 +110,7 @@ function M:update_status()
-- start drawing from current buffer and draw left and right of it until
-- all buffers are drawn or max_length has been reached.
if current == -2 then
local b = Buffer { bufnr = vim.fn.bufnr(), options = self.options, highlights = self.highlights }
local b = Buffer({ bufnr = vim.fn.bufnr(), options = self.options, highlights = self.highlights })
b.current = true
if self.options.self.section < 'lualine_x' then
b.last = true
@ -193,10 +193,10 @@ function M:draw()
return self.status
end
vim.cmd [[
vim.cmd([[
function! LualineSwitchBuffer(bufnr, mouseclicks, mousebutton, modifiers)
execute ":buffer " . a:bufnr
endfunction
]]
]])
return M

View File

@ -1,5 +1,5 @@
local require = require('lualine_require').require
local utils = require 'lualine.utils.utils'
local utils = require('lualine.utils.utils')
local M = {}
-- default symbols for diagnostics component
@ -18,7 +18,7 @@ M.options = {
colored = true,
update_in_insert = false,
always_visible = false,
sources = { vim.fn.has 'nvim-0.6' == 1 and 'nvim_diagnostic' or 'nvim_lsp', 'coc' },
sources = { vim.fn.has('nvim-0.6') == 1 and 'nvim_diagnostic' or 'nvim_lsp', 'coc' },
sections = { 'error', 'warn', 'info', 'hint' },
diagnostics_color = {
error = {

View File

@ -1,13 +1,13 @@
-- Copyright (c) 2020-2021 hoob3rt
-- MIT license, see LICENSE for more details.
local lualine_require = require 'lualine_require'
local modules = lualine_require.lazy_require {
local lualine_require = require('lualine_require')
local modules = lualine_require.lazy_require({
default_config = 'lualine.components.diagnostics.config',
sources = 'lualine.components.diagnostics.sources',
highlight = 'lualine.highlight',
utils = 'lualine.utils.utils',
utils_notices = 'lualine.utils.notices',
}
})
local M = lualine_require.require('lualine.component'):extend()
@ -55,14 +55,14 @@ function M:init(options)
-- Error out no source
if #self.options.sources < 1 then
print 'no sources for diagnostics configured'
print('no sources for diagnostics configured')
return ''
end
if vim.fn.has 'nvim-0.6' == 1 then
if vim.fn.has('nvim-0.6') == 1 then
for i, name in ipairs(self.options.sources) do
if name == 'nvim_lsp' then
self.options.sources[i] = 'nvim_diagnostic'
modules.utils_notices.add_notice [[
modules.utils_notices.add_notice([[
### diagnostics.source
Diagnostics source `nvim_lsp` has been deprecated in favour of `nvim_diagnostic`.
nvim_diagnostic shows diagnostics from neovim's diagnostics api
@ -76,10 +76,10 @@ It needs to be updated to:
```lua
{'diagnostics', sources = {'nvim_diagnostic'}}
```
]]
]])
elseif name == 'nvim' then
self.options.sources[i] = 'nvim_diagnostic'
modules.utils_notices.add_notice [[
modules.utils_notices.add_notice([[
### diagnostics.source
Diagnostics source `nvim` has been renamed to `nvim_diagnostic`
@ -91,7 +91,7 @@ It needs to be updated to:
```lua
{'diagnostics', sources = {'nvim_diagnostic'}}
```
]]
]])
end
end
end

View File

@ -1,8 +1,8 @@
local lualine_require = require 'lualine_require'
local modules = lualine_require.lazy_require {
local lualine_require = require('lualine_require')
local modules = lualine_require.lazy_require({
utils = 'lualine.utils.utils',
Job = 'lualine.utils.job',
}
})
local M = {}
@ -86,7 +86,7 @@ end
function M.update_diff_args()
-- Donn't show git diff when current buffer doesn't have a filename
active_bufnr = tostring(vim.fn.bufnr())
if #vim.fn.expand '%' == 0 then
if #vim.fn.expand('%') == 0 then
M.diff_args = nil
git_diff = nil
return
@ -94,8 +94,8 @@ function M.update_diff_args()
M.diff_args = {
cmd = string.format(
[[git -C %s --no-pager diff --no-color --no-ext-diff -U0 -- %s]],
vim.fn.expand '%:h',
vim.fn.expand '%:t'
vim.fn.expand('%:h'),
vim.fn.expand('%:t')
),
on_stdout = function(_, data)
if next(data) then

View File

@ -1,12 +1,12 @@
-- Copyright (c) 2020-2021 shadmansaleh
-- MIT license, see LICENSE for more details.
local lualine_require = require 'lualine_require'
local modules = lualine_require.lazy_require {
local lualine_require = require('lualine_require')
local modules = lualine_require.lazy_require({
git_diff = 'lualine.components.diff.git_diff',
utils = 'lualine.utils.utils',
utils_notices = 'lualine.utils.notices',
highlight = 'lualine.highlight',
}
})
local M = lualine_require.require('lualine.component'):extend()
local default_options = {
@ -81,7 +81,7 @@ function M:update_status(is_focused)
local result = {}
-- loop though data and load available sections in result table
for _, name in ipairs { 'added', 'modified', 'removed' } do
for _, name in ipairs({ 'added', 'modified', 'removed' }) do
if git_diff[name] and git_diff[name] > 0 then
if self.options.colored then
table.insert(result, colors[name] .. self.options.symbols[name] .. git_diff[name])

View File

@ -35,13 +35,13 @@ M.update_status = function(self)
local data
if self.options.path == 1 then
-- relative path
data = vim.fn.expand '%:~:.'
data = vim.fn.expand('%:~:.')
elseif self.options.path == 2 then
-- absolute path
data = vim.fn.expand '%:p'
data = vim.fn.expand('%:p')
else
-- just filename
data = vim.fn.expand '%:t'
data = vim.fn.expand('%:t')
end
if data == '' then

View File

@ -1,7 +1,7 @@
-- Copyright (c) 2020-2021 shadmansaleh
-- MIT license, see LICENSE for more details.
local function filesize()
local file = vim.fn.expand '%:p'
local file = vim.fn.expand('%:p')
if file == nil or #file == 0 then
return ''
end

View File

@ -1,10 +1,10 @@
-- Copyright (c) 2020-2021 hoob3rt
-- MIT license, see LICENSE for more details.
local lualine_require = require 'lualine_require'
local modules = lualine_require.lazy_require {
local lualine_require = require('lualine_require')
local modules = lualine_require.lazy_require({
highlight = 'lualine.highlight',
utils = 'lualine.utils.utils',
}
})
local M = lualine_require.require('lualine.component'):extend()
local default_options = {
@ -29,7 +29,7 @@ function M:apply_icon()
local icon, icon_highlight_group
local ok, devicons = pcall(require, 'nvim-web-devicons')
if ok then
local f_name, f_extension = vim.fn.expand '%:t', vim.fn.expand '%:e'
local f_name, f_extension = vim.fn.expand('%:t'), vim.fn.expand('%:e')
f_extension = f_extension ~= '' and f_extension or vim.bo.filetype
icon, icon_highlight_group = devicons.get_icon(f_name, f_extension)
@ -48,7 +48,7 @@ function M:apply_icon()
icon = modules.highlight.component_format_highlight(icon_highlight) .. icon .. default_highlight
end
else
ok = vim.fn.exists '*WebDevIconsGetFileTypeSymbol'
ok = vim.fn.exists('*WebDevIconsGetFileTypeSymbol')
if ok ~= 0 then
icon = vim.fn.WebDevIconsGetFileTypeSymbol()
end

View File

@ -7,7 +7,7 @@ function M:update_status()
-- vim veriable component
-- accepts g:, v:, t:, w:, b:, o, go:, vo:, to:, wo:, bo:
-- filters g portion from g:var
local scope = component:match '[gvtwb]?o?'
local scope = component:match('[gvtwb]?o?')
-- filters var portion from g:var
local var_name = component:sub(#scope + 2, #component)
-- Displays nothing when veriable aren't present

View File

@ -1,9 +1,9 @@
-- Copyright (c) 2020-2021 shadmansaleh
-- MIT license, see LICENSE for more details.
local require = require('lualine_require').require
local Tab = require 'lualine.components.tabs.tab'
local Tab = require('lualine.components.tabs.tab')
local M = require('lualine.component'):extend()
local highlight = require 'lualine.highlight'
local highlight = require('lualine.highlight')
local default_options = {
max_length = 0,
@ -57,8 +57,8 @@ end
function M:update_status()
local data = {}
local tabs = {}
for t = 1, vim.fn.tabpagenr '$' do
tabs[#tabs + 1] = Tab { tabnr = t, options = self.options, highlights = self.highlights }
for t = 1, vim.fn.tabpagenr('$') do
tabs[#tabs + 1] = Tab({ tabnr = t, options = self.options, highlights = self.highlights })
end
-- mark the first, last, current, before current, after current tabpages
-- for rendering
@ -93,7 +93,7 @@ function M:update_status()
-- start drawing from current tab and draw left and right of it until
-- all tabpages are drawn or max_length has been reached.
if current_tab == nil then -- maybe redundent code
local t = Tab { tabnr = vim.fn.tabpagenr(), options = self.options, highlights = self.highlights }
local t = Tab({ tabnr = vim.fn.tabpagenr(), options = self.options, highlights = self.highlights })
t.current = true
t.last = true
data[#data + 1] = t:render()
@ -163,10 +163,10 @@ function M:draw()
return self.status
end
vim.cmd [[
vim.cmd([[
function! LualineSwitchTab(tabnr, mouseclicks, mousebutton, modifiers)
execute a:tabnr . "tabnext"
endfunction
]]
]])
return M

View File

@ -1,4 +1,4 @@
local highlight = require 'lualine.highlight'
local highlight = require('lualine.highlight')
local Tab = require('lualine.utils.class'):extend()
---intialize a new tab from opts

View File

@ -1,6 +1,6 @@
-- Copyright (c) 2020-2021 hoob3rt
-- MIT license, see LICENSE for more details.
local utils = require 'lualine.utils.utils'
local utils = require('lualine.utils.utils')
local config = {
options = {
@ -62,10 +62,10 @@ local function apply_configuration(config_table)
config[section_group_name][section_name] = utils.deepcopy(section)
end
end
parse_sections 'options'
parse_sections 'sections'
parse_sections 'inactive_sections'
parse_sections 'tabline'
parse_sections('options')
parse_sections('sections')
parse_sections('inactive_sections')
parse_sections('tabline')
if config_table.extensions then
config.extensions = utils.deepcopy(config_table.extensions)
end

View File

@ -1,6 +1,6 @@
-- Copyright (c) 2020-2021 hoob3rt
-- MIT license, see LICENSE for more details.
local nerdtree = require 'lualine.extensions.nerdtree'
local nerdtree = require('lualine.extensions.nerdtree')
local M = {}

View File

@ -1,6 +1,6 @@
-- MIT license, see LICENSE for more details.
-- Extension for fern file explorer.
local nerdtree = require 'lualine.extensions.nerdtree'
local nerdtree = require('lualine.extensions.nerdtree')
local M = {}

View File

@ -1,6 +1,6 @@
-- Copyright (c) 2020-2021 hoob3rt
-- MIT license, see LICENSE for more details.
local nerdtree = require 'lualine.extensions.nerdtree'
local nerdtree = require('lualine.extensions.nerdtree')
local M = {}

View File

@ -1,12 +1,12 @@
-- Copyright (c) 2020-2021 hoob3rt
-- MIT license, see LICENSE for more details.
local M = {}
local lualine_require = require 'lualine_require'
local lualine_require = require('lualine_require')
local require = lualine_require.require
local modules = lualine_require.lazy_require {
local modules = lualine_require.lazy_require({
utils = 'lualine.utils.utils',
color_utils = 'lualine.utils.color_utils',
}
})
local section_highlight_map = { x = 'c', y = 'b', z = 'a' }
local active_theme = nil
@ -202,7 +202,7 @@ function M.create_component_highlight_group(color, highlight_tag, options)
}
local normal_hl
-- convert lualine_a -> a before setting section
local section = options.self.section:match 'lualine_(.*)'
local section = options.self.section:match('lualine_(.*)')
if section > 'c' and not active_theme.normal[section] then
section = section_highlight_map[section]
end
@ -231,7 +231,7 @@ end
---@return string formatted highlight group name
function M.component_format_highlight(highlight_name)
local highlight_group = highlight_name
if highlight_name:find 'no_mode' == #highlight_name - #'no_mode' + 1 then
if highlight_name:find('no_mode') == #highlight_name - #'no_mode' + 1 then
return '%#' .. highlight_group .. '#'
end
highlight_group = M.append_mode(highlight_group)
@ -251,7 +251,7 @@ end
function M.format_highlight(highlight_group, is_focused)
local highlight_name = M.append_mode(highlight_group, is_focused)
if highlight_group > 'lualine_c' and not M.highlight_exists(highlight_name) then
highlight_group = 'lualine_' .. section_highlight_map[highlight_group:match 'lualine_(.)']
highlight_group = 'lualine_' .. section_highlight_map[highlight_group:match('lualine_(.)')]
highlight_name = M.append_mode(highlight_group, is_focused)
end
if M.highlight_exists(highlight_name) then

View File

@ -1,7 +1,7 @@
-- Copyright (c) 2020-2021 shadmansaleh
-- MIT license, see LICENSE for more details.
local utils = require 'lualine.utils.utils'
local loader = require 'lualine.utils.loader'
local utils = require('lualine.utils.utils')
local loader = require('lualine.utils.loader')
local color_name = vim.g.colors_name
if color_name then
@ -23,7 +23,7 @@ local brightness_modifier_parameter = 10
-- truns #rrggbb -> { red, green, blue }
local function rgb_str2num(rgb_color_str)
if rgb_color_str:find '#' == 1 then
if rgb_color_str:find('#') == 1 then
rgb_color_str = rgb_color_str:sub(2, #rgb_color_str)
end
local red = tonumber(rgb_color_str:sub(1, 2), 16)

View File

@ -1,17 +1,17 @@
-- Copyright (c) 2020-2021 shadmansaleh
-- MIT license, see LICENSE for more details.
local lualine_require = require 'lualine_require'
local modules = lualine_require.lazy_require {
local lualine_require = require('lualine_require')
local modules = lualine_require.lazy_require({
utils_notices = 'lualine.utils.notices',
}
})
local sep = package.config:sub(1, 1)
local wal_colors_path = table.concat({ os.getenv 'HOME', '.cache', 'wal', 'colors.sh' }, sep)
local wal_colors_path = table.concat({ os.getenv('HOME'), '.cache', 'wal', 'colors.sh' }, sep)
local wal_colors_file = io.open(wal_colors_path, 'r')
if wal_colors_file == nil then
modules.utils_notices.add_notice('lualine.nvim: ' .. wal_colors_path .. ' not found')
error ''
error('')
end
local ok, wal_colors_text = pcall(wal_colors_file.read, wal_colors_file, '*a')
@ -19,14 +19,14 @@ wal_colors_file:close()
if not ok then
modules.utils_notices.add_notice('lualine.nvim: ' .. wal_colors_path .. ' could not be read: ' .. wal_colors_text)
error ''
error('')
end
local colors = {}
for line in vim.gsplit(wal_colors_text, '\n') do
if line:match "^[a-z0-9]+='#[a-fA-F0-9]+'$" ~= nil then
local i = line:find '='
if line:match("^[a-z0-9]+='#[a-fA-F0-9]+'$") ~= nil then
local i = line:find('=')
local key = line:sub(0, i - 1)
local value = line:sub(i + 2, #line - 1)
colors[key] = value

View File

@ -12,7 +12,7 @@ function Object:init(...) end
function Object:extend()
local cls = {}
for k, v in pairs(self) do
if k:find '__' == 1 then
if k:find('__') == 1 then
cls[k] = v
end
end

View File

@ -44,9 +44,9 @@ local Job = setmetatable({
end
self.__index = self
local job = setmetatable({ args = args }, self)
job:wrap_cb_alive 'on_stdout'
job:wrap_cb_alive 'on_stderr'
job:wrap_cb_alive 'on_stdin'
job:wrap_cb_alive('on_stdout')
job:wrap_cb_alive('on_stderr')
job:wrap_cb_alive('on_stdin')
return job
end,
})

View File

@ -1,12 +1,12 @@
-- Copyright (c) 2020-2021 hoob3rt
-- MIT license, see LICENSE for more details.
local lualine_require = require 'lualine_require'
local lualine_require = require('lualine_require')
local require = lualine_require.require
local modules = lualine_require.lazy_require {
local modules = lualine_require.lazy_require({
utils = 'lualine.utils.utils',
notice = 'lualine.utils.notices',
}
})
local is_valid_filename = lualine_require.is_valid_filename
local sep = lualine_require.sep
@ -18,7 +18,7 @@ local component_types = {
end,
--- loads lua functions as component
lua_fun = function(component)
return require 'lualine.components.special.function_component'(component)
return require('lualine.components.special.function_component')(component)
end,
--- loads lua modules as components (ones in /lua/lualine/components/)
mod = function(component)
@ -29,7 +29,7 @@ local component_types = {
loaded_component = loaded_component(component)
elseif type(loaded_component) == 'function' then
component[1] = loaded_component
loaded_component = require 'lualine.components.special.function_component'(component)
loaded_component = require('lualine.components.special.function_component')(component)
end
return loaded_component
end
@ -40,15 +40,15 @@ local component_types = {
component[1] = function()
return stl_expr
end
return require 'lualine.components.special.function_component'(component)
return require('lualine.components.special.function_component')(component)
end,
--- loads variables & options (g:,go:,b:,bo:...) as componenta
var = function(component)
return require 'lualine.components.special.vim_var_component'(component)
return require('lualine.components.special.vim_var_component')(component)
end,
--- loads vim functions and lua expressions as components
['_'] = function(component)
return require 'lualine.components.special.eval_func_component'(component)
return require('lualine.components.special.eval_func_component')(component)
end,
}
@ -80,7 +80,7 @@ component type '%s' isn't recognised. Check if spelling is correct.]],
return loaded_component
elseif string.char(component[1]:byte(1)) == '%' then
return component_types.stl(component)
elseif component[1]:find '[gvtwb]?o?:' == 1 then
elseif component[1]:find('[gvtwb]?o?:') == 1 then
return component_types.var(component)
else
return component_types['_'](component)
@ -252,10 +252,10 @@ end
local function load_theme(theme_name)
assert(is_valid_filename(theme_name), 'Invalid filename')
local retval
local path = table.concat { 'lua/lualine/themes/', theme_name, '.lua' }
local path = table.concat({ 'lua/lualine/themes/', theme_name, '.lua' })
local files = vim.api.nvim_get_runtime_file(path, true)
if #files <= 0 then
path = table.concat { 'lua/lualine/themes/', theme_name, '/init.lua' }
path = table.concat({ 'lua/lualine/themes/', theme_name, '/init.lua' })
files = vim.api.nvim_get_runtime_file(path, true)
end
local n_files = #files

View File

@ -30,7 +30,7 @@ end
---are notices available
function M.notice_message_startup()
if #notices > 0 or #persistent_notices then
vim.cmd 'command! -nargs=0 LualineNotices lua require"lualine.utils.notices".show_notices()'
vim.cmd('command! -nargs=0 LualineNotices lua require"lualine.utils.notices".show_notices()')
vim.schedule(function()
vim.notify(
'lualine: There are some issues with your config. Run :LualineNotices for details',
@ -43,7 +43,7 @@ end
---create notice view
function M.show_notices()
vim.cmd 'silent! keepalt split'
vim.cmd('silent! keepalt split')
local winid = vim.fn.win_getid()
local bufnr = vim.api.nvim_create_buf(false, true)
@ -62,14 +62,14 @@ function M.show_notices()
local ok, _ = pcall(vim.api.nvim_buf_set_name, 0, 'Lualine Notices')
if not ok then
vim.notify('Lualine Notices is already open in another buffer', vim.log.levels.ERROR, {})
vim.cmd 'normal q'
vim.cmd('normal q')
return
end
local notice = vim.tbl_flatten(persistent_notices)
notice = vim.list_extend(notice, vim.tbl_flatten(notices))
vim.fn.appendbufline(bufnr, 0, notice)
vim.fn.deletebufline(bufnr, #notice, vim.fn.line '$')
vim.fn.deletebufline(bufnr, #notice, vim.fn.line('$'))
vim.api.nvim_win_set_cursor(winid, { 1, 0 })
vim.bo[bufnr].modified = false
vim.bo[bufnr].modifiable = false

View File

@ -2,8 +2,8 @@
-- MIT license, see LICENSE for more details.
local M = {}
local require = require('lualine_require').require
local utils = require 'lualine.utils.utils'
local highlight = require 'lualine.highlight'
local utils = require('lualine.utils.utils')
local highlight = require('lualine.highlight')
---runs draw function on components in section
---handles separator edge cases :/
@ -95,13 +95,13 @@ function M.draw_section(section, section_name, is_focused)
local needs_hl
local find_start_trans_sep_start, find_start_trans_sep_end = status_str:find '^%%s{.-}'
local find_start_trans_sep_start, find_start_trans_sep_end = status_str:find('^%%s{.-}')
if find_start_trans_sep_start then
-- the section doesn't need to be prepended with default hl when sections
-- first component has trasitionals sep
needs_hl = status_str:find('^%%#', find_start_trans_sep_end + 1)
else
needs_hl = status_str:find '^%%#'
needs_hl = status_str:find('^%%#')
end
if needs_hl then

View File

@ -53,10 +53,10 @@ function M.require(module)
end
end
pattern_path = table.concat { 'lua/', module:gsub('%.', '/'), '.lua' }
pattern_path = table.concat({ 'lua/', module:gsub('%.', '/'), '.lua' })
local paths = vim.api.nvim_get_runtime_file(pattern_path, false)
if #paths <= 0 then
pattern_path = table.concat { 'lua/', module:gsub('%.', '/'), '/init.lua' }
pattern_path = table.concat({ 'lua/', module:gsub('%.', '/'), '/init.lua' })
paths = vim.api.nvim_get_runtime_file(pattern_path, false)
end
if #paths > 0 then

View File

@ -22,7 +22,7 @@ function M.init_component(component, opts)
comp = comp(opts)
elseif type(comp) == 'function' then
opts[1] = comp
comp = require 'lualine.components.special.function_component'(opts)
comp = require('lualine.components.special.function_component')(opts)
end
return comp
end

View File

@ -1,14 +1,14 @@
-- Copyright (c) 2020-2021 shadmansaleh
-- MIT license, see LICENSE for more details.
if os.getenv 'TEST_COV' then
require 'luacov'
if os.getenv('TEST_COV') then
require('luacov')
end
-- load lualine and plenary
vim.cmd [[
vim.cmd([[
set noswapfile
set rtp+=.
set rtp+=../plenary.nvim
set rtp+=../nvim-web-devicons/
runtime plugin/plenary.vim
]]
]])

View File

@ -1,41 +1,41 @@
-- Copyright (c) 2020-2021 shadmansaleh
-- MIT license, see LICENSE for more details.
local helpers = require 'tests.helpers'
local helpers = require('tests.helpers')
local eq = assert.are.same
local neq = assert.are_not.same
local assert_component = helpers.assert_component
local build_component_opts = helpers.build_component_opts
local stub = require 'luassert.stub'
local stub = require('luassert.stub')
describe('Component:', function()
it('can select separators', function()
local opts = build_component_opts()
local comp = require 'lualine.components.special.function_component'(opts)
local comp = require('lualine.components.special.function_component')(opts)
-- correct for lualine_c
eq('', comp.options.separator)
local opts2 = build_component_opts { self = { section = 'lualine_y' } }
local comp2 = require 'lualine.components.special.function_component'(opts2)
local opts2 = build_component_opts({ self = { section = 'lualine_y' } })
local comp2 = require('lualine.components.special.function_component')(opts2)
-- correct for lualine_u
eq('', comp2.options.separator)
end)
it('can provide unique identifier', function()
local opts1 = build_component_opts()
local comp1 = require 'lualine.components.special.function_component'(opts1)
local comp1 = require('lualine.components.special.function_component')(opts1)
local opts2 = build_component_opts()
local comp2 = require 'lualine.components.special.function_component'(opts2)
local comp2 = require('lualine.components.special.function_component')(opts2)
neq(comp1.component_no, comp2.component_no)
end)
it('create option highlights', function()
local color = { fg = '#224532', bg = '#892345' }
local opts1 = build_component_opts { color = color }
local hl = require 'lualine.highlight'
local opts1 = build_component_opts({ color = color })
local hl = require('lualine.highlight')
stub(hl, 'create_component_highlight_group')
hl.create_component_highlight_group.returns 'MyCompHl'
local comp1 = require 'lualine.components.special.function_component'(opts1)
hl.create_component_highlight_group.returns('MyCompHl')
local comp1 = require('lualine.components.special.function_component')(opts1)
eq('MyCompHl', comp1.options.color_highlight)
-- color highlight wan't in options when create_comp_hl was
-- called so remove it before assert
@ -43,10 +43,10 @@ describe('Component:', function()
assert.stub(hl.create_component_highlight_group).was_called_with(color, comp1.options.component_name, comp1.options)
hl.create_component_highlight_group:revert()
color = 'MyHl'
local opts2 = build_component_opts { color = color }
local opts2 = build_component_opts({ color = color })
stub(hl, 'create_component_highlight_group')
hl.create_component_highlight_group.returns 'MyCompLinkedHl'
local comp2 = require 'lualine.components.special.function_component'(opts2)
hl.create_component_highlight_group.returns('MyCompLinkedHl')
local comp2 = require('lualine.components.special.function_component')(opts2)
eq('MyCompLinkedHl', comp2.options.color_highlight)
-- color highlight wan't in options when create_comp_hl was
-- called so remove it before assert
@ -56,147 +56,147 @@ describe('Component:', function()
end)
it('can draw', function()
local opts = build_component_opts {
local opts = build_component_opts({
component_separators = { left = '', right = '' },
padding = 0,
}
})
assert_component(nil, opts, 'test')
end)
it('can apply separators', function()
local opts = build_component_opts { padding = 0 }
local opts = build_component_opts({ padding = 0 })
assert_component(nil, opts, 'test')
end)
it('can apply default highlight', function()
local opts = build_component_opts { padding = 0, hl = '%#My_highlight#' }
local opts = build_component_opts({ padding = 0, hl = '%#My_highlight#' })
assert_component(nil, opts, '%#My_highlight#test')
opts = build_component_opts {
opts = build_component_opts({
function()
return '%#Custom_hl#test'
end,
padding = 0,
hl = '%#My_highlight#',
}
})
assert_component(nil, opts, '%#Custom_hl#test%#My_highlight#')
opts = build_component_opts {
opts = build_component_opts({
function()
return 'in middle%#Custom_hl#test'
end,
padding = 0,
hl = '%#My_highlight#',
}
})
assert_component(nil, opts, '%#My_highlight#in middle%#Custom_hl#test%#My_highlight#')
end)
describe('Global options:', function()
it('left_padding', function()
local opts = build_component_opts {
local opts = build_component_opts({
component_separators = { left = '', right = '' },
padding = { left = 5 },
}
})
assert_component(nil, opts, ' test')
end)
it('right_padding', function()
local opts = build_component_opts {
local opts = build_component_opts({
component_separators = { left = '', right = '' },
padding = { right = 5 },
}
})
assert_component(nil, opts, 'test ')
end)
it('padding', function()
local opts = build_component_opts {
local opts = build_component_opts({
component_separators = { left = '', right = '' },
padding = 5,
}
})
assert_component(nil, opts, ' test ')
end)
it('icon', function()
local opts = build_component_opts {
local opts = build_component_opts({
component_separators = { left = '', right = '' },
padding = 0,
icon = '0',
}
})
assert_component(nil, opts, '0 test')
end)
it('icons_enabled', function()
local opts = build_component_opts {
local opts = build_component_opts({
component_separators = { left = '', right = '' },
padding = 0,
icons_enabled = true,
icon = '0',
}
})
assert_component(nil, opts, '0 test')
local opts2 = build_component_opts {
local opts2 = build_component_opts({
component_separators = { left = '', right = '' },
padding = 0,
icons_enabled = false,
icon = '0',
}
})
assert_component(nil, opts2, 'test')
end)
it('separator', function()
local opts = build_component_opts {
local opts = build_component_opts({
component_separators = { left = '', right = '' },
padding = 0,
separator = '|',
}
})
assert_component(nil, opts, 'test|')
end)
it('fmt', function()
local opts = build_component_opts {
local opts = build_component_opts({
component_separators = { left = '', right = '' },
padding = 0,
fmt = function(data)
return data:sub(1, 1):upper() .. data:sub(2, #data)
end,
}
})
assert_component(nil, opts, 'Test')
end)
it('cond', function()
local opts = build_component_opts {
local opts = build_component_opts({
component_separators = { left = '', right = '' },
padding = 0,
cond = function()
return true
end,
}
})
assert_component(nil, opts, 'test')
local opts2 = build_component_opts {
local opts2 = build_component_opts({
component_separators = { left = '', right = '' },
padding = 0,
cond = function()
return false
end,
}
})
assert_component(nil, opts2, '')
end)
it('color', function()
local opts = build_component_opts {
local opts = build_component_opts({
component_separators = { left = '', right = '' },
padding = 0,
color = 'MyHl',
}
local comp = require 'lualine.components.special.function_component'(opts)
})
local comp = require('lualine.components.special.function_component')(opts)
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 {
local opts2 = build_component_opts({
component_separators = { left = '', right = '' },
padding = 0,
color = { bg = '#230055', fg = '#223344' },
}
local hl = require 'lualine.highlight'
})
local hl = require('lualine.highlight')
stub(hl, 'component_format_highlight')
hl.component_format_highlight.returns '%#MyCompHl#'
local comp2 = require 'lualine.components.special.function_component'(opts2)
hl.component_format_highlight.returns('%#MyCompHl#')
local comp2 = require('lualine.components.special.function_component')(opts2)
assert_component(nil, opts2, '%#MyCompHl#test')
assert.stub(hl.component_format_highlight).was_called_with(comp2.options.color_highlight)
hl.component_format_highlight:revert()
@ -206,27 +206,27 @@ end)
describe('Encoding component', function()
it('works', function()
local opts = build_component_opts {
local opts = build_component_opts({
component_separators = { left = '', right = '' },
padding = 0,
}
})
local tmp_path = 'tmp.txt'
local tmp_fp = io.open(tmp_path, 'w')
tmp_fp:write 'test file'
tmp_fp:write('test file')
tmp_fp:close()
vim.cmd('e ' .. tmp_path)
assert_component('encoding', opts, 'utf-8')
vim.cmd 'bd!'
vim.cmd('bd!')
os.remove(tmp_path)
end)
end)
describe('Fileformat component', function()
it('works with icons', function()
local opts = build_component_opts {
local opts = build_component_opts({
component_separators = { left = '', right = '' },
padding = 0,
}
})
local fmt = vim.bo.fileformat
vim.bo.fileformat = 'unix'
assert_component('fileformat', opts, '')
@ -237,11 +237,11 @@ describe('Fileformat component', function()
vim.bo.fileformat = fmt
end)
it('works without icons', function()
local opts = build_component_opts {
local opts = build_component_opts({
component_separators = { left = '', right = '' },
padding = 0,
icons_enabled = false,
}
})
assert_component('fileformat', opts, vim.bo.fileformat)
end)
end)
@ -262,14 +262,14 @@ describe('Filetype component', function()
local old_require = _G.require
function _G.require(...)
if select(1, ...) == 'nvim-web-devicons' then
error 'Test case not suppose to have web-dev-icon 👀'
error('Test case not suppose to have web-dev-icon 👀')
end
return old_require(...)
end
local opts = build_component_opts {
local opts = build_component_opts({
component_separators = { left = '', right = '' },
padding = 0,
}
})
assert_component('filetype', opts, 'lua')
_G.require = old_require
end)
@ -281,19 +281,19 @@ describe('Filetype component', function()
end,
}
local hl = require 'lualine.highlight'
local utils = require 'lualine.utils.utils'
local hl = require('lualine.highlight')
local utils = require('lualine.utils.utils')
stub(hl, 'create_component_highlight_group')
stub(utils, 'extract_highlight_colors')
hl.create_component_highlight_group.returns 'MyCompHl'
utils.extract_highlight_colors.returns '#000'
hl.create_component_highlight_group.returns('MyCompHl')
utils.extract_highlight_colors.returns('#000')
local opts = build_component_opts {
local opts = build_component_opts({
component_separators = { left = '', right = '' },
padding = 0,
colored = true,
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')
assert.stub(hl.create_component_highlight_group).was_called_with({ fg = '#000' }, 'test_highlight_group', opts)
@ -308,17 +308,17 @@ describe('Filetype component', function()
return '*', 'test_highlight_group'
end,
}
local hl = require 'lualine.highlight'
local utils = require 'lualine.utils.utils'
local hl = require('lualine.highlight')
local utils = require('lualine.utils.utils')
stub(hl, 'create_component_highlight_group')
stub(utils, 'extract_highlight_colors')
hl.create_component_highlight_group.returns 'MyCompHl'
utils.extract_highlight_colors.returns '#000'
local opts = build_component_opts {
hl.create_component_highlight_group.returns('MyCompHl')
utils.extract_highlight_colors.returns('#000')
local opts = build_component_opts({
component_separators = { left = '', right = '' },
padding = 0,
colored = false,
}
})
assert_component('filetype', opts, '* lua')
hl.create_component_highlight_group:revert()
utils.extract_highlight_colors:revert()
@ -332,12 +332,12 @@ describe('Filetype component', function()
end,
}
local opts = build_component_opts {
local opts = build_component_opts({
component_separators = { left = '', right = '' },
padding = 0,
colored = false,
icon_only = true,
}
})
assert_component('filetype', opts, '*')
package.loaded['nvim-web-devicons'] = nil
end)
@ -346,11 +346,11 @@ end)
describe('Hostname component', function()
it('works', function()
stub(vim.loop, 'os_gethostname')
vim.loop.os_gethostname.returns 'localhost'
local opts = build_component_opts {
vim.loop.os_gethostname.returns('localhost')
local opts = build_component_opts({
component_separators = { left = '', right = '' },
padding = 0,
}
})
assert_component('hostname', opts, 'localhost')
vim.loop.os_gethostname:revert()
end)
@ -358,20 +358,20 @@ end)
describe('Location component', function()
it('works', function()
local opts = build_component_opts {
local opts = build_component_opts({
component_separators = { left = '', right = '' },
padding = 0,
}
})
assert_component('location', opts, '%3l:%-2v')
end)
end)
describe('Progress component', function()
it('works', function()
local opts = build_component_opts {
local opts = build_component_opts({
component_separators = { left = '', right = '' },
padding = 0,
}
})
assert_component('progress', opts, '%3p%%')
end)
end)
@ -379,11 +379,11 @@ end)
describe('Mode component', function()
it('works', function()
stub(vim.api, 'nvim_get_mode')
vim.api.nvim_get_mode.returns { mode = 'n', blocking = false }
local opts = build_component_opts {
vim.api.nvim_get_mode.returns({ mode = 'n', blocking = false })
local opts = build_component_opts({
component_separators = { left = '', right = '' },
padding = 0,
}
})
assert_component('mode', opts, 'NORMAL')
vim.api.nvim_get_mode:revert()
end)
@ -391,17 +391,17 @@ end)
describe('FileSize component', function()
it('works', function()
local opts = build_component_opts {
local opts = build_component_opts({
component_separators = { left = '', right = '' },
padding = 0,
}
})
local fname = 'test-file.txt'
local f = io.open(fname, 'w')
f:write(string.rep('........................................\n', 200))
f:close()
vim.cmd(':edit ' .. fname)
assert_component('filesize', opts, '8.0k')
vim.cmd ':bdelete!'
vim.cmd(':bdelete!')
os.remove(fname)
end)
end)
@ -421,25 +421,25 @@ describe('Filename component', function()
end
it('works', function()
local opts = build_component_opts {
local opts = build_component_opts({
component_separators = { left = '', right = '' },
padding = 0,
file_status = false,
path = 0,
}
vim.cmd ':e test-file.txt'
})
vim.cmd(':e test-file.txt')
assert_component('filename', opts, 'test-file.txt')
vim.cmd ':bdelete!'
vim.cmd(':bdelete!')
end)
it('can show file_status', function()
local opts = build_component_opts {
local opts = build_component_opts({
component_separators = { left = '', right = '' },
padding = 0,
file_status = true,
path = 0,
}
vim.cmd ':e test-file.txt'
})
vim.cmd(':e test-file.txt')
vim.bo.modified = false
assert_component('filename', opts, 'test-file.txt')
vim.bo.modified = true
@ -447,39 +447,39 @@ describe('Filename component', function()
vim.bo.modified = false
vim.bo.ro = true
assert_component('filename', opts, 'test-file.txt[-]')
vim.cmd ':bdelete!'
vim.cmd(':bdelete!')
end)
it('can show relative path', function()
local opts = build_component_opts {
local opts = build_component_opts({
component_separators = { left = '', right = '' },
padding = 0,
file_status = false,
path = 1,
}
vim.cmd ':e test-file.txt'
assert_component('filename', opts, shorten_path(vim.fn.expand '%:~:.'))
vim.cmd ':bdelete!'
})
vim.cmd(':e test-file.txt')
assert_component('filename', opts, shorten_path(vim.fn.expand('%:~:.')))
vim.cmd(':bdelete!')
end)
it('can show full path', function()
local opts = build_component_opts {
local opts = build_component_opts({
component_separators = { left = '', right = '' },
padding = 0,
file_status = false,
path = 2,
}
vim.cmd ':e test-file.txt'
assert_component('filename', opts, shorten_path(vim.fn.expand '%:p'))
vim.cmd ':bdelete!'
})
vim.cmd(':e test-file.txt')
assert_component('filename', opts, shorten_path(vim.fn.expand('%:p')))
vim.cmd(':bdelete!')
end)
end)
describe('vim option & variable component', function()
local opts = build_component_opts {
local opts = build_component_opts({
component_separators = { left = '', right = '' },
padding = 0,
}
})
local function assert_vim_var_component(name, options, result)
options[1] = name
@ -514,10 +514,10 @@ describe('vim option & variable component', function()
end)
describe('Vim option & variable component', function()
local opts = build_component_opts {
local opts = build_component_opts({
component_separators = { left = '', right = '' },
padding = 0,
}
})
local function assert_vim_var_component(name, options, result)
options[1] = name
@ -526,13 +526,13 @@ describe('Vim option & variable component', function()
end
it('works with vim function', function()
vim.cmd [[
vim.cmd([[
func! TestFunction() abort
return "TestVimFunction"
endf
]]
]])
assert_vim_var_component('TestFunction', opts, 'TestVimFunction')
vim.cmd 'delfunction TestFunction'
vim.cmd('delfunction TestFunction')
end)
it('works with lua expression', function()
@ -557,11 +557,11 @@ describe('Branch component', function()
os.remove(tmpdir)
file = tmpdir .. '/test.txt'
vim.fn.mkdir(tmpdir, 'p')
git 'init -b test_branch'
vim.cmd [[aug lualine
git('init -b test_branch')
vim.cmd([[aug lualine
au!
aug END
]]
]])
end)
after_each(function()
@ -569,16 +569,16 @@ describe('Branch component', function()
end)
it('works with regular branches', function()
local opts = build_component_opts {
local opts = build_component_opts({
component_separators = { left = '', right = '' },
padding = 0,
}
})
local branch_comp = helpers.init_component('branch', opts)
vim.cmd('e ' .. file)
assert_comp_ins(branch_comp, ' test_branch')
git 'checkout -b test_branch2'
vim.cmd 'e k'
vim.cmd 'bd'
git('checkout -b test_branch2')
vim.cmd('e k')
vim.cmd('bd')
vim.cmd('e ' .. file)
opts.icons_enabled = false
assert_comp_ins(branch_comp, 'test_branch2')

View File

@ -4,12 +4,12 @@
local eq = assert.are.same
describe('config parsing', function()
local config_module = require 'lualine.config'
local config_module = require('lualine.config')
describe('options', function()
describe('icons_enabled', function()
it('default', function()
local config = config_module.apply_configuration {}
local config = config_module.apply_configuration({})
eq(config.options.icons_enabled, true)
end)
it('custom', function()
@ -21,7 +21,7 @@ describe('config parsing', function()
describe('theme', function()
it('default', function()
local config = config_module.apply_configuration {}
local config = config_module.apply_configuration({})
eq(config.options.theme, 'auto')
end)
it('custom', function()
@ -36,7 +36,7 @@ describe('config parsing', function()
describe('separators', function()
it('default', function()
local config = config_module.apply_configuration {}
local config = config_module.apply_configuration({})
eq(config.options.component_separators, { left = '', right = '' })
eq(config.options.section_separators, { left = '', right = '' })
end)
@ -85,7 +85,7 @@ describe('config parsing', function()
describe('disabled filetypes', function()
it('default', function()
local config = config_module.apply_configuration {}
local config = config_module.apply_configuration({})
eq(config.options.disabled_filetypes, {})
end)
it('custom', function()

View File

@ -4,7 +4,7 @@
local eq = assert.are.same
describe('Lualine', function()
local utils = require 'lualine.utils.utils'
local utils = require('lualine.utils.utils')
local lualine_focused = true
utils.is_focused = function()
return lualine_focused
@ -51,7 +51,7 @@ describe('Lualine', function()
extensions = {},
}
before_each(function()
vim.cmd 'bufdo bdelete'
vim.cmd('bufdo bdelete')
pcall(vim.cmd, 'tabdo tabclose')
lualine_focused = true
require('lualine').setup(config)

View File

@ -1,26 +1,26 @@
-- Copyright (c) 2020-2021 shadmansaleh
-- MIT license, see LICENSE for more details.
local helpers = require 'tests.helpers'
local helpers = require('tests.helpers')
local eq = assert.are.same
local build_component_opts = helpers.build_component_opts
describe('Utils', function()
local utils = require 'lualine.utils.utils'
local utils = require('lualine.utils.utils')
it('can retrive highlight groups', function()
local hl2 = { fg = '#aabbcc', bg = '#889977', reverse = true }
-- handles non existing hl groups
eq(utils.extract_highlight_colors 'hl2', nil)
eq(utils.extract_highlight_colors('hl2'), nil)
-- create highlight
vim.cmd(string.format('hi hl2 guifg=%s guibg=%s gui=reverse', hl2.fg, hl2.bg))
-- Can retrive entire highlight table
eq(utils.extract_highlight_colors 'hl2', hl2)
eq(utils.extract_highlight_colors('hl2'), hl2)
-- Can retrive specific parts of highlight
eq(utils.extract_highlight_colors('hl2', 'fg'), hl2.fg)
-- clear hl2
vim.cmd 'hi clear hl2'
vim.cmd('hi clear hl2')
end)
it('can shrink list with holes', function()
@ -44,7 +44,7 @@ describe('Utils', function()
end)
describe('Cterm genarator', function()
local cterm = require 'lualine.utils.color_utils'
local cterm = require('lualine.utils.color_utils')
it('can convert rgb to cterm', function()
local colors = { ['#112233'] = 235, ['#7928ae'] = 97, ['#017bdc'] = 68 }
@ -55,32 +55,32 @@ describe('Cterm genarator', function()
end)
describe('Section genarator', function()
local sec = require 'lualine.utils.section'
local sec = require('lualine.utils.section')
it('can draw', function()
local opts = build_component_opts { section_separators = { left = '', right = '' } }
local opts = build_component_opts({ section_separators = { left = '', right = '' } })
local section = {
require 'lualine.components.special.function_component'(opts),
require 'lualine.components.special.function_component'(opts),
require('lualine.components.special.function_component')(opts),
require('lualine.components.special.function_component')(opts),
}
eq('%#lualine_MySection_normal# test %#lualine_MySection_normal# test ', sec.draw_section(section, 'MySection'))
end)
it('can remove separators from component with custom colors', function()
local opts = build_component_opts { section_separators = { left = '', right = '' } }
local opts_colored = build_component_opts { color = 'MyColor' }
local opts_colored2 = build_component_opts {
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 = { left = '', right = '' },
}
local opts_colored3 = build_component_opts {
})
local opts_colored3 = build_component_opts({
color = { fg = '#223344' },
section_separators = { left = '', right = '' },
}
require('lualine.highlight').create_highlight_groups(require 'lualine.themes.gruvbox')
})
require('lualine.highlight').create_highlight_groups(require('lualine.themes.gruvbox'))
local section = {
require 'lualine.components.special.function_component'(opts),
require 'lualine.components.special.function_component'(opts_colored),
require 'lualine.components.special.function_component'(opts),
require('lualine.components.special.function_component')(opts),
require('lualine.components.special.function_component')(opts_colored),
require('lualine.components.special.function_component')(opts),
}
local highlight_name2 = 'lualine_' .. section[2].options.component_name .. '_no_mode'
-- Removes separator on string color
@ -88,14 +88,14 @@ describe('Section genarator', function()
'%#lualine_MySection_normal# test %#' .. highlight_name2 .. '#' .. ' test %#lualine_MySection_normal# test ',
sec.draw_section(section, 'MySection')
)
section[2] = require 'lua.lualine.components.special.function_component'(opts_colored2)
section[2] = require('lua.lualine.components.special.function_component')(opts_colored2)
local highlight_name = '%#lualine_c_' .. section[2].options.component_name .. '_normal#'
-- Removes separator on color with bg
eq(
'%#lualine_MySection_normal# test ' .. highlight_name .. ' test %#lualine_MySection_normal# test ',
sec.draw_section(section, 'MySection')
)
section[2] = require 'lua.lualine.components.special.function_component'(opts_colored3)
section[2] = require('lua.lualine.components.special.function_component')(opts_colored3)
highlight_name2 = '%#lualine_c_' .. section[2].options.component_name .. '_normal#'
-- Doesn't remove separator on color without bg
eq(