vim/lualine: make plugin config self-contained
This commit is contained in:
parent
56aa86df56
commit
5da88d464b
2 changed files with 180 additions and 216 deletions
|
@ -1,151 +0,0 @@
|
||||||
local M = {}
|
|
||||||
|
|
||||||
-- filename component
|
|
||||||
|
|
||||||
M.filename = require('lualine.component'):extend()
|
|
||||||
|
|
||||||
function M.filename:init(options)
|
|
||||||
M.filename.super.init(self, options)
|
|
||||||
|
|
||||||
local color = options.color or {}
|
|
||||||
local modified = { gui = 'italic' }
|
|
||||||
|
|
||||||
self.custom_highlights = { -- [is_focused, modified]
|
|
||||||
[true] = {
|
|
||||||
[true] = self:create_hl(vim.tbl_extend('force', color, modified), 'focus_modified'),
|
|
||||||
[false] = self:create_hl(color, 'focus'),
|
|
||||||
},
|
|
||||||
[false] = {
|
|
||||||
[true] = self:create_hl(modified, 'nofocus_modified'),
|
|
||||||
[false] = self:create_hl({}, 'nofocus'),
|
|
||||||
},
|
|
||||||
}
|
|
||||||
end
|
|
||||||
|
|
||||||
function M.filename:update_status(is_focused)
|
|
||||||
self.options.color_highlight = self.custom_highlights[is_focused][vim.bo.modified]
|
|
||||||
|
|
||||||
local window = require 'fschauen.window'
|
|
||||||
local path = vim.fn.expand('%:~:.')
|
|
||||||
|
|
||||||
if window.is_wide() then
|
|
||||||
return path
|
|
||||||
elseif window.is_medium() then
|
|
||||||
return vim.fn.pathshorten(path) -- only first letter of directories
|
|
||||||
else
|
|
||||||
return vim.fn.fnamemodify(path, ':t') -- only tail
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
-- mode component
|
|
||||||
|
|
||||||
M.mode = require('lualine.component'):extend()
|
|
||||||
|
|
||||||
M.mode.map = {
|
|
||||||
['n'] = '', -- 'Normal ', -- Normal
|
|
||||||
['no'] = '', -- 'O-Pend ', -- Operator-pending
|
|
||||||
['ni'] = '', -- 'Normal ', -- Normal via i_CTRL-O
|
|
||||||
['v'] = '', -- 'Visual ', -- Visual by character
|
|
||||||
[''] = '', -- 'V-Block', -- Visual blockwise
|
|
||||||
['s'] = '', -- 'Select ', -- Select by character
|
|
||||||
[''] = '', -- 'S-Block', -- Select blockwise
|
|
||||||
['i'] = '', -- 'Insert ', -- Insert
|
|
||||||
['r'] = '', -- 'Replace', -- Replace
|
|
||||||
['rv'] = '', -- 'V-Repl ', -- Virtual Replace
|
|
||||||
['c'] = '', -- 'Command', -- Command-line
|
|
||||||
['cv'] = '', -- ' Ex ', -- Ex mode
|
|
||||||
['rm'] = '', -- ' modeore ', -- -- modeORE --
|
|
||||||
['r?'] = '', -- 'Confirm', -- :confirm
|
|
||||||
['!'] = '', -- ' Shell ', -- External command executing
|
|
||||||
['t'] = '', -- ' Term ', -- Terminal
|
|
||||||
}
|
|
||||||
|
|
||||||
function M.mode:update_status(is_focused)
|
|
||||||
if is_focused then
|
|
||||||
local code = vim.api.nvim_get_mode().mode:lower()
|
|
||||||
local symbol = M.mode.map[code:sub(1, 2)] or M.mode.map[code:sub(1, 1)] or code
|
|
||||||
return ' ' .. symbol .. ' '
|
|
||||||
end
|
|
||||||
|
|
||||||
return ' '
|
|
||||||
end
|
|
||||||
|
|
||||||
-- searchcount component
|
|
||||||
|
|
||||||
M.searchcount = require('lualine.component'):extend()
|
|
||||||
|
|
||||||
function M.searchcount:init(options)
|
|
||||||
M.searchcount.super.init(self, options)
|
|
||||||
self.options = vim.tbl_extend('keep', self.options or {}, {
|
|
||||||
maxcount = 999,
|
|
||||||
timeout = 250,
|
|
||||||
})
|
|
||||||
end
|
|
||||||
|
|
||||||
function M.searchcount:update_status()
|
|
||||||
if vim.v.hlsearch == 0 then
|
|
||||||
return ''
|
|
||||||
end
|
|
||||||
|
|
||||||
local count = vim.fn.searchcount {
|
|
||||||
maxcount = self.options.maxcount,
|
|
||||||
timeout = self.options.timeout
|
|
||||||
}
|
|
||||||
if next(count) == nil then
|
|
||||||
return ''
|
|
||||||
end
|
|
||||||
|
|
||||||
local denominator = count.total > count.maxcount and '' or string.format('%d', count.total)
|
|
||||||
return string.format(' %d/%s', count.current, denominator)
|
|
||||||
end
|
|
||||||
|
|
||||||
-- trailing_whitespace component
|
|
||||||
|
|
||||||
M.trailing_whitespace = function()
|
|
||||||
local pattern = [[\s\+$]]
|
|
||||||
local lineno = vim.fn.search(pattern, 'nwc')
|
|
||||||
if lineno == 0 then
|
|
||||||
return ''
|
|
||||||
end
|
|
||||||
|
|
||||||
local result = '·' .. lineno
|
|
||||||
|
|
||||||
local info = vim.fn.searchcount { pattern = pattern }
|
|
||||||
if info.total then
|
|
||||||
result = result .. string.format(' Σ%d', info.total)
|
|
||||||
end
|
|
||||||
|
|
||||||
return result
|
|
||||||
end
|
|
||||||
|
|
||||||
-- modifier to color component when window is in focus
|
|
||||||
|
|
||||||
M.colored_if_focused = function(component)
|
|
||||||
if type(component) == 'string' then
|
|
||||||
local c = require('lualine.components.' .. component):extend()
|
|
||||||
|
|
||||||
function c:update_status(is_focused)
|
|
||||||
self.options.colored = is_focused
|
|
||||||
return c.super.update_status(self, is_focused)
|
|
||||||
end
|
|
||||||
|
|
||||||
return c
|
|
||||||
elseif type(component) == 'function' then
|
|
||||||
local c = require('lualine.component'):extend()
|
|
||||||
|
|
||||||
function c:init(options)
|
|
||||||
c.super.init(self, options)
|
|
||||||
self.saved_hl = self.options.color_highlight
|
|
||||||
end
|
|
||||||
|
|
||||||
function c:update_status(is_focused)
|
|
||||||
self.options.color_highlight = is_focused and self.saved_hl or nil
|
|
||||||
return component(is_focused)
|
|
||||||
end
|
|
||||||
|
|
||||||
return c
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
return M
|
|
||||||
|
|
|
@ -9,76 +9,191 @@ M.dependencies = {
|
||||||
|
|
||||||
M.config = function()
|
M.config = function()
|
||||||
local window = require 'fschauen.window'
|
local window = require 'fschauen.window'
|
||||||
local colored_if_focused = require('fschauen.lualine').colored_if_focused
|
|
||||||
|
|
||||||
-- custom components
|
local filename = (function()
|
||||||
local C = {
|
local C = require('lualine.component'):extend()
|
||||||
diagnostics = {
|
|
||||||
colored_if_focused('diagnostics'),
|
function C:init(options)
|
||||||
},
|
C.super.init(self, options)
|
||||||
diff = {
|
|
||||||
colored_if_focused('diff'),
|
local color = options.color or {}
|
||||||
symbols = {
|
local modified = { gui = 'italic' }
|
||||||
added = '',
|
|
||||||
modified = '',
|
self.custom_highlights = { -- [is_focused, modified]
|
||||||
removed = '',
|
[true] = {
|
||||||
},
|
[true] = self:create_hl(vim.tbl_extend('force', color, modified), 'focus_modified'),
|
||||||
},
|
[false] = self:create_hl(color, 'focus'),
|
||||||
branch = {
|
},
|
||||||
'branch',
|
[false] = {
|
||||||
icon = '',
|
[true] = self:create_hl(modified, 'nofocus_modified'),
|
||||||
cond = window.is_medium,
|
[false] = self:create_hl({}, 'nofocus'),
|
||||||
},
|
},
|
||||||
fileformat = {
|
}
|
||||||
'fileformat',
|
end
|
||||||
cond = window.is_medium,
|
|
||||||
},
|
function C:update_status(is_focused)
|
||||||
filename = {
|
self.options.color_highlight = self.custom_highlights[is_focused][vim.bo.modified]
|
||||||
require('fschauen.lualine').filename,
|
|
||||||
padding = {
|
local path = vim.fn.expand('%:~:.')
|
||||||
left = 1,
|
|
||||||
right = 0,
|
if window.is_wide() then
|
||||||
},
|
return path
|
||||||
},
|
elseif window.is_medium() then
|
||||||
filetype = {
|
return vim.fn.pathshorten(path) -- only first letter of directories
|
||||||
colored_if_focused('filetype'),
|
else
|
||||||
cond = window.is_medium,
|
return vim.fn.fnamemodify(path, ':t') -- only tail
|
||||||
},
|
end
|
||||||
mode = require('fschauen.lualine').mode,
|
end
|
||||||
paste = {
|
|
||||||
colored_if_focused(function(has_focus) return has_focus and '' or ' ' end),
|
return C
|
||||||
color = {
|
end)()
|
||||||
bg = orange,
|
|
||||||
},
|
local mode = (function()
|
||||||
cond = function() return vim.o.paste end
|
local C = require('lualine.component'):extend()
|
||||||
},
|
|
||||||
searchcount = require('fschauen.lualine').searchcount,
|
C.map = {
|
||||||
status = {
|
['n'] = '', -- 'Normal ', -- Normal
|
||||||
colored_if_focused(function(_)
|
['no'] = '', -- 'O-Pend ', -- Operator-pending
|
||||||
local status = ''
|
['ni'] = '', -- 'Normal ', -- Normal via i_CTRL-O
|
||||||
if vim.bo.modified then status = status .. '' end
|
['v'] = '', -- 'Visual ', -- Visual by character
|
||||||
if vim.bo.readonly or not vim.bo.modifiable then status = status .. 'RO' end
|
[''] = '', -- 'V-Block', -- Visual blockwise
|
||||||
return status
|
['s'] = '', -- 'Select ', -- Select by character
|
||||||
end),
|
[''] = '', -- 'S-Block', -- Select blockwise
|
||||||
color = {
|
['i'] = '', -- 'Insert ', -- Insert
|
||||||
fg = bright,
|
['r'] = '', -- 'Replace', -- Replace
|
||||||
},
|
['rv'] = '', -- 'V-Repl ', -- Virtual Replace
|
||||||
},
|
['c'] = '', -- 'Command', -- Command-line
|
||||||
trailing_whitespace = {
|
['cv'] = '', -- ' Ex ', -- Ex mode
|
||||||
colored_if_focused(require('fschauen.lualine').trailing_whitespace),
|
['rm'] = '', -- ' modeore ', -- -- modeORE --
|
||||||
color = {
|
['r?'] = '', -- 'Confirm', -- :confirm
|
||||||
bg = orange,
|
['!'] = '', -- ' Shell ', -- External command executing
|
||||||
},
|
['t'] = '', -- ' Term ', -- Terminal
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function C:update_status(is_focused)
|
||||||
|
if not is_focused then return ' ' end
|
||||||
|
|
||||||
|
local code = vim.api.nvim_get_mode().mode:lower()
|
||||||
|
local symbol = C.map[code:sub(1, 2)] or C.map[code:sub(1, 1)] or code
|
||||||
|
return ' ' .. symbol .. ' '
|
||||||
|
end
|
||||||
|
|
||||||
|
return C
|
||||||
|
end)()
|
||||||
|
|
||||||
|
local searchcount = (function()
|
||||||
|
local C = require('lualine.component'):extend()
|
||||||
|
|
||||||
|
function C:init(options)
|
||||||
|
C.super.init(self, options)
|
||||||
|
self.options = vim.tbl_extend('keep', self.options or {}, {
|
||||||
|
maxcount = 999,
|
||||||
|
timeout = 250,
|
||||||
|
})
|
||||||
|
end
|
||||||
|
|
||||||
|
function C:update_status()
|
||||||
|
if vim.v.hlsearch == 0 then return '' end
|
||||||
|
|
||||||
|
local count = vim.fn.searchcount {
|
||||||
|
maxcount = self.options.maxcount,
|
||||||
|
timeout = self.options.timeout
|
||||||
|
}
|
||||||
|
if next(count) == nil then return '' end
|
||||||
|
|
||||||
|
local denominator = count.total > count.maxcount and '' or string.format('%d', count.total)
|
||||||
|
return string.format(' %d/%s', count.current, denominator)
|
||||||
|
end
|
||||||
|
|
||||||
|
return C
|
||||||
|
end)()
|
||||||
|
|
||||||
|
local trailing_whitespace = function()
|
||||||
|
local trailing = [[\s\+$]]
|
||||||
|
local lineno = vim.fn.search(trailing, 'nwc')
|
||||||
|
if lineno == 0 then return '' end
|
||||||
|
|
||||||
|
local result = ' ' .. lineno
|
||||||
|
|
||||||
|
local total = vim.fn.searchcount({ pattern = trailing }).total
|
||||||
|
if total > 1 then result = result .. string.format(' (%d total)', total) end
|
||||||
|
|
||||||
|
return result
|
||||||
|
end
|
||||||
|
|
||||||
|
local colored_if_focused = function(component)
|
||||||
|
if type(component) == 'string' then
|
||||||
|
local C = require('lualine.components.' .. component):extend()
|
||||||
|
|
||||||
|
function C:update_status(is_focused)
|
||||||
|
self.options.colored = is_focused
|
||||||
|
return C.super.update_status(self, is_focused)
|
||||||
|
end
|
||||||
|
|
||||||
|
return C
|
||||||
|
|
||||||
|
elseif type(component) == 'function' then
|
||||||
|
local C = require('lualine.component'):extend()
|
||||||
|
|
||||||
|
function C:init(options)
|
||||||
|
C.super.init(self, options)
|
||||||
|
self.saved_hl = self.options.color_highlight
|
||||||
|
end
|
||||||
|
|
||||||
|
function C:update_status(is_focused)
|
||||||
|
self.options.color_highlight = is_focused and self.saved_hl or nil
|
||||||
|
return component(is_focused)
|
||||||
|
end
|
||||||
|
|
||||||
|
return C
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
local paste = {
|
||||||
|
colored_if_focused(function(has_focus) return has_focus and '' or ' ' end),
|
||||||
|
color = {
|
||||||
|
bg = orange,
|
||||||
|
},
|
||||||
|
cond = function() return vim.o.paste end
|
||||||
|
}
|
||||||
|
|
||||||
|
local status = {
|
||||||
|
colored_if_focused(function(_)
|
||||||
|
local status = ''
|
||||||
|
if vim.bo.modified then status = status .. '' end
|
||||||
|
if vim.bo.readonly or not vim.bo.modifiable then status = status .. 'RO' end
|
||||||
|
return status
|
||||||
|
end),
|
||||||
|
color = {
|
||||||
|
fg = bright,
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
local sections = {
|
local sections = {
|
||||||
lualine_a = { C.paste, C.mode },
|
lualine_a = {
|
||||||
lualine_b = { C.branch },
|
paste,
|
||||||
lualine_c = { C.filename, C.status },
|
mode
|
||||||
lualine_x = { C.diagnostics, C.searchcount, C.filetype },
|
},
|
||||||
lualine_y = { C.fileformat, 'progress' },
|
lualine_b = {
|
||||||
lualine_z = { 'location', C.trailing_whitespace },
|
{ 'branch', icon = '', cond = window.is_medium },
|
||||||
|
},
|
||||||
|
lualine_c = {
|
||||||
|
filename,
|
||||||
|
status,
|
||||||
|
},
|
||||||
|
lualine_x = {
|
||||||
|
colored_if_focused('diagnostics'),
|
||||||
|
searchcount,
|
||||||
|
{ colored_if_focused('filetype'), cond = window.is_medium },
|
||||||
|
},
|
||||||
|
lualine_y = {
|
||||||
|
{ 'fileformat', cond = window.is_medium },
|
||||||
|
'progress',
|
||||||
|
},
|
||||||
|
lualine_z = {
|
||||||
|
'location',
|
||||||
|
{ colored_if_focused(trailing_whitespace), color = { bg = orange } },
|
||||||
|
},
|
||||||
}
|
}
|
||||||
|
|
||||||
require('lualine').setup {
|
require('lualine').setup {
|
||||||
|
|
Loading…
Add table
Reference in a new issue