my-nvim-setup/lua/plugins/configs/statusline.lua

392 lines
9.6 KiB
Lua
Raw Normal View History

Restructure config | Move some to a packer plugin | Lot of cleanup * move teleacope files, updater and related utils to https://github.com/NvChad/core * restructure config file and directory structure * expose mappings for better escape * allow multiple mappings for some * improve merge table function for the same * move autocommands to a seperate file * rearrange everything alphabetically where sanely possible * rearrange packer plugin list on the basis of trigerred state config structure now . ├── init.lua ├── LICENSE ├── lua │ ├── chadrc.lua │ ├── colors │ │ ├── highlights.lua │ │ ├── init.lua │ │ └── themes │ │ ├── chadracula.lua │ │ ├── everforest.lua │ │ ├── gruvchad.lua │ │ ├── javacafe.lua │ │ ├── mountain.lua │ │ ├── norchad.lua │ │ ├── one-light.lua │ │ ├── onedark.lua │ │ ├── tokyonight.lua │ │ └── tomorrow-night.lua │ ├── core │ │ ├── autocmds.lua │ │ ├── init.lua │ │ ├── mappings.lua │ │ ├── options.lua │ │ └── utils.lua │ ├── default_config.lua │ └── plugins │ ├── configs │ │ ├── autopairs.lua │ │ ├── autosave.lua │ │ ├── bufferline.lua │ │ ├── chadsheet.lua │ │ ├── compe.lua │ │ ├── dashboard.lua │ │ ├── gitsigns.lua │ │ ├── icons.lua │ │ ├── lspconfig.lua │ │ ├── luasnip.lua │ │ ├── nvimtree.lua │ │ ├── others.lua │ │ ├── statusline.lua │ │ ├── telescope.lua │ │ ├── treesitter.lua │ │ └── zenmode.lua │ ├── init.lua │ └── packerInit.lua └── README.md
2021-08-22 08:49:15 +01:00
local colors = require("colors").get()
2021-08-26 06:18:13 +01:00
local lsp = require "feline.providers.lsp"
local icon_styles = {
default = {
left = "",
right = "",
main_icon = "",
vi_mode_icon = "",
position_icon = "",
},
Restructure config | Move some to a packer plugin | Lot of cleanup * move teleacope files, updater and related utils to https://github.com/NvChad/core * restructure config file and directory structure * expose mappings for better escape * allow multiple mappings for some * improve merge table function for the same * move autocommands to a seperate file * rearrange everything alphabetically where sanely possible * rearrange packer plugin list on the basis of trigerred state config structure now . ├── init.lua ├── LICENSE ├── lua │ ├── chadrc.lua │ ├── colors │ │ ├── highlights.lua │ │ ├── init.lua │ │ └── themes │ │ ├── chadracula.lua │ │ ├── everforest.lua │ │ ├── gruvchad.lua │ │ ├── javacafe.lua │ │ ├── mountain.lua │ │ ├── norchad.lua │ │ ├── one-light.lua │ │ ├── onedark.lua │ │ ├── tokyonight.lua │ │ └── tomorrow-night.lua │ ├── core │ │ ├── autocmds.lua │ │ ├── init.lua │ │ ├── mappings.lua │ │ ├── options.lua │ │ └── utils.lua │ ├── default_config.lua │ └── plugins │ ├── configs │ │ ├── autopairs.lua │ │ ├── autosave.lua │ │ ├── bufferline.lua │ │ ├── chadsheet.lua │ │ ├── compe.lua │ │ ├── dashboard.lua │ │ ├── gitsigns.lua │ │ ├── icons.lua │ │ ├── lspconfig.lua │ │ ├── luasnip.lua │ │ ├── nvimtree.lua │ │ ├── others.lua │ │ ├── statusline.lua │ │ ├── telescope.lua │ │ ├── treesitter.lua │ │ └── zenmode.lua │ ├── init.lua │ └── packerInit.lua └── README.md
2021-08-22 08:49:15 +01:00
arrow = {
left = "",
right = "",
main_icon = "",
vi_mode_icon = "",
position_icon = "",
},
block = {
left = " ",
right = " ",
main_icon = "",
2021-08-27 09:18:04 +01:00
vi_mode_icon = "",
position_icon = "",
},
2021-08-19 13:05:24 +01:00
Restructure config | Move some to a packer plugin | Lot of cleanup * move teleacope files, updater and related utils to https://github.com/NvChad/core * restructure config file and directory structure * expose mappings for better escape * allow multiple mappings for some * improve merge table function for the same * move autocommands to a seperate file * rearrange everything alphabetically where sanely possible * rearrange packer plugin list on the basis of trigerred state config structure now . ├── init.lua ├── LICENSE ├── lua │ ├── chadrc.lua │ ├── colors │ │ ├── highlights.lua │ │ ├── init.lua │ │ └── themes │ │ ├── chadracula.lua │ │ ├── everforest.lua │ │ ├── gruvchad.lua │ │ ├── javacafe.lua │ │ ├── mountain.lua │ │ ├── norchad.lua │ │ ├── one-light.lua │ │ ├── onedark.lua │ │ ├── tokyonight.lua │ │ └── tomorrow-night.lua │ ├── core │ │ ├── autocmds.lua │ │ ├── init.lua │ │ ├── mappings.lua │ │ ├── options.lua │ │ └── utils.lua │ ├── default_config.lua │ └── plugins │ ├── configs │ │ ├── autopairs.lua │ │ ├── autosave.lua │ │ ├── bufferline.lua │ │ ├── chadsheet.lua │ │ ├── compe.lua │ │ ├── dashboard.lua │ │ ├── gitsigns.lua │ │ ├── icons.lua │ │ ├── lspconfig.lua │ │ ├── luasnip.lua │ │ ├── nvimtree.lua │ │ ├── others.lua │ │ ├── statusline.lua │ │ ├── telescope.lua │ │ ├── treesitter.lua │ │ └── zenmode.lua │ ├── init.lua │ └── packerInit.lua └── README.md
2021-08-22 08:49:15 +01:00
round = {
left = "",
right = "",
main_icon = "",
vi_mode_icon = "",
position_icon = "",
},
slant = {
left = "",
right = "",
2021-08-19 13:05:24 +01:00
main_icon = "",
vi_mode_icon = "",
position_icon = "",
},
}
Restructure config | Move some to a packer plugin | Lot of cleanup * move teleacope files, updater and related utils to https://github.com/NvChad/core * restructure config file and directory structure * expose mappings for better escape * allow multiple mappings for some * improve merge table function for the same * move autocommands to a seperate file * rearrange everything alphabetically where sanely possible * rearrange packer plugin list on the basis of trigerred state config structure now . ├── init.lua ├── LICENSE ├── lua │ ├── chadrc.lua │ ├── colors │ │ ├── highlights.lua │ │ ├── init.lua │ │ └── themes │ │ ├── chadracula.lua │ │ ├── everforest.lua │ │ ├── gruvchad.lua │ │ ├── javacafe.lua │ │ ├── mountain.lua │ │ ├── norchad.lua │ │ ├── one-light.lua │ │ ├── onedark.lua │ │ ├── tokyonight.lua │ │ └── tomorrow-night.lua │ ├── core │ │ ├── autocmds.lua │ │ ├── init.lua │ │ ├── mappings.lua │ │ ├── options.lua │ │ └── utils.lua │ ├── default_config.lua │ └── plugins │ ├── configs │ │ ├── autopairs.lua │ │ ├── autosave.lua │ │ ├── bufferline.lua │ │ ├── chadsheet.lua │ │ ├── compe.lua │ │ ├── dashboard.lua │ │ ├── gitsigns.lua │ │ ├── icons.lua │ │ ├── lspconfig.lua │ │ ├── luasnip.lua │ │ ├── nvimtree.lua │ │ ├── others.lua │ │ ├── statusline.lua │ │ ├── telescope.lua │ │ ├── treesitter.lua │ │ └── zenmode.lua │ ├── init.lua │ └── packerInit.lua └── README.md
2021-08-22 08:49:15 +01:00
local user_statusline_style = require("core.utils").load_config().ui.plugin.statusline.style
local statusline_style = icon_styles[user_statusline_style]
2021-08-26 06:18:13 +01:00
-- Initialize the components table
local components = {
left = { active = {}, inactive = {} },
mid = { active = {}, inactive = {} },
right = { active = {}, inactive = {} },
}
2021-08-26 06:18:13 +01:00
components.left.active[1] = {
provider = statusline_style.main_icon,
hl = {
fg = colors.statusline_bg,
bg = colors.nord_blue,
},
2021-08-26 06:18:13 +01:00
right_sep = { str = statusline_style.right, hl = {
fg = colors.nord_blue,
bg = colors.one_bg2,
} },
}
2021-08-26 06:18:13 +01:00
components.left.active[2] = {
provider = statusline_style.right,
hl = {
fg = colors.one_bg2,
bg = colors.lightbg,
2021-08-19 13:05:24 +01:00
},
}
2021-08-26 06:18:13 +01:00
components.left.active[3] = {
provider = function()
local filename = vim.fn.expand "%:t"
local extension = vim.fn.expand "%:e"
local icon = require("nvim-web-devicons").get_icon(filename, extension)
if icon == nil then
icon = ""
return icon
end
return icon .. " " .. filename .. " "
end,
hl = {
fg = colors.white,
bg = colors.lightbg,
},
2021-08-26 06:18:13 +01:00
right_sep = { str = statusline_style.right, hl = { fg = colors.lightbg, bg = colors.lightbg2 } },
}
2021-08-19 13:43:58 +01:00
2021-08-26 06:18:13 +01:00
components.left.active[4] = {
provider = function()
local dir_name = vim.fn.fnamemodify(vim.fn.getcwd(), ":t")
2021-08-28 02:18:51 +01:00
return "" .. dir_name .. " "
2021-08-26 06:18:13 +01:00
end,
2021-08-19 13:43:58 +01:00
2021-08-26 06:18:13 +01:00
hl = {
fg = colors.grey_fg2,
bg = colors.lightbg2,
},
2021-08-26 06:18:13 +01:00
right_sep = { str = statusline_style.right, hi = {
fg = colors.lightbg2,
bg = colors.statusline_bg,
} },
}
2021-08-26 06:18:13 +01:00
components.left.active[5] = {
provider = "git_diff_added",
hl = {
fg = colors.grey_fg2,
bg = colors.statusline_bg,
},
2021-08-26 06:18:13 +01:00
icon = "",
}
2021-08-26 06:18:13 +01:00
-- diffModfified
components.left.active[6] = {
provider = "git_diff_changed",
hl = {
fg = colors.grey_fg2,
bg = colors.statusline_bg,
},
2021-08-26 06:18:13 +01:00
icon = "",
}
2021-08-26 06:18:13 +01:00
-- diffRemove
components.left.active[7] = {
provider = "git_diff_removed",
hl = {
fg = colors.grey_fg2,
bg = colors.statusline_bg,
},
2021-08-26 06:18:13 +01:00
icon = "",
}
2021-08-26 06:18:13 +01:00
components.left.active[8] = {
provider = "diagnostic_errors",
enabled = function()
return lsp.diagnostics_exist "Error"
end,
hl = { fg = colors.red },
icon = "",
}
2021-08-26 06:18:13 +01:00
components.left.active[9] = {
provider = "diagnostic_warnings",
enabled = function()
return lsp.diagnostics_exist "Warning"
end,
hl = { fg = colors.yellow },
icon = "",
}
2021-08-26 06:18:13 +01:00
components.left.active[10] = {
provider = "diagnostic_hints",
enabled = function()
return lsp.diagnostics_exist "Hint"
end,
hl = { fg = colors.grey_fg2 },
icon = "",
}
2021-08-26 06:18:13 +01:00
components.left.active[11] = {
provider = "diagnostic_info",
enabled = function()
return lsp.diagnostics_exist "Information"
end,
hl = { fg = colors.green },
icon = "",
}
2021-08-26 08:52:48 +01:00
components.mid.active[1] = {
provider = function()
local Lsp = vim.lsp.util.get_progress_messages()[1]
if Lsp then
local msg = Lsp.message or ""
local percentage = Lsp.percentage or 0
local title = Lsp.title or ""
local spinners = {
"",
"",
"",
}
local success_icon = {
"",
"",
"",
2021-08-26 08:52:48 +01:00
}
local ms = vim.loop.hrtime() / 1000000
local frame = math.floor(ms / 120) % #spinners
if percentage >= 70 then
return string.format(" %%<%s %s %s (%s%%%%) ", success_icon[frame + 1], title, msg, percentage)
else
return string.format(" %%<%s %s %s (%s%%%%) ", spinners[frame + 1], title, msg, percentage)
end
2021-08-26 08:52:48 +01:00
end
return ""
end,
hl = { fg = colors.green },
}
2021-08-26 06:18:13 +01:00
components.right.active[1] = {
provider = function()
2021-08-26 06:29:37 +01:00
if next(vim.lsp.buf_get_clients()) ~= nil then
2021-08-27 09:18:04 +01:00
return " LSP"
2021-08-26 06:29:37 +01:00
else
return ""
2021-08-26 06:18:13 +01:00
end
end,
hl = { fg = colors.grey_fg2, bg = colors.statusline_bg },
}
components.right.active[2] = {
-- taken from: https://github.com/hoob3rt/lualine.nvim/blob/master/lua/lualine/components/branch.lua
provider = function()
local git_branch = ""
-- first try with gitsigns
local gs_dict = vim.b.gitsigns_status_dict
if gs_dict then
git_branch = (gs_dict.head and #gs_dict.head > 0 and gs_dict.head) or git_branch
else
-- path seperator
local branch_sep = package.config:sub(1, 1)
-- get file dir so we can search from that dir
local file_dir = vim.fn.expand "%:p:h" .. ";"
-- find .git/ folder genaral case
local git_dir = vim.fn.finddir(".git", file_dir)
-- find .git file in case of submodules or any other case git dir is in
-- any other place than .git/
local git_file = vim.fn.findfile(".git", file_dir)
-- for some weird reason findfile gives relative path so expand it to fullpath
if #git_file > 0 then
git_file = vim.fn.fnamemodify(git_file, ":p")
end
if #git_file > #git_dir then
-- separate git-dir or submodule is used
local file = io.open(git_file)
git_dir = file:read()
git_dir = git_dir:match "gitdir: (.+)$"
file:close()
-- submodule / relative file path
if git_dir:sub(1, 1) ~= branch_sep and not git_dir:match "^%a:.*$" then
git_dir = git_file:match "(.*).git" .. git_dir
end
end
if #git_dir > 0 then
local head_file = git_dir .. branch_sep .. "HEAD"
local f_head = io.open(head_file)
if f_head then
local HEAD = f_head:read()
f_head:close()
local branch = HEAD:match "ref: refs/heads/(.+)$"
if branch then
git_branch = branch
else
git_branch = HEAD:sub(1, 6)
end
end
end
end
return (git_branch ~= "" and "" .. git_branch) or git_branch
end,
2021-08-26 06:18:13 +01:00
hl = {
fg = colors.grey_fg2,
bg = colors.statusline_bg,
},
}
2021-08-26 06:18:13 +01:00
components.right.active[3] = {
provider = " " .. statusline_style.left,
hl = {
fg = colors.one_bg2,
bg = colors.statusline_bg,
},
}
local mode_colors = {
2021-08-26 06:18:13 +01:00
["n"] = { "NORMAL", colors.red },
["no"] = { "N-PENDING", colors.red },
["i"] = { "INSERT", colors.dark_purple },
["ic"] = { "INSERT", colors.dark_purple },
["t"] = { "TERMINAL", colors.green },
["v"] = { "VISUAL", colors.cyan },
["V"] = { "V-LINE", colors.cyan },
[""] = { "V-BLOCK", colors.cyan },
["R"] = { "REPLACE", colors.orange },
["Rv"] = { "V-REPLACE", colors.orange },
["s"] = { "SELECT", colors.nord_blue },
["S"] = { "S-LINE", colors.nord_blue },
[""] = { "S-BLOCK", colors.nord_blue },
["c"] = { "COMMAND", colors.pink },
["cv"] = { "COMMAND", colors.pink },
["ce"] = { "COMMAND", colors.pink },
["r"] = { "PROMPT", colors.teal },
["rm"] = { "MORE", colors.teal },
["r?"] = { "CONFIRM", colors.teal },
["!"] = { "SHELL", colors.green },
}
2021-08-26 06:18:13 +01:00
local chad_mode_hl = function()
return {
fg = mode_colors[vim.fn.mode()][2],
bg = colors.one_bg,
}
2021-08-13 07:42:43 +01:00
end
2021-08-26 06:18:13 +01:00
components.right.active[4] = {
provider = statusline_style.left,
hl = function()
return {
fg = mode_colors[vim.fn.mode()][2],
bg = colors.one_bg2,
}
end,
2021-08-19 13:05:24 +01:00
}
2021-08-26 06:18:13 +01:00
components.right.active[5] = {
provider = statusline_style.vi_mode_icon,
hl = function()
return {
fg = colors.statusline_bg,
bg = mode_colors[vim.fn.mode()][2],
}
end,
2021-08-13 07:42:43 +01:00
}
2021-08-26 06:18:13 +01:00
components.right.active[6] = {
provider = function()
return " " .. mode_colors[vim.fn.mode()][1] .. " "
end,
hl = chad_mode_hl,
}
2021-08-26 06:18:13 +01:00
components.right.active[7] = {
provider = statusline_style.left,
hl = {
fg = colors.grey,
bg = colors.one_bg,
},
}
2021-08-26 06:18:13 +01:00
components.right.active[8] = {
provider = statusline_style.left,
hl = {
fg = colors.green,
bg = colors.grey,
2021-08-19 13:05:24 +01:00
},
}
2021-08-26 06:18:13 +01:00
components.right.active[9] = {
provider = statusline_style.position_icon,
hl = {
fg = colors.black,
bg = colors.green,
},
}
2021-08-26 06:18:13 +01:00
components.right.active[10] = {
provider = function()
local current_line = vim.fn.line "."
local total_line = vim.fn.line "$"
if current_line == 1 then
return " Top "
elseif current_line == vim.fn.line "$" then
return " Bot "
end
local result, _ = math.modf((current_line / total_line) * 100)
2021-08-28 05:09:38 +01:00
return " " .. result .. "%% "
2021-08-26 06:18:13 +01:00
end,
hl = {
fg = colors.green,
bg = colors.one_bg,
},
}
2021-08-26 06:18:13 +01:00
require("feline").setup {
default_bg = colors.statusline_bg,
default_fg = colors.fg,
components = components,
}