Skip to content

Commit

Permalink
perf(lualine.nvim): improve statusline stylish (#426)
Browse files Browse the repository at this point in the history
  • Loading branch information
linrongbin16 authored Jan 4, 2024
1 parent 94c09b8 commit 105502c
Showing 1 changed file with 19 additions and 32 deletions.
51 changes: 19 additions & 32 deletions lua/configs/nvim-lualine/lualine-nvim/config.lua
Original file line number Diff line number Diff line change
@@ -1,33 +1,18 @@
local function GitDiff()
if vim.g.loaded_gitgutter == nil or vim.g.loaded_gitgutter <= 0 then
return {}
end
local changes = vim.fn["GitGutterGetHunkSummary"]()
if changes == nil or #changes ~= 3 then
return {}
end
return { added = changes[1], modified = changes[2], removed = changes[3] }
local function GitDiffCondition()
return vim.fn.exists("*GitGutterGetHunkSummary") > 0
end

local function Search()
if vim.v.hlsearch == 0 then
return ""
end
local lastsearch = vim.fn.getreg("/")
if not lastsearch or lastsearch == "" then
return ""
end
local searchcount = vim.fn.searchcount({ maxcount = 9999 })
return lastsearch
.. "("
.. searchcount.current
.. "/"
.. searchcount.total
.. ")"
local function GitDiffSource()
local changes = vim.fn.GitGutterGetHunkSummary() or {}
return {
added = changes[1] or 0,
modified = changes[2] or 0,
removed = changes[3] or 0,
}
end

local function Location()
return " %3l:%-2v"
return " %l:%v"
end

local constants = require("builtin.utils.constants")
Expand All @@ -48,7 +33,7 @@ local config = {
component_separators = empty_component_separators,
section_separators = slash_section_separators,
refresh = {
statusline = 1000,
statusline = 3000,
tabline = 10000,
winbar = 10000,
},
Expand All @@ -61,15 +46,17 @@ local config = {
"branch",
{
"diff",
source = GitDiff,
cond = GitDiffCondition,
source = GitDiffSource,
padding = { left = 0, right = 1 },
},
},
lualine_c = {
"filename",
{ "filename", file_status = true, path = 4 },
require("lsp-progress").progress,
},
lualine_x = {
Search,
{ "searchcount", maxcount = 100, timeout = 300 },
{
"diagnostics",
symbols = {
Expand All @@ -90,8 +77,8 @@ local config = {
},
"encoding",
},
lualine_y = { "progress" },
lualine_z = { Location },
lualine_y = { Location },
lualine_z = { "progress" },
},
inactive_sections = {},
tabline = {},
Expand All @@ -106,7 +93,7 @@ require("lualine").setup(config)
vim.api.nvim_create_augroup("lualine_augroup", { clear = true })
vim.api.nvim_create_autocmd("User", {
group = "lualine_augroup",
pattern = "LspProgressStatusUpdated",
pattern = { "LspProgressStatusUpdated", "GitGutter" },
callback = function()
require("lualine").refresh({
place = { "statusline" },
Expand Down

0 comments on commit 105502c

Please sign in to comment.