vim/lualine: fix filename italics and refactor component extensions
This commit is contained in:
parent
0ef1cba81f
commit
31b9a726eb
3 changed files with 167 additions and 124 deletions
|
@ -1,134 +1,100 @@
|
||||||
local M = {}
|
local filename = require('lualine.component'):extend()
|
||||||
|
|
||||||
local window = require('fschauen.window')
|
function filename:init(options)
|
||||||
|
filename.super.init(self, options)
|
||||||
|
|
||||||
local colored_when_focused = function(component)
|
local color = options.color or {}
|
||||||
local new = require(component):extend()
|
local modified = { gui = 'italic' }
|
||||||
function new:update_status(is_focused)
|
|
||||||
self.options.colored = is_focused
|
self.custom_highlights = { -- [is_focused, modified]
|
||||||
return self.super.update_status(self, is_focused)
|
[true] = {
|
||||||
end
|
[true] = self:create_hl(vim.tbl_extend('force', color, modified), 'focus_modified'),
|
||||||
return new
|
[false] = self:create_hl(color, 'focus'),
|
||||||
|
},
|
||||||
|
[false] = {
|
||||||
|
[true] = self:create_hl(modified, 'nofocus_modified'),
|
||||||
|
[false] = self:create_hl({}, 'nofocus'),
|
||||||
|
},
|
||||||
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
local diagnostics = colored_when_focused('lualine.components.diagnostics')
|
function filename:update_status(is_focused)
|
||||||
|
self.options.color_highlight = self.custom_highlights[is_focused][vim.bo.modified]
|
||||||
|
|
||||||
local branch = {
|
local window = require 'fschauen.window'
|
||||||
'branch',
|
local path = vim.fn.expand('%:~:.')
|
||||||
icon = '',
|
|
||||||
cond = window.is_medium,
|
|
||||||
}
|
|
||||||
|
|
||||||
local fileformat = {
|
if window.is_wide() then
|
||||||
'fileformat',
|
return path
|
||||||
cond = window.is_medium,
|
elseif window.is_medium() then
|
||||||
}
|
return vim.fn.pathshorten(path) -- only first letter of directories
|
||||||
|
|
||||||
local filename = {
|
|
||||||
function()
|
|
||||||
local shorten_path = function(path)
|
|
||||||
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
|
|
||||||
|
|
||||||
return shorten_path(vim.fn.expand('%:~:.'))
|
|
||||||
end,
|
|
||||||
|
|
||||||
padding = { left = 1, right = 0 },
|
|
||||||
}
|
|
||||||
|
|
||||||
local filetype = {
|
|
||||||
colored_when_focused('lualine.components.filetype'),
|
|
||||||
cond = window.is_medium,
|
|
||||||
}
|
|
||||||
|
|
||||||
local mode = {
|
|
||||||
(function()
|
|
||||||
local MODES = {
|
|
||||||
['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'] = ' ', -- ' More ', -- -- MORE --
|
|
||||||
['r?'] = ' ', -- 'Confirm', -- :confirm
|
|
||||||
['!'] = ' ', -- ' Shell ', -- External command executing
|
|
||||||
['t'] = ' ', -- ' Term ', -- Terminal
|
|
||||||
}
|
|
||||||
return function()
|
|
||||||
local code = vim.api.nvim_get_mode().mode
|
|
||||||
return MODES[code:sub(1, 2):lower()] or MODES[code:sub(1, 1):lower()] or code
|
|
||||||
end
|
|
||||||
end)()
|
|
||||||
}
|
|
||||||
|
|
||||||
local mode_placeholder = {
|
|
||||||
function()
|
|
||||||
return ' '
|
|
||||||
end
|
|
||||||
}
|
|
||||||
|
|
||||||
local paste = {
|
|
||||||
function() return '' end,
|
|
||||||
color = { bg = '#fe8019' },
|
|
||||||
cond = function() return vim.opt.paste:get() end
|
|
||||||
}
|
|
||||||
|
|
||||||
local paste_placeholder = {
|
|
||||||
function() return ' ' end,
|
|
||||||
cond = function() return vim.opt.paste:get() end
|
|
||||||
}
|
|
||||||
|
|
||||||
local status = {
|
|
||||||
function()
|
|
||||||
local flags = vim.list_extend(
|
|
||||||
vim.bo.modified and { '✶' } or {},
|
|
||||||
(vim.bo.readonly or not vim.bo.modifiable) and { 'RO' } or {})
|
|
||||||
return vim.fn.join(flags, ' ')
|
|
||||||
end,
|
|
||||||
|
|
||||||
color = {
|
|
||||||
fg = '#f9f5d7',
|
|
||||||
gui = 'bold',
|
|
||||||
},
|
|
||||||
}
|
|
||||||
|
|
||||||
local visual_multi = function()
|
|
||||||
local info = vim.F.npcall(vim.fn.VMInfos)
|
|
||||||
if info and info.status then
|
|
||||||
return info.current .. '/' .. info.total .. ' ' .. info.status
|
|
||||||
else
|
else
|
||||||
return ''
|
return vim.fn.fnamemodify(path, ':t') -- only tail
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local default = {
|
|
||||||
lualine_a = { paste_placeholder, mode_placeholder },
|
local mode = require('lualine.component'):extend()
|
||||||
lualine_b = { visual_multi, branch },
|
|
||||||
lualine_c = { filename, status },
|
mode.map = {
|
||||||
lualine_x = { diagnostics, filetype },
|
['n'] = '', -- 'Normal ', -- Normal
|
||||||
lualine_y = { fileformat, 'progress' },
|
['no'] = '', -- 'O-Pend ', -- Operator-pending
|
||||||
lualine_z = { 'location' },
|
['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
|
||||||
}
|
}
|
||||||
|
|
||||||
M.sections = {
|
function mode:update_status(is_focused)
|
||||||
inactive = default,
|
if is_focused then
|
||||||
active = vim.tbl_extend('force', default, {
|
local code = vim.api.nvim_get_mode().mode:lower()
|
||||||
lualine_a = { paste, mode },
|
local symbol = mode.map[code:sub(1, 2)] or mode.map[code:sub(1, 1)] or code
|
||||||
})
|
return ' ' .. symbol .. ' '
|
||||||
|
end
|
||||||
|
|
||||||
|
return ' '
|
||||||
|
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
|
||||||
|
|
||||||
|
return {
|
||||||
|
colored_if_focused = colored_if_focused,
|
||||||
|
filename = filename,
|
||||||
|
mode = mode,
|
||||||
}
|
}
|
||||||
|
|
||||||
return M
|
|
||||||
|
|
||||||
|
|
|
@ -1,7 +1,73 @@
|
||||||
return {
|
return {
|
||||||
'nvim-lualine/lualine.nvim',
|
'nvim-lualine/lualine.nvim',
|
||||||
opts = function()
|
config = function()
|
||||||
return {
|
local window = require 'fschauen.window'
|
||||||
|
local colored_if_focused = require('fschauen.lualine').colored_if_focused
|
||||||
|
|
||||||
|
-- custom components
|
||||||
|
local C = {
|
||||||
|
diagnostics = {
|
||||||
|
colored_if_focused('diagnostics'),
|
||||||
|
},
|
||||||
|
diff = {
|
||||||
|
colored_if_focused('diff'),
|
||||||
|
symbols = {
|
||||||
|
added = '',
|
||||||
|
modified = '',
|
||||||
|
removed = '',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
branch = {
|
||||||
|
'branch',
|
||||||
|
icon = '',
|
||||||
|
cond = window.is_medium,
|
||||||
|
},
|
||||||
|
fileformat = {
|
||||||
|
'fileformat',
|
||||||
|
cond = window.is_medium,
|
||||||
|
},
|
||||||
|
filename = {
|
||||||
|
require('fschauen.lualine').filename,
|
||||||
|
padding = {
|
||||||
|
left = 1,
|
||||||
|
right = 0,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
filetype = {
|
||||||
|
colored_if_focused('filetype'),
|
||||||
|
cond = window.is_medium,
|
||||||
|
},
|
||||||
|
mode = require('fschauen.lualine').mode,
|
||||||
|
paste = {
|
||||||
|
colored_if_focused(function(has_focus) return has_focus and '' or ' ' end),
|
||||||
|
color = {
|
||||||
|
bg = '#fe8019',
|
||||||
|
},
|
||||||
|
cond = function() return vim.o.paste end
|
||||||
|
},
|
||||||
|
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 = '#f9f5d7',
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
|
local sections = {
|
||||||
|
lualine_a = { C.paste, C.mode },
|
||||||
|
lualine_b = { C.branch },
|
||||||
|
lualine_c = { C.filename, C.status },
|
||||||
|
lualine_x = { C.diagnostics, C.filetype },
|
||||||
|
lualine_y = { C.fileformat, 'progress' },
|
||||||
|
lualine_z = { 'location' },
|
||||||
|
}
|
||||||
|
|
||||||
|
require('lualine').setup {
|
||||||
options = {
|
options = {
|
||||||
icons_enabled = true,
|
icons_enabled = true,
|
||||||
component_separators = {
|
component_separators = {
|
||||||
|
@ -14,8 +80,8 @@ return {
|
||||||
},
|
},
|
||||||
theme = 'gruvbox',
|
theme = 'gruvbox',
|
||||||
},
|
},
|
||||||
sections = require('fschauen.lualine').sections.active,
|
sections = sections,
|
||||||
inactive_sections = require('fschauen.lualine').sections.inactive,
|
inactive_sections = sections,
|
||||||
extensions = {
|
extensions = {
|
||||||
'fugitive',
|
'fugitive',
|
||||||
'quickfix',
|
'quickfix',
|
||||||
|
|
|
@ -6,3 +6,14 @@ return {
|
||||||
end,
|
end,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
-- Component for lualine:
|
||||||
|
-- function()
|
||||||
|
-- local info = vim.F.npcall(vim.fn.VMInfos)
|
||||||
|
-- if info and info.status then
|
||||||
|
-- return info.current .. '/' .. info.total .. ' ' .. info.status
|
||||||
|
-- else
|
||||||
|
-- return ''
|
||||||
|
-- end
|
||||||
|
-- end,
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue