summaryrefslogtreecommitdiff
path: root/lua/lvim/core/builtins/lualine/components.lua
diff options
context:
space:
mode:
Diffstat (limited to 'lua/lvim/core/builtins/lualine/components.lua')
-rw-r--r--lua/lvim/core/builtins/lualine/components.lua179
1 files changed, 179 insertions, 0 deletions
diff --git a/lua/lvim/core/builtins/lualine/components.lua b/lua/lvim/core/builtins/lualine/components.lua
new file mode 100644
index 00000000..755c42af
--- /dev/null
+++ b/lua/lvim/core/builtins/lualine/components.lua
@@ -0,0 +1,179 @@
+local conditions = require "lvim.core.builtins.lualine.conditions"
+local colors = require "lvim.core.builtins.lualine.colors"
+
+local function diff_source()
+ local gitsigns = vim.b.gitsigns_status_dict
+ if gitsigns then
+ return {
+ added = gitsigns.added,
+ modified = gitsigns.changed,
+ removed = gitsigns.removed,
+ }
+ end
+end
+
+local branch = lvim.icons.git.Branch
+
+if lvim.colorscheme == "lunar" then
+ branch = "%#SLGitIcon#" .. lvim.icons.git.Branch .. "%*" .. "%#SLBranchName#"
+end
+
+return {
+ mode = {
+ function()
+ return " " .. lvim.icons.ui.Target .. " "
+ end,
+ padding = { left = 0, right = 0 },
+ color = {},
+ cond = nil,
+ },
+ branch = {
+ "b:gitsigns_head",
+ icon = branch,
+ color = { gui = "bold" },
+ },
+ filename = {
+ "filename",
+ color = {},
+ cond = nil,
+ },
+ diff = {
+ "diff",
+ source = diff_source,
+ symbols = {
+ added = lvim.icons.git.LineAdded .. " ",
+ modified = lvim.icons.git.LineModified .. " ",
+ removed = lvim.icons.git.LineRemoved .. " ",
+ },
+ padding = { left = 2, right = 1 },
+ diff_color = {
+ added = { fg = colors.green },
+ modified = { fg = colors.yellow },
+ removed = { fg = colors.red },
+ },
+ cond = nil,
+ },
+ python_env = {
+ function()
+ local utils = require "lvim.core.builtins.lualine.utils"
+ if vim.bo.filetype == "python" then
+ local venv = os.getenv "CONDA_DEFAULT_ENV" or os.getenv "VIRTUAL_ENV"
+ if venv then
+ local icons = require "nvim-web-devicons"
+ local py_icon, _ = icons.get_icon ".py"
+ return string.format(" " .. py_icon .. " (%s)", utils.env_cleanup(venv))
+ end
+ end
+ return ""
+ end,
+ color = { fg = colors.green },
+ cond = conditions.hide_in_width,
+ },
+ diagnostics = {
+ "diagnostics",
+ sources = { "nvim_diagnostic" },
+ symbols = {
+ error = lvim.icons.diagnostics.BoldError .. " ",
+ warn = lvim.icons.diagnostics.BoldWarning .. " ",
+ info = lvim.icons.diagnostics.BoldInformation .. " ",
+ hint = lvim.icons.diagnostics.BoldHint .. " ",
+ },
+ -- cond = conditions.hide_in_width,
+ },
+ treesitter = {
+ function()
+ return lvim.icons.ui.Tree
+ end,
+ color = function()
+ local buf = vim.api.nvim_get_current_buf()
+ local ts = vim.treesitter.highlighter.active[buf]
+ return { fg = ts and not vim.tbl_isempty(ts) and colors.green or colors.red }
+ end,
+ cond = conditions.hide_in_width,
+ },
+ lsp = {
+ function(msg)
+ msg = msg or "LS Inactive"
+ local buf_clients = vim.lsp.buf_get_clients()
+ if next(buf_clients) == nil then
+ -- TODO: clean up this if statement
+ if type(msg) == "boolean" or #msg == 0 then
+ return "LS Inactive"
+ end
+ return msg
+ end
+ local buf_ft = vim.bo.filetype
+ local buf_client_names = {}
+ local copilot_active = false
+
+ -- add client
+ for _, client in pairs(buf_clients) do
+ if client.name ~= "null-ls" and client.name ~= "copilot" then
+ table.insert(buf_client_names, client.name)
+ end
+
+ if client.name == "copilot" then
+ copilot_active = true
+ end
+ end
+
+ -- add formatter
+ local formatters = require "lvim.lsp.null-ls.formatters"
+ local supported_formatters = formatters.list_registered(buf_ft)
+ vim.list_extend(buf_client_names, supported_formatters)
+
+ -- add linter
+ local linters = require "lvim.lsp.null-ls.linters"
+ local supported_linters = linters.list_registered(buf_ft)
+ vim.list_extend(buf_client_names, supported_linters)
+
+ local unique_client_names = vim.fn.uniq(buf_client_names)
+
+ local language_servers = "[" .. table.concat(unique_client_names, ", ") .. "]"
+
+ if copilot_active then
+ language_servers = language_servers .. "%#SLCopilot#" .. " " .. lvim.icons.git.Octoface .. "%*"
+ end
+
+ return language_servers
+ end,
+ color = { gui = "bold" },
+ cond = conditions.hide_in_width,
+ },
+ location = { "location" },
+ progress = {
+ "progress",
+ fmt = function()
+ return "%P/%L"
+ end,
+ color = {},
+ },
+
+ spaces = {
+ function()
+ local shiftwidth = vim.api.nvim_buf_get_option(0, "shiftwidth")
+ return lvim.icons.ui.Tab .. " " .. shiftwidth
+ end,
+ padding = 1,
+ },
+ encoding = {
+ "o:encoding",
+ fmt = string.upper,
+ color = {},
+ cond = conditions.hide_in_width,
+ },
+ filetype = { "filetype", cond = nil, padding = { left = 1, right = 1 } },
+ scrollbar = {
+ function()
+ local current_line = vim.fn.line "."
+ local total_lines = vim.fn.line "$"
+ local chars = { "__", "▁▁", "▂▂", "▃▃", "▄▄", "▅▅", "▆▆", "▇▇", "██" }
+ local line_ratio = current_line / total_lines
+ local index = math.ceil(line_ratio * #chars)
+ return chars[index]
+ end,
+ padding = { left = 0, right = 0 },
+ color = "SLProgress",
+ cond = nil,
+ },
+}