Compare commits
No commits in common. "a8c1fa25b72483225a233329ed36e4d3e6d014bd" and "75b544e352c55aab752649a8bc10c7f7188d1e59" have entirely different histories.
a8c1fa25b7
...
75b544e352
8 changed files with 66 additions and 112 deletions
|
@ -42,11 +42,11 @@ M.open_float = function(opts) vim.diagnostic.open_float(opts) end
|
||||||
---Toggle diagnostics in the given buffer.
|
---Toggle diagnostics in the given buffer.
|
||||||
---@param bufnr integer|nil: Buffer number (0 for current buffer, nil for all buffers.
|
---@param bufnr integer|nil: Buffer number (0 for current buffer, nil for all buffers.
|
||||||
M.toggle = function(bufnr)
|
M.toggle = function(bufnr)
|
||||||
local filter = { bufnr = bufnr or 0 }
|
bufnr = bufnr or 0
|
||||||
if vim.diagnostic.is_enabled(filter) then
|
if vim.diagnostic.is_disabled(bufnr) then
|
||||||
vim.diagnostic.enable(false, filter)
|
vim.diagnostic.enable(bufnr)
|
||||||
else
|
else
|
||||||
vim.diagnostic.enable(true, filter)
|
vim.diagnostic.disable(bufnr)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -4,76 +4,34 @@ return {
|
||||||
dependencies = "nvim-tree/nvim-web-devicons",
|
dependencies = "nvim-tree/nvim-web-devicons",
|
||||||
|
|
||||||
opts = function()
|
opts = function()
|
||||||
local icons = require("fschauen.util.icons")
|
|
||||||
local dynamic_color = require("fschauen.util.lualine").dynamic_color
|
local dynamic_color = require("fschauen.util.lualine").dynamic_color
|
||||||
local indicator = require("fschauen.util.lualine").indicator
|
|
||||||
local window = require("fschauen.util.window")
|
local window = require("fschauen.util.window")
|
||||||
local orange = "#d65d0e"
|
local orange = "#d65d0e"
|
||||||
|
|
||||||
local is_diagnostics_enabled = function(bufnr)
|
local autoformat = require("fschauen.util.autoformat").lualine()
|
||||||
return vim.diagnostic.is_enabled { bufnr = bufnr or 0 }
|
|
||||||
end
|
|
||||||
|
|
||||||
--
|
|
||||||
-- Components
|
|
||||||
--
|
|
||||||
|
|
||||||
local autoformat = indicator {
|
|
||||||
icon = icons.ui.Format,
|
|
||||||
cond = require("fschauen.util.autoformat").is_enabled,
|
|
||||||
}
|
|
||||||
local branch = {
|
local branch = {
|
||||||
"branch",
|
"branch",
|
||||||
icon = icons.git.Branch,
|
icon = require("fschauen.util.icons").git.Branch,
|
||||||
cond = window.is_medium,
|
|
||||||
}
|
|
||||||
local diagnostics = {
|
|
||||||
dynamic_color("diagnostics"),
|
|
||||||
cond = is_diagnostics_enabled,
|
|
||||||
}
|
|
||||||
local diag_status = indicator {
|
|
||||||
icon = icons.ui.Diagnostic,
|
|
||||||
cond = is_diagnostics_enabled,
|
|
||||||
}
|
|
||||||
local fileformat = {
|
|
||||||
"fileformat",
|
|
||||||
cond = window.is_medium,
|
cond = window.is_medium,
|
||||||
}
|
}
|
||||||
|
local diagnostics = dynamic_color("diagnostics")
|
||||||
|
local fileformat = { "fileformat", cond = window.is_medium }
|
||||||
local filename = "fschauen.filename"
|
local filename = "fschauen.filename"
|
||||||
local filetype = {
|
local filetype = { dynamic_color("filetype"), cond = window.is_medium }
|
||||||
dynamic_color("filetype"),
|
|
||||||
cond = window.is_medium,
|
|
||||||
}
|
|
||||||
local mode = "fschauen.mode"
|
local mode = "fschauen.mode"
|
||||||
local searchcount = "fschauen.searchcount"
|
local searchcount = "fschauen.searchcount"
|
||||||
local spell = indicator {
|
local spell = "fschauen.spell"
|
||||||
icon = icons.ui.SpellCheck,
|
local status =
|
||||||
cond = function() return vim.o.spell end,
|
{ dynamic_color("fschauen.status"), color = { fg = orange }, padding = 0 }
|
||||||
}
|
local whitespace = { dynamic_color("fschauen.whitespace"), cond = window.is_wide }
|
||||||
local status = {
|
local wrap = "fschauen.wrap"
|
||||||
dynamic_color("fschauen.status"),
|
|
||||||
color = { fg = orange },
|
|
||||||
padding = 0,
|
|
||||||
}
|
|
||||||
local whitespace = {
|
|
||||||
dynamic_color("fschauen.whitespace"),
|
|
||||||
cond = window.is_wide,
|
|
||||||
}
|
|
||||||
local wrap = indicator {
|
|
||||||
icon = icons.ui.TextWrap,
|
|
||||||
cond = function() return vim.o.wrap end,
|
|
||||||
}
|
|
||||||
|
|
||||||
--
|
|
||||||
-- Sections
|
|
||||||
--
|
|
||||||
|
|
||||||
local sections = {
|
local sections = {
|
||||||
lualine_a = { mode },
|
lualine_a = { mode },
|
||||||
lualine_b = { branch },
|
lualine_b = { branch },
|
||||||
lualine_c = { filename, status },
|
lualine_c = { filename, status },
|
||||||
lualine_x = { diagnostics, searchcount, whitespace, filetype },
|
lualine_x = { diagnostics, searchcount, whitespace, filetype },
|
||||||
lualine_y = { diag_status, spell, wrap, autoformat, fileformat, "progress" },
|
lualine_y = { spell, wrap, autoformat, fileformat, "progress" },
|
||||||
lualine_z = { "location" },
|
lualine_z = { "location" },
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -4,18 +4,18 @@ M._augroup = nil
|
||||||
|
|
||||||
---Whether autoformatting is enabled.
|
---Whether autoformatting is enabled.
|
||||||
---@return boolean
|
---@return boolean
|
||||||
M.is_enabled = function() return M._augroup ~= nil end
|
local is_enabled = function() return M._augroup ~= nil end
|
||||||
|
|
||||||
---Disable autoformatting.
|
---Disable autoformatting.
|
||||||
M.disable = function()
|
M.disable = function()
|
||||||
if not M.is_enabled() then return end
|
if not is_enabled() then return end
|
||||||
vim.api.nvim_del_augroup_by_id(M._augroup)
|
vim.api.nvim_del_augroup_by_id(M._augroup)
|
||||||
M._augroup = nil
|
M._augroup = nil
|
||||||
end
|
end
|
||||||
|
|
||||||
---Enable autoformatting.
|
---Enable autoformatting.
|
||||||
M.enable = function()
|
M.enable = function()
|
||||||
if M.is_enabled() then return end
|
if is_enabled() then return end
|
||||||
|
|
||||||
local ok, formatter = pcall(require, "formatter.format")
|
local ok, formatter = pcall(require, "formatter.format")
|
||||||
if not ok then
|
if not ok then
|
||||||
|
@ -34,11 +34,21 @@ end
|
||||||
|
|
||||||
---Toggle autoformatting.
|
---Toggle autoformatting.
|
||||||
M.toggle = function()
|
M.toggle = function()
|
||||||
if M.is_enabled() then
|
if is_enabled() then
|
||||||
M.disable()
|
M.disable()
|
||||||
else
|
else
|
||||||
M.enable()
|
M.enable()
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
---Create a lualine component that shows an icon when autoformatting is enabled.
|
||||||
|
---@return table component
|
||||||
|
M.lualine = function()
|
||||||
|
local icon = require("fschauen.util.icons").ui.Format
|
||||||
|
return {
|
||||||
|
function() return icon end,
|
||||||
|
cond = is_enabled,
|
||||||
|
}
|
||||||
|
end
|
||||||
|
|
||||||
return M
|
return M
|
||||||
|
|
|
@ -119,11 +119,9 @@ M.ui = {
|
||||||
ReadOnly = "", -- "RO",
|
ReadOnly = "", -- "RO",
|
||||||
Search = "", --
|
Search = "", --
|
||||||
Sleep = "",
|
Sleep = "",
|
||||||
SpellCheck = "",
|
|
||||||
Telescope = "",
|
Telescope = "",
|
||||||
TestTube = "", --
|
TestTube = "", --
|
||||||
Text = "",
|
Text = "",
|
||||||
TextWrap = "",
|
|
||||||
Toggle = "",
|
Toggle = "",
|
||||||
TrafficLight = "",
|
TrafficLight = "",
|
||||||
Tree = "",
|
Tree = "",
|
||||||
|
|
|
@ -38,37 +38,4 @@ M.dynamic_color = function(base)
|
||||||
return component
|
return component
|
||||||
end
|
end
|
||||||
|
|
||||||
---@class LualineIndicatorSpec
|
|
||||||
---@field icon string The icon to show when the indicator is active.
|
|
||||||
---@field cond function A function that returns true when the indicator should
|
|
||||||
--- be visible, false otherwise.
|
|
||||||
|
|
||||||
---Make a lualine indicator that shows an icon when a condition is true.
|
|
||||||
---@param spec LualineIndicatorSpec
|
|
||||||
---@return table component
|
|
||||||
M.indicator = function(spec)
|
|
||||||
vim.validate {
|
|
||||||
spec = { spec, "table" },
|
|
||||||
icon = { spec.icon, "string" },
|
|
||||||
cond = { spec.cond, "function" },
|
|
||||||
}
|
|
||||||
|
|
||||||
local component = require("lualine.component"):extend()
|
|
||||||
|
|
||||||
function component:init(options)
|
|
||||||
component.super.init(
|
|
||||||
self,
|
|
||||||
vim.tbl_deep_extend(
|
|
||||||
"keep",
|
|
||||||
options or {},
|
|
||||||
{ cond = spec.cond or function() return false end }
|
|
||||||
)
|
|
||||||
)
|
|
||||||
end
|
|
||||||
|
|
||||||
function component:update_status(--[[is_focused]]_) return spec.icon or "?" end
|
|
||||||
|
|
||||||
return component
|
|
||||||
end
|
|
||||||
|
|
||||||
return M
|
return M
|
||||||
|
|
|
@ -6,29 +6,22 @@ function M:init(options)
|
||||||
vim.tbl_extend("keep", options or {}, {
|
vim.tbl_extend("keep", options or {}, {
|
||||||
maxcount = 999,
|
maxcount = 999,
|
||||||
timeout = 250,
|
timeout = 250,
|
||||||
cond = function() return vim.v.hlsearch == 1 end,
|
|
||||||
})
|
})
|
||||||
)
|
)
|
||||||
end
|
end
|
||||||
|
|
||||||
local denominator = function(tbl)
|
|
||||||
if tbl.total > tbl.maxcount then return "" end
|
|
||||||
return string.format("%d", tbl.total)
|
|
||||||
end
|
|
||||||
|
|
||||||
local render = function(tbl)
|
|
||||||
local status = "?"
|
|
||||||
if not vim.tbl_isempty(tbl) and vim.v.hlsearch == 1 then
|
|
||||||
status = string.format("%d/%s", tbl.current, denominator(tbl))
|
|
||||||
end
|
|
||||||
return string.format(" %s", status)
|
|
||||||
end
|
|
||||||
|
|
||||||
function M:update_status()
|
function M:update_status()
|
||||||
return render(vim.fn.searchcount {
|
if vim.v.hlsearch == 0 then return "" end
|
||||||
|
|
||||||
|
local count = vim.fn.searchcount {
|
||||||
maxcount = self.options.maxcount,
|
maxcount = self.options.maxcount,
|
||||||
timeout = self.options.timeout,
|
timeout = self.options.timeout,
|
||||||
})
|
}
|
||||||
|
if next(count) == nil then return "" end
|
||||||
|
|
||||||
|
local denominator = count.total > count.maxcount and ""
|
||||||
|
or string.format("%d", count.total)
|
||||||
|
return string.format(" %d/%s", count.current, denominator)
|
||||||
end
|
end
|
||||||
|
|
||||||
return M
|
return M
|
||||||
|
|
14
config/nvim/lua/lualine/components/fschauen/spell.lua
Normal file
14
config/nvim/lua/lualine/components/fschauen/spell.lua
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
local M = require("lualine.component"):extend()
|
||||||
|
|
||||||
|
function M:init(options)
|
||||||
|
M.super.init(
|
||||||
|
self,
|
||||||
|
vim.tbl_deep_extend("keep", options or {}, {
|
||||||
|
cond = function() return vim.o.spell end,
|
||||||
|
})
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
|
function M:update_status(--[[is_focused]]_) return "" end
|
||||||
|
|
||||||
|
return M
|
14
config/nvim/lua/lualine/components/fschauen/wrap.lua
Normal file
14
config/nvim/lua/lualine/components/fschauen/wrap.lua
Normal file
|
@ -0,0 +1,14 @@
|
||||||
|
local M = require("lualine.component"):extend()
|
||||||
|
|
||||||
|
function M:init(options)
|
||||||
|
M.super.init(
|
||||||
|
self,
|
||||||
|
vim.tbl_deep_extend("keep", options or {}, {
|
||||||
|
cond = function() return vim.o.wrap end,
|
||||||
|
})
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
|
function M:update_status(--[[is_focused]]_) return "" end
|
||||||
|
|
||||||
|
return M
|
Loading…
Add table
Reference in a new issue