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_type = "Spaces"
indent_width = 2 indent_width = 2
quote_style = "AutoPreferSingle" 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 = { options = {
theme = bubbles_theme, theme = bubbles_theme,
component_separators = '|', component_separators = '|',
@ -59,4 +59,4 @@ require('lualine').setup {
}, },
tabline = {}, tabline = {},
extensions = {}, extensions = {},
} })

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -2,7 +2,7 @@
-- MIT license, see LICENSE for more details. -- MIT license, see LICENSE for more details.
local M = require('lualine.component'):extend() local M = require('lualine.component'):extend()
local require = require('lualine_require').require 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 -- Initilizer
M.init = function(self, options) 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() local Buffer = require('lualine.utils.class'):extend()
---intialize a new buffer from opts ---intialize a new buffer from opts
@ -26,13 +26,13 @@ function Buffer:get_props()
if not status then if not status then
dev, _ = '', '' dev, _ = '', ''
elseif self.filetype == 'TelescopePrompt' then 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 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 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 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 elseif vim.fn.isdirectory(self.file) == 1 then
dev, _ = '', nil dev, _ = '', nil
else else

View File

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

View File

@ -1,5 +1,5 @@
local require = require('lualine_require').require local require = require('lualine_require').require
local utils = require 'lualine.utils.utils' local utils = require('lualine.utils.utils')
local M = {} local M = {}
-- default symbols for diagnostics component -- default symbols for diagnostics component
@ -18,7 +18,7 @@ M.options = {
colored = true, colored = true,
update_in_insert = false, update_in_insert = false,
always_visible = 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' }, sections = { 'error', 'warn', 'info', 'hint' },
diagnostics_color = { diagnostics_color = {
error = { error = {

View File

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

View File

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

View File

@ -1,12 +1,12 @@
-- Copyright (c) 2020-2021 shadmansaleh -- Copyright (c) 2020-2021 shadmansaleh
-- MIT license, see LICENSE for more details. -- MIT license, see LICENSE for more details.
local lualine_require = require 'lualine_require' local lualine_require = require('lualine_require')
local modules = lualine_require.lazy_require { local modules = lualine_require.lazy_require({
git_diff = 'lualine.components.diff.git_diff', git_diff = 'lualine.components.diff.git_diff',
utils = 'lualine.utils.utils', utils = 'lualine.utils.utils',
utils_notices = 'lualine.utils.notices', utils_notices = 'lualine.utils.notices',
highlight = 'lualine.highlight', highlight = 'lualine.highlight',
} })
local M = lualine_require.require('lualine.component'):extend() local M = lualine_require.require('lualine.component'):extend()
local default_options = { local default_options = {
@ -81,7 +81,7 @@ function M:update_status(is_focused)
local result = {} local result = {}
-- loop though data and load available sections in result table -- 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 git_diff[name] and git_diff[name] > 0 then
if self.options.colored then if self.options.colored then
table.insert(result, colors[name] .. self.options.symbols[name] .. git_diff[name]) 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 local data
if self.options.path == 1 then if self.options.path == 1 then
-- relative path -- relative path
data = vim.fn.expand '%:~:.' data = vim.fn.expand('%:~:.')
elseif self.options.path == 2 then elseif self.options.path == 2 then
-- absolute path -- absolute path
data = vim.fn.expand '%:p' data = vim.fn.expand('%:p')
else else
-- just filename -- just filename
data = vim.fn.expand '%:t' data = vim.fn.expand('%:t')
end end
if data == '' then if data == '' then

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -53,10 +53,10 @@ function M.require(module)
end end
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) local paths = vim.api.nvim_get_runtime_file(pattern_path, false)
if #paths <= 0 then 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) paths = vim.api.nvim_get_runtime_file(pattern_path, false)
end end
if #paths > 0 then if #paths > 0 then

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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