fix: feline integration

dev
Pocco81 2 years ago
parent 1d1fda12f4
commit f76626386e

@ -1,7 +1,13 @@
local M = {}
local lsp = require("feline.providers.lsp") local lsp = require("feline.providers.lsp")
local lsp_severity = vim.diagnostic.severity local lsp_severity = vim.diagnostic.severity
local b = vim.b local b = vim.b
local clrs = require("catppuccin.palettes.init").get_palette()
local ucolors = require("catppuccin.utils.colors")
local latte = require("catppuccin.palettes.latte")
local assets = { local assets = {
left_semicircle = "", left_semicircle = "",
right_semicircle = "", right_semicircle = "",
@ -26,11 +32,9 @@ local assets = {
slim_dot = "", slim_dot = "",
} }
local clrs = require("catppuccin.palettes.init").get_palette()
-- settings
local sett = { local sett = {
bkg = clrs.surface0, text = ucolors.vary_color({ latte = latte.base }, clrs.surface0),
bkg = ucolors.vary_color({ latte = latte.crust }, clrs.surface0),
diffs = clrs.mauve, diffs = clrs.mauve,
extras = clrs.overlay1, extras = clrs.overlay1,
curr_file = clrs.maroon, curr_file = clrs.maroon,
@ -60,38 +64,51 @@ local mode_colors = {
["!"] = { "SHELL", clrs.green }, ["!"] = { "SHELL", clrs.green },
} }
local shortline = false function M.setup(opts)
if opts then
opts.assets = opts.assets or {}
opts.sett = opts.sett or {}
opts.mode_colors = opts.mode_colors or {}
else
opts = {}
end
assets = vim.tbl_deep_extend("force", assets, opts.assets)
sett = vim.tbl_deep_extend("force", sett, opts.sett)
mode_colors = vim.tbl_deep_extend("force", mode_colors, opts.mode_colors)
end
local function is_enabled(is_shortline, winid, min_width) function M.get()
local shortline = false
local components = {
active = {},
inactive = {},
}
local function is_enabled(is_shortline, winid, min_width)
if is_shortline then if is_shortline then
return true return true
end end
winid = winid or 0 winid = winid or 0
return vim.api.nvim_win_get_width(winid) > min_width return vim.api.nvim_win_get_width(winid) > min_width
end end
-- Initialize the components table
local components = {
active = {},
inactive = {},
}
table.insert(components.active, {}) -- (1) left table.insert(components.active, {}) -- (1) left
table.insert(components.active, {}) -- (2) center table.insert(components.active, {}) -- (2) center
table.insert(components.active, {}) -- (3) right table.insert(components.active, {}) -- (3) right
-- global components -- global components
local invi_sep = { local invi_sep = {
str = " ", str = " ",
hl = { hl = {
fg = sett.bkg, fg = sett.bkg,
bg = sett.bkg, bg = sett.bkg,
}, },
} }
-- helpers -- helpers
local function any_git_changes() local function any_git_changes()
local gst = b.gitsigns_status_dict -- git stats local gst = b.gitsigns_status_dict -- git stats
if gst then if gst then
if if
@ -103,22 +120,22 @@ local function any_git_changes()
end end
end end
return false return false
end end
-- #################### STATUSLINE -> -- #################### STATUSLINE ->
-- ######## Left -- ######## Left
-- Current vi mode ------> -- Current vi mode ------>
local vi_mode_hl = function() local vi_mode_hl = function()
return { return {
fg = sett.bkg, fg = sett.text,
bg = mode_colors[vim.fn.mode()][2], bg = mode_colors[vim.fn.mode()][2],
style = { "bold" }, style = "bold",
} }
end end
components.active[1][1] = { components.active[1][1] = {
provider = assets.vertical_bar_chubby, provider = assets.vertical_bar_chubby,
hl = function() hl = function()
return { return {
@ -126,33 +143,33 @@ components.active[1][1] = {
bg = sett.bkg, bg = sett.bkg,
} }
end, end,
} }
components.active[1][2] = { components.active[1][2] = {
provider = "", provider = "",
hl = function() hl = function()
return { return {
fg = sett.bkg, fg = sett.text,
bg = mode_colors[vim.fn.mode()][2], bg = mode_colors[vim.fn.mode()][2],
} }
end, end,
} }
components.active[1][3] = { components.active[1][3] = {
provider = function() provider = function()
return " " .. mode_colors[vim.fn.mode()][1] .. " " return " " .. mode_colors[vim.fn.mode()][1] .. " "
end, end,
hl = vi_mode_hl, hl = vi_mode_hl,
} }
-- there is a dilema: we need to hide Diffs if there is no git info. We can do that, but this will -- there is a dilema: we need to hide Diffs if ther is no git info. We can do that, but this will
-- leave the right_semicircle colored with purple, and since we can't change the color conditonally -- leave the right_semicircle colored with purple, and since we can't change the color conditonally
-- then the solution is to create two right_semicircles: one with a mauve sett.bkg and the other one normal -- then the solution is to create two right_semicircles: one with a mauve sett.bkg and the other one normal
-- sett.bkg; both have the same fg (vi mode). The mauve one appears if there is git info, else the one with -- sett.bkg; both have the same fg (vi mode). The mauve one appears if there is git info, else the one with
-- the normal sett.bkg appears. Fixed :) -- the normal sett.bkg appears. Fixed :)
-- enable if git diffs are not available -- enable if git diffs are not available
components.active[1][4] = { components.active[1][4] = {
provider = assets.right_semicircle, provider = assets.right_semicircle,
hl = function() hl = function()
return { return {
@ -163,10 +180,10 @@ components.active[1][4] = {
enabled = function() enabled = function()
return not any_git_changes() return not any_git_changes()
end, end,
} }
-- enable if git diffs are available -- enable if git diffs are available
components.active[1][5] = { components.active[1][5] = {
provider = assets.right_semicircle, provider = assets.right_semicircle,
hl = function() hl = function()
return { return {
@ -177,38 +194,38 @@ components.active[1][5] = {
enabled = function() enabled = function()
return any_git_changes() return any_git_changes()
end, end,
} }
-- Current vi mode ------> -- Current vi mode ------>
-- Diffs ------> -- Diffs ------>
components.active[1][6] = { components.active[1][6] = {
provider = "git_diff_added", provider = "git_diff_added",
hl = { hl = {
fg = sett.bkg, fg = sett.text,
bg = sett.diffs, bg = sett.diffs,
}, },
icon = "", icon = "",
} }
components.active[1][7] = { components.active[1][7] = {
provider = "git_diff_changed", provider = "git_diff_changed",
hl = { hl = {
fg = sett.bkg, fg = sett.text,
bg = sett.diffs, bg = sett.diffs,
}, },
icon = "", icon = "",
} }
components.active[1][8] = { components.active[1][8] = {
provider = "git_diff_removed", provider = "git_diff_removed",
hl = { hl = {
fg = sett.bkg, fg = sett.text,
bg = sett.diffs, bg = sett.diffs,
}, },
icon = "", icon = "",
} }
components.active[1][9] = { components.active[1][9] = {
provider = assets.right_semicircle, provider = assets.right_semicircle,
hl = { hl = {
fg = sett.diffs, fg = sett.diffs,
@ -217,13 +234,13 @@ components.active[1][9] = {
enabled = function() enabled = function()
return any_git_changes() return any_git_changes()
end, end,
} }
-- Diffs ------> -- Diffs ------>
-- Extras ------> -- Extras ------>
-- file progess -- file progess
components.active[1][10] = { components.active[1][10] = {
provider = function() provider = function()
local current_line = vim.fn.line(".") local current_line = vim.fn.line(".")
local total_line = vim.fn.line("$") local total_line = vim.fn.line("$")
@ -244,10 +261,10 @@ components.active[1][10] = {
bg = sett.bkg, bg = sett.bkg,
}, },
left_sep = invi_sep, left_sep = invi_sep,
} }
-- position -- position
components.active[1][11] = { components.active[1][11] = {
provider = "position", provider = "position",
-- enabled = shortline or function(winid) -- enabled = shortline or function(winid)
-- return vim.api.nvim_win_get_width(winid) > 90 -- return vim.api.nvim_win_get_width(winid) > 90
@ -257,16 +274,16 @@ components.active[1][11] = {
bg = sett.bkg, bg = sett.bkg,
}, },
left_sep = invi_sep, left_sep = invi_sep,
} }
-- Extras ------> -- Extras ------>
-- ######## Left -- ######## Left
-- ######## Center -- ######## Center
-- Diagnostics ------> -- Diagnostics ------>
-- workspace loader -- workspace loader
components.active[2][1] = { components.active[2][1] = {
provider = function() provider = function()
local Lsp = vim.lsp.util.get_progress_messages()[1] local Lsp = vim.lsp.util.get_progress_messages()[1]
@ -301,10 +318,10 @@ components.active[2][1] = {
fg = clrs.rosewater, fg = clrs.rosewater,
bg = sett.bkg, bg = sett.bkg,
}, },
} }
-- genral diagnostics (errors, warnings. info and hints) -- genral diagnostics (errors, warnings. info and hints)
components.active[2][2] = { components.active[2][2] = {
provider = "diagnostic_errors", provider = "diagnostic_errors",
enabled = function() enabled = function()
return lsp.diagnostics_exist(lsp_severity.ERROR) return lsp.diagnostics_exist(lsp_severity.ERROR)
@ -315,9 +332,9 @@ components.active[2][2] = {
bg = sett.bkg, bg = sett.bkg,
}, },
icon = "", icon = "",
} }
components.active[2][3] = { components.active[2][3] = {
provider = "diagnostic_warnings", provider = "diagnostic_warnings",
enabled = function() enabled = function()
return lsp.diagnostics_exist(lsp_severity.WARN) return lsp.diagnostics_exist(lsp_severity.WARN)
@ -327,9 +344,9 @@ components.active[2][3] = {
bg = sett.bkg, bg = sett.bkg,
}, },
icon = "", icon = "",
} }
components.active[2][4] = { components.active[2][4] = {
provider = "diagnostic_info", provider = "diagnostic_info",
enabled = function() enabled = function()
return lsp.diagnostics_exist(lsp_severity.INFO) return lsp.diagnostics_exist(lsp_severity.INFO)
@ -339,9 +356,9 @@ components.active[2][4] = {
bg = sett.bkg, bg = sett.bkg,
}, },
icon = "", icon = "",
} }
components.active[2][5] = { components.active[2][5] = {
provider = "diagnostic_hints", provider = "diagnostic_hints",
enabled = function() enabled = function()
return lsp.diagnostics_exist(lsp_severity.HINT) return lsp.diagnostics_exist(lsp_severity.HINT)
@ -351,14 +368,14 @@ components.active[2][5] = {
bg = sett.bkg, bg = sett.bkg,
}, },
icon = "", icon = "",
} }
-- Diagnostics ------> -- Diagnostics ------>
-- ######## Center -- ######## Center
-- ######## Right -- ######## Right
components.active[3][1] = { components.active[3][1] = {
provider = "git_branch", provider = "git_branch",
enabled = is_enabled(shortline, winid, 70), enabled = is_enabled(shortline, winid, 70),
hl = { hl = {
@ -368,9 +385,9 @@ components.active[3][1] = {
icon = "", icon = "",
left_sep = invi_sep, left_sep = invi_sep,
right_sep = invi_sep, right_sep = invi_sep,
} }
components.active[3][2] = { components.active[3][2] = {
provider = function() provider = function()
if next(vim.lsp.buf_get_clients()) ~= nil then if next(vim.lsp.buf_get_clients()) ~= nil then
return "" return ""
@ -383,9 +400,9 @@ components.active[3][2] = {
bg = sett.bkg, bg = sett.bkg,
}, },
right_sep = invi_sep, right_sep = invi_sep,
} }
components.active[3][3] = { components.active[3][3] = {
provider = function() provider = function()
local filename = vim.fn.expand("%:t") local filename = vim.fn.expand("%:t")
local extension = vim.fn.expand("%:e") local extension = vim.fn.expand("%:e")
@ -394,11 +411,11 @@ components.active[3][3] = {
icon = "" icon = ""
return icon return icon
end end
return "%m" .. " " .. icon .. " " .. filename .. " " return " " .. icon .. " " .. filename .. " "
end, end,
enabled = is_enabled(shortline, winid, 70), enabled = is_enabled(shortline, winid, 70),
hl = { hl = {
fg = sett.bkg, fg = sett.text,
bg = sett.curr_file, bg = sett.curr_file,
}, },
left_sep = { left_sep = {
@ -408,18 +425,16 @@ components.active[3][3] = {
bg = sett.bkg, bg = sett.bkg,
}, },
}, },
} }
components.active[3][4] = { components.active[3][4] = {
provider = function() provider = function()
local dir_name = vim.fn.fnamemodify(vim.fn.getcwd(), ":t") local dir_name = vim.fn.fnamemodify(vim.fn.getcwd(), ":t")
return "" .. dir_name .. " " return "" .. dir_name .. " "
end, end,
enabled = is_enabled(shortline, winid, 80), enabled = is_enabled(shortline, winid, 80),
hl = { hl = {
fg = sett.bkg, fg = sett.text,
bg = sett.curr_dir, bg = sett.curr_dir,
}, },
left_sep = { left_sep = {
@ -429,7 +444,10 @@ components.active[3][4] = {
bg = sett.curr_file, bg = sett.curr_file,
}, },
}, },
} }
-- ######## Right -- ######## Right
return components
end
return components return M

Loading…
Cancel
Save