nvim: Extract statusline plugin into separate file

Extract lualine into its own 'statusline.lua' plugin file. This makes
the ui plugin file a little more lean but also prepares the way of
tinkering with statusline alternatives, like heirline.
This commit is contained in:
Marty Oehme 2024-09-15 22:11:20 +02:00
parent 03f18bea3a
commit f15a64c121
Signed by: Marty
GPG key ID: EDBF2ED917B2EF6A
2 changed files with 90 additions and 87 deletions

View file

@ -0,0 +1,90 @@
return {
-- statusline
{
"nvim-lualine/lualine.nvim",
cond = true,
dependencies = { { "nvim-tree/nvim-web-devicons", config = true } },
config = function()
local has_pynvim = -1
-- if molten exists, is initialized and connected to a kernel
-- show it in the statusline
local function molten()
-- we don't have access to python, disregard element
if has_pynvim == 0 then
return ""
elseif has_pynvim == 1 then
local status_ok, res = pcall(function()
return require("molten.status").kernels() ~= ""
end)
if status_ok and res then
return "󱪄"
end
return ""
-- we don't know if we have python yet, start a check
else
vim.system({ "poetry", "env", "info", "-p" }, { text = true }, function(obj)
if obj.code == 0 then
has_pynvim = 1
else
has_pynvim = 0
end
end)
has_pynvim = 0
end
end
-- count number of selected lines and characters
-- stolen: https://github.com/chrisgrieser/.config/blob/8af1841ba24f7c81c513e12f853b52f530ef5b37/nvim/lua/plugins/lualine.lua#L80C1-L87C4
local function selectionCount()
local isVisualMode = vim.fn.mode():find("[Vv]")
if not isVisualMode then
return ""
end
local starts = vim.fn.line("v")
local ends = vim.fn.line(".")
local lines = starts <= ends and ends - starts + 1 or starts - ends + 1
return " " .. tostring(lines) .. "L " .. tostring(vim.fn.wordcount().visual_chars) .. "C"
end
require("lualine").setup({
options = {
icons_enabled = true,
theme = "auto",
component_separators = { left = "", right = "" },
section_separators = { left = "", right = "" },
disabled_filetypes = {},
always_divide_middle = true,
},
sections = {
lualine_a = { "mode" },
lualine_b = { "branch", "diff", "diagnostics" },
lualine_c = { "filename" },
lualine_x = { "encoding", "fileformat", "filetype", molten },
lualine_y = { "progress" },
lualine_z = { selectionCount, "location" },
},
inactive_sections = {
lualine_a = {},
lualine_b = { "branch", "diff" },
lualine_c = { "filename" },
lualine_x = {},
lualine_y = { "location" },
lualine_z = {},
},
tabline = {},
extensions = {
"aerial",
"lazy",
"man",
"mason",
"nvim-dap-ui",
"nvim-tree",
"oil",
"quickfix",
"toggleterm",
"trouble",
},
})
end,
event = { "VeryLazy" },
},
}

View file

@ -1,91 +1,4 @@
return { return {
-- statusline
{
"nvim-lualine/lualine.nvim",
dependencies = { { "nvim-tree/nvim-web-devicons", config = true } },
config = function()
local has_pynvim = -1
-- if molten exists, is initialized and connected to a kernel
-- show it in the statusline
local function molten()
-- we don't have access to python, disregard element
if has_pynvim == 0 then
return ""
elseif has_pynvim == 1 then
local status_ok, res = pcall(function()
return require("molten.status").kernels() ~= ""
end)
if status_ok and res then
return "󱪄"
end
return ""
-- we don't know if we have python yet, start a check
else
vim.system({ "poetry", "env", "info", "-p" }, { text = true }, function(obj)
if obj.code == 0 then
has_pynvim = 1
else
has_pynvim = 0
end
end)
has_pynvim = 0
end
end
-- count number of selected lines and characters
-- stolen: https://github.com/chrisgrieser/.config/blob/8af1841ba24f7c81c513e12f853b52f530ef5b37/nvim/lua/plugins/lualine.lua#L80C1-L87C4
local function selectionCount()
local isVisualMode = vim.fn.mode():find("[Vv]")
if not isVisualMode then
return ""
end
local starts = vim.fn.line("v")
local ends = vim.fn.line(".")
local lines = starts <= ends and ends - starts + 1 or starts - ends + 1
return " " .. tostring(lines) .. "L " .. tostring(vim.fn.wordcount().visual_chars) .. "C"
end
require("lualine").setup({
options = {
icons_enabled = true,
theme = "auto",
component_separators = { left = "", right = "" },
section_separators = { left = "", right = "" },
disabled_filetypes = {},
always_divide_middle = true,
},
sections = {
lualine_a = { "mode" },
lualine_b = { "branch", "diff", "diagnostics" },
lualine_c = { "filename" },
lualine_x = { "encoding", "fileformat", "filetype", molten },
lualine_y = { "progress" },
lualine_z = { selectionCount, "location" },
},
inactive_sections = {
lualine_a = {},
lualine_b = { "branch", "diff" },
lualine_c = { "filename" },
lualine_x = {},
lualine_y = { "location" },
lualine_z = {},
},
tabline = {},
extensions = {
"aerial",
"lazy",
"man",
"mason",
"nvim-dap-ui",
"nvim-tree",
"oil",
"quickfix",
"toggleterm",
"trouble",
},
})
end,
event = { "VeryLazy" },
},
-- create pretty unobtrusive notifications -- create pretty unobtrusive notifications
{ {
"j-hui/fidget.nvim", "j-hui/fidget.nvim",