2021-10-10 21:07:41 +02:00
|
|
|
local conditions = require "lvim.core.lualine.conditions"
|
|
|
|
local colors = require "lvim.core.lualine.colors"
|
2021-08-20 11:16:29 +02:00
|
|
|
|
2021-08-26 09:20:04 +02:00
|
|
|
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
|
|
|
|
|
2021-08-20 11:16:29 +02:00
|
|
|
return {
|
2021-08-24 08:49:18 +02:00
|
|
|
mode = {
|
2021-08-20 11:16:29 +02:00
|
|
|
function()
|
|
|
|
return " "
|
|
|
|
end,
|
2021-09-15 21:11:21 +02:00
|
|
|
padding = { left = 0, right = 0 },
|
2021-08-24 08:49:18 +02:00
|
|
|
color = {},
|
2021-09-15 21:11:21 +02:00
|
|
|
cond = nil,
|
2021-08-20 11:16:29 +02:00
|
|
|
},
|
|
|
|
branch = {
|
2021-08-26 09:20:04 +02:00
|
|
|
"b:gitsigns_head",
|
2021-08-20 11:16:29 +02:00
|
|
|
icon = " ",
|
2021-08-24 08:49:18 +02:00
|
|
|
color = { gui = "bold" },
|
2021-09-15 21:11:21 +02:00
|
|
|
cond = conditions.hide_in_width,
|
2021-08-24 08:49:18 +02:00
|
|
|
},
|
|
|
|
filename = {
|
|
|
|
"filename",
|
|
|
|
color = {},
|
2021-09-15 21:11:21 +02:00
|
|
|
cond = nil,
|
2021-08-20 11:16:29 +02:00
|
|
|
},
|
|
|
|
diff = {
|
|
|
|
"diff",
|
2021-08-26 09:20:04 +02:00
|
|
|
source = diff_source,
|
2022-02-04 16:55:11 +01:00
|
|
|
symbols = { added = " ", modified = " ", removed = " " },
|
2021-09-15 21:11:21 +02:00
|
|
|
diff_color = {
|
|
|
|
added = { fg = colors.green },
|
|
|
|
modified = { fg = colors.yellow },
|
|
|
|
removed = { fg = colors.red },
|
|
|
|
},
|
|
|
|
cond = nil,
|
2021-08-20 11:16:29 +02:00
|
|
|
},
|
|
|
|
python_env = {
|
|
|
|
function()
|
2021-10-10 21:07:41 +02:00
|
|
|
local utils = require "lvim.core.lualine.utils"
|
2021-08-20 11:16:29 +02:00
|
|
|
if vim.bo.filetype == "python" then
|
|
|
|
local venv = os.getenv "CONDA_DEFAULT_ENV"
|
|
|
|
if venv then
|
|
|
|
return string.format(" (%s)", utils.env_cleanup(venv))
|
|
|
|
end
|
|
|
|
venv = os.getenv "VIRTUAL_ENV"
|
|
|
|
if venv then
|
|
|
|
return string.format(" (%s)", utils.env_cleanup(venv))
|
|
|
|
end
|
|
|
|
return ""
|
|
|
|
end
|
|
|
|
return ""
|
|
|
|
end,
|
2021-08-24 08:49:18 +02:00
|
|
|
color = { fg = colors.green },
|
2021-09-15 21:11:21 +02:00
|
|
|
cond = conditions.hide_in_width,
|
2021-08-20 11:16:29 +02:00
|
|
|
},
|
|
|
|
diagnostics = {
|
|
|
|
"diagnostics",
|
2021-12-11 09:46:36 +01:00
|
|
|
sources = { "nvim_diagnostic" },
|
2021-08-20 11:16:29 +02:00
|
|
|
symbols = { error = " ", warn = " ", info = " ", hint = " " },
|
2021-09-15 21:11:21 +02:00
|
|
|
cond = conditions.hide_in_width,
|
2021-08-20 11:16:29 +02:00
|
|
|
},
|
|
|
|
treesitter = {
|
|
|
|
function()
|
2022-08-09 13:32:35 +02:00
|
|
|
return ""
|
|
|
|
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 }
|
2021-08-20 11:16:29 +02:00
|
|
|
end,
|
2021-09-15 21:11:21 +02:00
|
|
|
cond = conditions.hide_in_width,
|
2021-08-20 11:16:29 +02:00
|
|
|
},
|
|
|
|
lsp = {
|
|
|
|
function(msg)
|
2021-09-05 16:03:58 +02:00
|
|
|
msg = msg or "LS Inactive"
|
2021-08-20 11:16:29 +02:00
|
|
|
local buf_clients = vim.lsp.buf_get_clients()
|
|
|
|
if next(buf_clients) == nil then
|
2021-09-06 20:23:41 +02:00
|
|
|
-- TODO: clean up this if statement
|
|
|
|
if type(msg) == "boolean" or #msg == 0 then
|
2021-09-05 16:03:58 +02:00
|
|
|
return "LS Inactive"
|
|
|
|
end
|
2021-08-20 11:16:29 +02:00
|
|
|
return msg
|
|
|
|
end
|
|
|
|
local buf_ft = vim.bo.filetype
|
|
|
|
local buf_client_names = {}
|
|
|
|
|
|
|
|
-- add client
|
|
|
|
for _, client in pairs(buf_clients) do
|
|
|
|
if client.name ~= "null-ls" then
|
|
|
|
table.insert(buf_client_names, client.name)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
-- add formatter
|
2021-10-10 21:07:41 +02:00
|
|
|
local formatters = require "lvim.lsp.null-ls.formatters"
|
2022-01-01 14:25:23 +01:00
|
|
|
local supported_formatters = formatters.list_registered(buf_ft)
|
2021-08-20 11:16:29 +02:00
|
|
|
vim.list_extend(buf_client_names, supported_formatters)
|
|
|
|
|
|
|
|
-- add linter
|
2021-10-10 21:07:41 +02:00
|
|
|
local linters = require "lvim.lsp.null-ls.linters"
|
2022-01-01 14:25:23 +01:00
|
|
|
local supported_linters = linters.list_registered(buf_ft)
|
2021-08-20 11:16:29 +02:00
|
|
|
vim.list_extend(buf_client_names, supported_linters)
|
|
|
|
|
2022-06-23 08:02:15 +02:00
|
|
|
local unique_client_names = vim.fn.uniq(buf_client_names)
|
|
|
|
return "[" .. table.concat(unique_client_names, ", ") .. "]"
|
2021-08-20 11:16:29 +02:00
|
|
|
end,
|
|
|
|
color = { gui = "bold" },
|
2021-09-15 21:11:21 +02:00
|
|
|
cond = conditions.hide_in_width,
|
2021-08-20 11:16:29 +02:00
|
|
|
},
|
2021-09-15 21:11:21 +02:00
|
|
|
location = { "location", cond = conditions.hide_in_width, color = {} },
|
|
|
|
progress = { "progress", cond = conditions.hide_in_width, color = {} },
|
2021-08-20 11:16:29 +02:00
|
|
|
spaces = {
|
|
|
|
function()
|
|
|
|
if not vim.api.nvim_buf_get_option(0, "expandtab") then
|
2021-10-22 13:03:48 +02:00
|
|
|
return "Tab size: " .. vim.api.nvim_buf_get_option(0, "tabstop") .. " "
|
2021-08-20 11:16:29 +02:00
|
|
|
end
|
2021-10-22 13:03:48 +02:00
|
|
|
local size = vim.api.nvim_buf_get_option(0, "shiftwidth")
|
|
|
|
if size == 0 then
|
|
|
|
size = vim.api.nvim_buf_get_option(0, "tabstop")
|
|
|
|
end
|
|
|
|
return "Spaces: " .. size .. " "
|
2021-08-20 11:16:29 +02:00
|
|
|
end,
|
2021-09-15 21:11:21 +02:00
|
|
|
cond = conditions.hide_in_width,
|
2021-08-24 08:49:18 +02:00
|
|
|
color = {},
|
2021-08-20 11:16:29 +02:00
|
|
|
},
|
|
|
|
encoding = {
|
|
|
|
"o:encoding",
|
2021-09-15 21:11:21 +02:00
|
|
|
fmt = string.upper,
|
2021-08-24 08:49:18 +02:00
|
|
|
color = {},
|
2021-09-15 21:11:21 +02:00
|
|
|
cond = conditions.hide_in_width,
|
2021-08-20 11:16:29 +02:00
|
|
|
},
|
2022-04-15 03:10:03 +02:00
|
|
|
filetype = { "filetype", cond = conditions.hide_in_width },
|
2021-08-20 11:16:29 +02:00
|
|
|
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,
|
2021-09-15 21:11:21 +02:00
|
|
|
padding = { left = 0, right = 0 },
|
2021-08-24 08:49:18 +02:00
|
|
|
color = { fg = colors.yellow, bg = colors.bg },
|
2021-09-15 21:11:21 +02:00
|
|
|
cond = nil,
|
2021-08-20 11:16:29 +02:00
|
|
|
},
|
|
|
|
}
|