feat!: Move from lualine to feline

Signed-off-by: Micah Halter <micah@balena.io>
This commit is contained in:
Micah Halter
2022-05-14 08:00:17 -04:00
committed by Micah Halter
parent 58159bf47f
commit b144855003
7 changed files with 156 additions and 204 deletions
+1 -1
View File
@@ -43,7 +43,7 @@ git -C ~/.config/nvim remote set-url origin https://github.com/AstroNvim/AstroNv
- File explorer with [Neo-tree](https://github.com/nvim-neo-tree/neo-tree.nvim)
- Autocompletion with [Cmp](https://github.com/hrsh7th/nvim-cmp)
- Git integration with [Gitsigns](https://github.com/lewis6991/gitsigns.nvim)
- Statusline with [Lualine](https://github.com/nvim-lualine/lualine.nvim)
- Statusline with [Feline](https://github.com/feline-nvim/feline.nvim)
- Terminal with [Toggleterm](https://github.com/akinsho/toggleterm.nvim)
- Fuzzy finding with [Telescope](https://github.com/nvim-telescope/telescope.nvim)
- Syntax highlighting with [Treesitter](https://github.com/nvim-treesitter/nvim-treesitter)
+52
View File
@@ -0,0 +1,52 @@
local M = {}
function M.config()
local present, feline = pcall(require, "feline")
if present then
local C = require "default_theme.colors"
local hl = require("core.status").hl
local provider = require("core.status").provider
local conditional = require("core.status").conditional
-- stylua: ignore
feline.setup(require("core.utils").user_plugin_opts("plugins.feline", {
disable = { filetypes = { "^NvimTree$", "^neo%-tree$", "^dashboard$", "^Outline$", "^aerial$" } },
theme = hl.group("StatusLine", { fg = C.fg, bg = C.bg_1 }),
components = {
active = {
{
{ provider = provider.spacer(), hl = hl.mode() },
{ provider = provider.spacer(2) },
{ provider = "git_branch", hl = hl.fg("Conditional", { fg = C.purple_1, style = "bold" }), icon = "" },
{ provider = provider.spacer(3), enabled = conditional.git_available },
{ provider = { name = "file_type", opts = { filetype_icon = true, case = "lowercase" } }, enabled = conditional.has_filetype },
{ provider = provider.spacer(2), enabled = conditional.has_filetype },
{ provider = "git_diff_added", hl = hl.fg("GitSignsAdd", { fg = C.green }), icon = "" },
{ provider = "git_diff_changed", hl = hl.fg("GitSignsChange", { fg = C.orange_1 }), icon = "" },
{ provider = "git_diff_removed", hl = hl.fg("GitSignsDelete", { fg = C.red_1 }), icon = "" },
{ provider = provider.spacer(2), enabled = conditional.git_changed },
{ provider = "diagnostic_errors", hl = hl.fg("DiagnosticError", { fg = C.red_1 }), icon = "" },
{ provider = "diagnostic_warnings", hl = hl.fg("DiagnosticWarn", { fg = C.orange_1 }), icon = "" },
{ provider = "diagnostic_info", hl = hl.fg("DiagnosticInfo", { fg = C.white_2 }), icon = "" },
{ provider = "diagnostic_hints", hl = hl.fg("DiagnosticHint", { fg = C.yellow_1 }), icon = "" },
},
{
{ provider = provider.lsp_progress, enabled = conditional.bar_width() },
{ provider = "lsp_client_names", enabled = conditional.bar_width(), icon = "" },
{ provider = provider.spacer(2), enabled = conditional.bar_width() },
{ provider = provider.treesitter_status, enabled = conditional.bar_width(), hl = hl.fg("GitSignsAdd", { fg = C.green }) },
{ provider = provider.spacer(2) },
{ provider = "position" },
{ provider = provider.spacer(2) },
{ provider = "line_percentage" },
{ provider = provider.spacer() },
{ provider = "scroll_bar", hl = hl.fg("TypeDef", { fg = C.yellow }) },
{ provider = provider.spacer(2) },
{ provider = provider.spacer(), hl = hl.mode() },
},
},
},
}))
end
end
return M
-134
View File
@@ -1,134 +0,0 @@
local M = {}
local status = require "core.status"
local function get_hl_by_name(name)
return string.format("#%06x", vim.api.nvim_get_hl_by_name(name.group, true)[name.prop])
end
local function get_hl_prop(group, prop, default)
local status_ok, color = pcall(get_hl_by_name, { group = group, prop = prop })
if status_ok then
default = color
end
return default
end
function M.config()
local status_ok, lualine = pcall(require, "lualine")
if status_ok then
local colors = require "default_theme.colors"
local conditions = {
buffer_not_empty = function()
return vim.fn.empty(vim.fn.expand "%:t") ~= 1
end,
hide_in_width = function()
return vim.fn.winwidth(0) > 80
end,
check_git_workspace = function()
local filepath = vim.fn.expand "%:p:h"
local gitdir = vim.fn.finddir(".git", filepath .. ";")
return gitdir and #gitdir > 0 and #gitdir < #filepath
end,
}
local spacer = {
function()
return " "
end,
padding = { left = 0, right = 0 },
}
lualine.setup(require("core.utils").user_plugin_opts("plugins.lualine", {
options = {
disabled_filetypes = { "NvimTree", "neo-tree", "dashboard", "Outline" },
component_separators = "",
section_separators = "",
globalstatus = true,
},
sections = {
lualine_a = { spacer },
lualine_b = {},
lualine_c = {
{
"branch",
icon = "",
color = { fg = get_hl_prop("Conditional", "foreground", colors.purple_1), gui = "bold" },
padding = { left = 2, right = 1 },
},
{
"filetype",
cond = conditions.buffer_not_empty,
padding = { left = 2, right = 1 },
},
{
"diff",
symbols = { added = "", modified = "", removed = "" },
cond = conditions.hide_in_width,
padding = { left = 2, right = 1 },
},
{
"diagnostics",
sources = { "nvim_diagnostic" },
symbols = { error = "", warn = "", info = "", hint = "" },
padding = { left = 2, right = 1 },
},
{
function()
return "%="
end,
},
},
lualine_x = {
{
status.lsp_progress,
color = { gui = "none" },
padding = { left = 0, right = 1 },
cond = conditions.hide_in_width,
},
{
status.lsp_name,
icon = "",
color = { gui = "none" },
padding = { left = 0, right = 1 },
cond = conditions.hide_in_width,
},
{
status.treesitter_status,
color = { fg = get_hl_prop("GitSignsAdd", "foreground", colors.green) },
padding = { left = 1, right = 0 },
cond = conditions.hide_in_width,
},
{
"location",
padding = { left = 1, right = 1 },
},
{
"progress",
color = { gui = "none" },
padding = { left = 0, right = 0 },
},
{
status.progress_bar,
padding = { left = 1, right = 2 },
color = { fg = get_hl_prop("TypeDef", "foreground", colors.yellow) },
cond = nil,
},
},
lualine_y = {},
lualine_z = { spacer },
},
inactive_sections = {
lualine_a = {},
lualine_b = {},
lualine_y = {},
lualine_z = {},
lualine_c = {},
lualine_x = {},
},
}))
end
end
return M
+9
View File
@@ -72,6 +72,15 @@ if utils.is_available "alpha-nvim" then
})
end
if utils.is_available "feline.nvim" then
augroup("feline_setup", { clear = true })
cmd("ColorScheme", {
desc = "Reload feline on colorscheme change",
group = "feline_setup",
callback = require("configs.feline").config,
})
end
create_command("AstroUpdate", require("core.utils").update, { desc = "Update AstroNvim" })
create_command("ToggleHighlightURL", require("core.utils").toggle_url_match, { desc = "Toggle URL Highlights" })
+1
View File
@@ -18,6 +18,7 @@ utils.vim_opts(utils.user_plugin_opts("options", {
fillchars = { eob = " " }, -- Disable `~` on nonexistent lines
history = 100, -- Number of commands to remember in a history table
ignorecase = true, -- Case insensitive searching
laststatus = 3, -- globalstatus
mouse = "a", -- Enable mouse support
number = true, -- Show numberline
preserveindent = true, -- Preserve indent structure as much as possible
+4 -7
View File
@@ -2,9 +2,7 @@ local packer_status_ok, packer = pcall(require, "packer")
if packer_status_ok then
local astro_plugins = {
-- Plugin manager
{
"wbthomason/packer.nvim",
},
{ "wbthomason/packer.nvim" },
-- Optimiser
{ "lewis6991/impatient.nvim" },
@@ -40,7 +38,7 @@ if packer_status_ok then
{
"antoinemadec/FixCursorHold.nvim",
event = { "BufRead", "BufNewFile" },
config = function()
setup = function()
vim.g.cursorhold_updatetime = 100
end,
},
@@ -89,9 +87,9 @@ if packer_status_ok then
-- Statusline
{
"nvim-lualine/lualine.nvim",
"feline-nvim/feline.nvim",
config = function()
require("configs.lualine").config()
require("configs.feline").config()
end,
},
@@ -353,7 +351,6 @@ if packer_status_ok then
packer.startup {
function(use)
-- Load plugins!
for _, plugin in
pairs(
require("core.utils").user_plugin_opts("plugins.init", require("core.utils").label_plugins(astro_plugins))
+89 -62
View File
@@ -1,73 +1,100 @@
local M = {}
local M = { hl = {}, provider = {}, conditional = {} }
local C = require "default_theme.colors"
function M.lsp_progress(_)
local function hl_by_name(name)
return string.format("#%06x", vim.api.nvim_get_hl_by_name(name.group, true)[name.prop])
end
local function hl_prop(group, prop)
local status_ok, color = pcall(hl_by_name, { group = group, prop = prop })
return status_ok and color or nil
end
M.modes = { -- mode text, hlgroup suffix, default color
["n"] = { "NORMAL", "Normal", C.blue },
["no"] = { "N-PENDING", "Normal", C.blue },
["i"] = { "INSERT", "Insert", C.green },
["ic"] = { "INSERT", "Insert", C.green },
["t"] = { "TERMINAL", "Insert", C.green },
["v"] = { "VISUAL", "Visual", C.purple },
["V"] = { "V-LINE", "Visual", C.purple },
[""] = { "V-BLOCK", "Visual", C.purple },
["R"] = { "REPLACE", "Replace", C.red_1 },
["Rv"] = { "V-REPLACE", "Replace", C.red_1 },
["s"] = { "SELECT", "Select", C.orange_1 },
["S"] = { "S-LINE", "Select", C.orange_1 },
[""] = { "S-BLOCK", "Select", C.orange_1 },
["c"] = { "COMMAND", "Command", C.yellow_1 },
["cv"] = { "COMMAND", "Command", C.yellow_1 },
["ce"] = { "COMMAND", "Command", C.yellow_1 },
["r"] = { "PROMPT", "Other", C.grey_7 },
["rm"] = { "MORE", "Other", C.grey_7 },
["r?"] = { "CONFIRM", "Other", C.grey_7 },
["!"] = { "SHELL", "Other", C.grey_7 },
}
function M.hl.group(hlgroup, base)
return vim.tbl_deep_extend(
"force",
base or {},
{ fg = hl_prop(hlgroup, "foreground"), bg = hl_prop(hlgroup, "background") }
)
end
function M.hl.fg(hlgroup, base)
return vim.tbl_deep_extend("force", base or {}, { fg = hl_prop(hlgroup, "foreground") })
end
function M.hl.mode(base)
return function()
return M.hl.group(
"Feline" .. M.modes[vim.fn.mode()][2],
vim.tbl_deep_extend("force", { fg = C.bg_1, bg = M.modes[vim.fn.mode()][3] }, base or {})
)
end
end
function M.provider.lsp_progress()
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 = { "", "", "" }
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)
end
return string.format(" %%<%s %s %s (%s%%%%) ", spinners[frame + 1], title, msg, percentage)
end
return ""
return Lsp
and string.format(
" %%<%s %s %s (%s%%%%) ",
((Lsp.percentage or 0) >= 70 and { "", "", "" } or { "", "", "" })[math.floor(
vim.loop.hrtime() / 12e7
) % 3 + 1],
Lsp.title or "",
Lsp.message or "",
Lsp.percentage or 0
)
or ""
end
function M.lsp_name(msg)
msg = msg or "Inactive"
local buf_clients = vim.lsp.buf_get_clients()
if next(buf_clients) == nil then
if type(msg) == "boolean" or #msg == 0 then
return "Inactive"
end
return msg
end
local buf_ft = vim.bo.filetype
local buf_client_names = {}
for _, client in pairs(buf_clients) do
if client.name ~= "null-ls" then
table.insert(buf_client_names, client.name)
end
end
local formatters = require "core.utils"
local supported_formatters = formatters.list_registered_formatters(buf_ft)
vim.list_extend(buf_client_names, supported_formatters)
local linters = require "core.utils"
local supported_linters = linters.list_registered_linters(buf_ft)
vim.list_extend(buf_client_names, supported_linters)
return table.concat(buf_client_names, ", ")
function M.provider.treesitter_status()
local ts = vim.treesitter.highlighter.active[vim.api.nvim_get_current_buf()]
return (ts and next(ts)) and " 綠TS" or ""
end
function M.treesitter_status()
local b = vim.api.nvim_get_current_buf()
if next(vim.treesitter.highlighter.active[b]) then
return " 綠TS"
end
return ""
function M.provider.spacer(n)
return string.rep(" ", n or 1)
end
function M.progress_bar()
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]
function M.conditional.git_available()
return vim.b.gitsigns_head ~= nil
end
function M.conditional.git_changed()
local git_status = vim.b.gitsigns_status_dict
return git_status and (git_status.added or 0) + (git_status.removed or 0) + (git_status.changed or 0) > 0
end
function M.conditional.has_filetype()
return vim.fn.empty(vim.fn.expand "%:t") ~= 1 and vim.bo.filetype and vim.bo.filetype ~= ""
end
function M.conditional.bar_width(n)
return function()
return (vim.opt.laststatus:get() == 3 and vim.opt.columns:get() or vim.fn.winwidth(0)) > (n or 80)
end
end
return M