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_severity = vim.diagnostic.severity
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 = {
left_semicircle = "",
right_semicircle = "",
@ -26,11 +32,9 @@ local assets = {
slim_dot = "",
}
local clrs = require("catppuccin.palettes.init").get_palette()
-- settings
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,
extras = clrs.overlay1,
curr_file = clrs.maroon,
@ -60,38 +64,51 @@ local mode_colors = {
["!"] = { "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
return true
end
winid = winid or 0
return vim.api.nvim_win_get_width(winid) > min_width
end
-- Initialize the components table
local components = {
active = {},
inactive = {},
}
end
table.insert(components.active, {}) -- (1) left
table.insert(components.active, {}) -- (2) center
table.insert(components.active, {}) -- (3) right
table.insert(components.active, {}) -- (1) left
table.insert(components.active, {}) -- (2) center
table.insert(components.active, {}) -- (3) right
-- global components
local invi_sep = {
-- global components
local invi_sep = {
str = " ",
hl = {
fg = sett.bkg,
bg = sett.bkg,
},
}
}
-- helpers
local function any_git_changes()
-- helpers
local function any_git_changes()
local gst = b.gitsigns_status_dict -- git stats
if gst then
if
@ -103,22 +120,22 @@ local function any_git_changes()
end
end
return false
end
end
-- #################### STATUSLINE ->
-- #################### STATUSLINE ->
-- ######## Left
-- ######## Left
-- Current vi mode ------>
local vi_mode_hl = function()
-- Current vi mode ------>
local vi_mode_hl = function()
return {
fg = sett.bkg,
fg = sett.text,
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,
hl = function()
return {
@ -126,33 +143,33 @@ components.active[1][1] = {
bg = sett.bkg,
}
end,
}
}
components.active[1][2] = {
components.active[1][2] = {
provider = "",
hl = function()
return {
fg = sett.bkg,
fg = sett.text,
bg = mode_colors[vim.fn.mode()][2],
}
end,
}
}
components.active[1][3] = {
components.active[1][3] = {
provider = function()
return " " .. mode_colors[vim.fn.mode()][1] .. " "
end,
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
-- 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
-- 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 :)
-- 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
-- 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
-- the normal sett.bkg appears. Fixed :)
-- enable if git diffs are not available
components.active[1][4] = {
-- enable if git diffs are not available
components.active[1][4] = {
provider = assets.right_semicircle,
hl = function()
return {
@ -163,10 +180,10 @@ components.active[1][4] = {
enabled = function()
return not any_git_changes()
end,
}
}
-- enable if git diffs are available
components.active[1][5] = {
-- enable if git diffs are available
components.active[1][5] = {
provider = assets.right_semicircle,
hl = function()
return {
@ -177,38 +194,38 @@ components.active[1][5] = {
enabled = function()
return any_git_changes()
end,
}
-- Current vi mode ------>
}
-- Current vi mode ------>
-- Diffs ------>
components.active[1][6] = {
-- Diffs ------>
components.active[1][6] = {
provider = "git_diff_added",
hl = {
fg = sett.bkg,
fg = sett.text,
bg = sett.diffs,
},
icon = "",
}
}
components.active[1][7] = {
components.active[1][7] = {
provider = "git_diff_changed",
hl = {
fg = sett.bkg,
fg = sett.text,
bg = sett.diffs,
},
icon = "",
}
}
components.active[1][8] = {
components.active[1][8] = {
provider = "git_diff_removed",
hl = {
fg = sett.bkg,
fg = sett.text,
bg = sett.diffs,
},
icon = "",
}
}
components.active[1][9] = {
components.active[1][9] = {
provider = assets.right_semicircle,
hl = {
fg = sett.diffs,
@ -217,13 +234,13 @@ components.active[1][9] = {
enabled = function()
return any_git_changes()
end,
}
-- Diffs ------>
}
-- Diffs ------>
-- Extras ------>
-- Extras ------>
-- file progess
components.active[1][10] = {
-- file progess
components.active[1][10] = {
provider = function()
local current_line = vim.fn.line(".")
local total_line = vim.fn.line("$")
@ -244,10 +261,10 @@ components.active[1][10] = {
bg = sett.bkg,
},
left_sep = invi_sep,
}
}
-- position
components.active[1][11] = {
-- position
components.active[1][11] = {
provider = "position",
-- enabled = shortline or function(winid)
-- return vim.api.nvim_win_get_width(winid) > 90
@ -257,16 +274,16 @@ components.active[1][11] = {
bg = sett.bkg,
},
left_sep = invi_sep,
}
-- Extras ------>
}
-- Extras ------>
-- ######## Left
-- ######## Left
-- ######## Center
-- ######## Center
-- Diagnostics ------>
-- workspace loader
components.active[2][1] = {
-- Diagnostics ------>
-- workspace loader
components.active[2][1] = {
provider = function()
local Lsp = vim.lsp.util.get_progress_messages()[1]
@ -301,10 +318,10 @@ components.active[2][1] = {
fg = clrs.rosewater,
bg = sett.bkg,
},
}
}
-- genral diagnostics (errors, warnings. info and hints)
components.active[2][2] = {
-- genral diagnostics (errors, warnings. info and hints)
components.active[2][2] = {
provider = "diagnostic_errors",
enabled = function()
return lsp.diagnostics_exist(lsp_severity.ERROR)
@ -315,9 +332,9 @@ components.active[2][2] = {
bg = sett.bkg,
},
icon = "",
}
}
components.active[2][3] = {
components.active[2][3] = {
provider = "diagnostic_warnings",
enabled = function()
return lsp.diagnostics_exist(lsp_severity.WARN)
@ -327,9 +344,9 @@ components.active[2][3] = {
bg = sett.bkg,
},
icon = "",
}
}
components.active[2][4] = {
components.active[2][4] = {
provider = "diagnostic_info",
enabled = function()
return lsp.diagnostics_exist(lsp_severity.INFO)
@ -339,9 +356,9 @@ components.active[2][4] = {
bg = sett.bkg,
},
icon = "",
}
}
components.active[2][5] = {
components.active[2][5] = {
provider = "diagnostic_hints",
enabled = function()
return lsp.diagnostics_exist(lsp_severity.HINT)
@ -351,14 +368,14 @@ components.active[2][5] = {
bg = sett.bkg,
},
icon = "",
}
-- Diagnostics ------>
}
-- Diagnostics ------>
-- ######## Center
-- ######## Center
-- ######## Right
-- ######## Right
components.active[3][1] = {
components.active[3][1] = {
provider = "git_branch",
enabled = is_enabled(shortline, winid, 70),
hl = {
@ -368,9 +385,9 @@ components.active[3][1] = {
icon = "",
left_sep = invi_sep,
right_sep = invi_sep,
}
}
components.active[3][2] = {
components.active[3][2] = {
provider = function()
if next(vim.lsp.buf_get_clients()) ~= nil then
return ""
@ -383,9 +400,9 @@ components.active[3][2] = {
bg = sett.bkg,
},
right_sep = invi_sep,
}
}
components.active[3][3] = {
components.active[3][3] = {
provider = function()
local filename = vim.fn.expand("%:t")
local extension = vim.fn.expand("%:e")
@ -394,11 +411,11 @@ components.active[3][3] = {
icon = ""
return icon
end
return "%m" .. " " .. icon .. " " .. filename .. " "
return " " .. icon .. " " .. filename .. " "
end,
enabled = is_enabled(shortline, winid, 70),
hl = {
fg = sett.bkg,
fg = sett.text,
bg = sett.curr_file,
},
left_sep = {
@ -408,18 +425,16 @@ components.active[3][3] = {
bg = sett.bkg,
},
},
}
}
components.active[3][4] = {
components.active[3][4] = {
provider = function()
local dir_name = vim.fn.fnamemodify(vim.fn.getcwd(), ":t")
return "" .. dir_name .. " "
end,
enabled = is_enabled(shortline, winid, 80),
hl = {
fg = sett.bkg,
fg = sett.text,
bg = sett.curr_dir,
},
left_sep = {
@ -429,7 +444,10 @@ components.active[3][4] = {
bg = sett.curr_file,
},
},
}
-- ######## Right
}
-- ######## Right
return components
end
return components
return M

Loading…
Cancel
Save