235 lines
5.9 KiB
Lua
235 lines
5.9 KiB
Lua
local orange = '#d65d0e'
|
||
local bright = '#ffffff' -- alternative: '#f9f5d7'
|
||
|
||
local M = { 'nvim-lualine/lualine.nvim' }
|
||
|
||
M.dependencies = {
|
||
'nvim-tree/nvim-web-devicons',
|
||
}
|
||
|
||
M.config = function()
|
||
local window = require 'fschauen.window'
|
||
|
||
local filename = (function()
|
||
local C = require('lualine.component'):extend()
|
||
|
||
function C:init(options)
|
||
C.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 C:update_status(is_focused)
|
||
self.options.color_highlight = self.custom_highlights[is_focused][vim.bo.modified]
|
||
|
||
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
|
||
|
||
return C
|
||
end)()
|
||
|
||
local mode = (function()
|
||
local C = require('lualine.component'):extend()
|
||
|
||
C.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 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 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 trailing_whitespace = {
|
||
colored_if_focused(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),
|
||
|
||
color = { bg = orange },
|
||
|
||
cond = function()
|
||
return vim.bo.filetype ~= 'help'
|
||
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 = {
|
||
lualine_a = {
|
||
paste,
|
||
mode
|
||
},
|
||
lualine_b = {
|
||
{ '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',
|
||
trailing_whitespace,
|
||
},
|
||
}
|
||
|
||
require('lualine').setup {
|
||
options = {
|
||
icons_enabled = true,
|
||
component_separators = {
|
||
left = '',
|
||
right = ''
|
||
},
|
||
section_separators = {
|
||
left = '',
|
||
right = ''
|
||
},
|
||
theme = 'gruvbox',
|
||
},
|
||
sections = sections,
|
||
inactive_sections = sections,
|
||
extensions = {
|
||
'fugitive',
|
||
'quickfix',
|
||
'nvim-tree',
|
||
'lazy',
|
||
'man',
|
||
'trouble',
|
||
},
|
||
}
|
||
end
|
||
|
||
return M
|
||
|