Add support for Nerd fonts

Also provides some graceful degradation without them
This commit is contained in:
ViViDboarder 2024-11-27 12:14:01 -08:00
parent 0c5367a1a8
commit bf630d6bbf
7 changed files with 100 additions and 76 deletions

70
neovim/lua/icons.lua Normal file
View File

@ -0,0 +1,70 @@
local M = {}
function M.init()
if vim.env["TERM_NERD_FONT"] == "1" then
M.nerd_font = true
else
M.nerd_font = false
end
-- Diagnostics signs
if vim.env["TERM"] == "xterm-kitty" then
-- Don't use double width emoji for Kitty
M.diagnostic_signs = {
Error = "🔥",
Warn = "",
Hint = "🤔",
Info = "i",
Pencil = "",
}
else
M.diagnostic_signs = {
Error = "🔥",
Warn = "⚠️",
Hint = "🤔",
Info = "",
Pencil = "✏️",
}
end
-- Debug icons
M.debug_icons = {
breakpoint = "🛑",
conditional_breakpoint = "🔍",
log_point = "📝",
current = "👉",
breakpoint_rejected = "🚫",
}
-- Debug control icons
if vim.env["TERM"] == "xterm-kitty" then
-- Don't use double width emoji for Kitty
M.debug_control_icons = {
disconnect = "",
pause = "",
play = "",
run_last = "",
step_back = "",
step_into = "",
step_out = "",
step_over = "",
terminate = "",
}
else
M.debug_control_icons = {
disconnect = "⏏️",
pause = "⏸️",
play = "▶️",
run_last = "⏮️",
step_back = "◀️",
step_into = "⤵️",
step_out = "⤴️",
step_over = "⏭️",
terminate = "⏹️",
}
end
end
M.init()
return M

View File

@ -66,6 +66,9 @@ return {
opts = { opts = {
-- Ignore warnings about config. Turn these on when switching major versions -- Ignore warnings about config. Turn these on when switching major versions
notify = false, notify = false,
icons = {
mappings = require("icons").nerd_font,
},
}, },
version = utils.map_version_rule({ version = utils.map_version_rule({
[">=0.9.4"] = "3.x.x", [">=0.9.4"] = "3.x.x",
@ -247,24 +250,26 @@ return {
-- dap_mapping("r", dap.repl.open, { desc = "Open REPL" }) -- dap_mapping("r", dap.repl.open, { desc = "Open REPL" })
-- dap_mapping("R", dap.repl.run_last, { desc = "Run last" }) -- dap_mapping("R", dap.repl.run_last, { desc = "Run last" })
local icons = require("icons")
-- Set dap signs -- Set dap signs
vim.fn.sign_define( vim.fn.sign_define(
"DapBreakpoint", "DapBreakpoint",
{ text = utils.debug_icons.breakpoint, texthl = "", linehl = "", numhl = "" } { text = icons.debug_icons.breakpoint, texthl = "", linehl = "", numhl = "" }
) )
vim.fn.sign_define( vim.fn.sign_define(
"DapLogPoint", "DapLogPoint",
{ text = utils.debug_icons.log_point, texthl = "", linehl = "", numhl = "" } { text = icons.debug_icons.log_point, texthl = "", linehl = "", numhl = "" }
) )
vim.fn.sign_define( vim.fn.sign_define(
"DapBreakpointCondition", "DapBreakpointCondition",
{ text = utils.debug_icons.conditional_breakpoint, texthl = "", linehl = "", numhl = "" } { text = icons.debug_icons.conditional_breakpoint, texthl = "", linehl = "", numhl = "" }
) )
vim.fn.sign_define("DapStopped", { text = utils.debug_icons.current, texthl = "", linehl = "", numhl = "" }) vim.fn.sign_define("DapStopped", { text = icons.debug_icons.current, texthl = "", linehl = "", numhl = "" })
vim.fn.sign_define( vim.fn.sign_define(
"DapBreakpointRejected", "DapBreakpointRejected",
{ text = utils.debug_icons.breakpoint_rejected, texthl = "", linehl = "", numhl = "" } { text = icons.debug_icons.breakpoint_rejected, texthl = "", linehl = "", numhl = "" }
) )
end, end,
lazy = true, lazy = true,
@ -284,7 +289,7 @@ return {
current_frame = ">", current_frame = ">",
}, },
controls = { controls = {
icons = utils.debug_control_icons, icons = require("icons").debug_control_icons,
}, },
}) })
local dap, dapui = require("dap"), require("dapui") local dap, dapui = require("dap"), require("dapui")

View File

@ -21,7 +21,7 @@ function M.config_lsp_ui()
end end
-- Diagnostics signs -- Diagnostics signs
for type, icon in pairs(utils.diagnostic_signs) do for type, icon in pairs(require("icons").diagnostic_signs) do
local hl = "DiagnosticSign" .. type local hl = "DiagnosticSign" .. type
vim.fn.sign_define(hl, { text = icon, texthl = hl, numhl = hl }) vim.fn.sign_define(hl, { text = icon, texthl = hl, numhl = hl })
end end
@ -30,7 +30,7 @@ function M.config_lsp_ui()
trouble.setup({ trouble.setup({
fold_open = "", fold_open = "",
fold_closed = "", fold_closed = "",
icons = false, icons = require("icons").nerd_font,
use_diagnostic_signs = true, use_diagnostic_signs = true,
}) })
end) end)

View File

@ -58,8 +58,9 @@ function M.config_lualine(theme_name)
-- navic -- navic
local code_loc = {} local code_loc = {}
utils.try_require("nvim-navic", function(navic) utils.try_require("nvim-navic", function(navic)
navic.setup({ local opts = {}
icons = { if not require("icons").nerd_font then
opts.icons = {
Array = "𝐴 ", Array = "𝐴 ",
Boolean = "𝐵 ", Boolean = "𝐵 ",
Class = " ", Class = " ",
@ -86,15 +87,17 @@ function M.config_lualine(theme_name)
Struct = "𝑆 ", Struct = "𝑆 ",
TypeParameter = "𝑇𝑃 ", TypeParameter = "𝑇𝑃 ",
Variable = "𝑉 ", Variable = "𝑉 ",
}, }
}) end
navic.setup(opts)
code_loc = { "navic" } code_loc = { "navic" }
end) end)
require("lualine").setup({ require("lualine").setup({
options = { options = {
theme = theme_name, theme = theme_name,
icons_enabled = false, icons_enabled = require("icons").nerd_font,
component_separators = { left = "|", right = "|" }, component_separators = { left = "|", right = "|" },
section_separators = { left = "", right = "" }, section_separators = { left = "", right = "" },
}, },

View File

@ -1,14 +1,14 @@
local utils = require("utils") local utils = require("utils")
local notify = require("notify") local notify = require("notify")
local icons = require("icons")
notify.setup({ notify.setup({
icons = { icons = {
ERROR = utils.diagnostic_signs.Error, ERROR = icons.diagnostic_signs.Error,
WARN = utils.diagnostic_signs.Warn, WARN = icons.diagnostic_signs.Warn,
DEBUG = utils.diagnostic_signs.Hint, DEBUG = icons.diagnostic_signs.Hint,
TRACE = utils.diagnostic_signs.Pencil, TRACE = icons.diagnostic_signs.Pencil,
INFO = utils.diagnostic_signs.Info, INFO = icons.diagnostic_signs.Info,
}, },
}) })

View File

@ -1,4 +1,4 @@
local utils = require("utils") local icons = require("icons")
require("todo-comments").setup({ require("todo-comments").setup({
signs = false, signs = false,
@ -7,7 +7,7 @@ require("todo-comments").setup({
icon = "🩹", icon = "🩹",
}, },
TODO = { TODO = {
icon = utils.diagnostic_signs.Pencil, icon = icons.diagnostic_signs.Pencil,
}, },
HACK = { HACK = {
icon = "🙈", icon = "🙈",
@ -19,7 +19,7 @@ require("todo-comments").setup({
icon = "📓", icon = "📓",
}, },
WARNING = { WARNING = {
icon = utils.diagnostic_signs.Warn, icon = icons.diagnostic_signs.Warn,
}, },
}, },
}) })

View File

@ -178,58 +178,4 @@ function M.curry_keymap(mode, prefix, default_opts)
end end
end end
-- Diagnostics signs
M.diagnostic_signs = {
Error = "🔥",
Warn = "⚠️",
Hint = "🤔",
Info = "",
Pencil = "✏️",
}
-- Don't use emoji for Kitty
if vim.env["TERM"] == "xterm-kitty" then
M.diagnostic_signs = {
Error = "🔥",
Warn = "",
Hint = "🤔",
Info = "i",
Pencil = "",
}
end
M.debug_icons = {
breakpoint = "🛑",
conditional_breakpoint = "🔍",
log_point = "📝",
current = "👉",
breakpoint_rejected = "🚫",
}
M.debug_control_icons = {
disconnect = "⏏️",
pause = "⏸️",
play = "▶️",
run_last = "⏮️",
step_back = "◀️",
step_into = "⤵️",
step_out = "⤴️",
step_over = "⏭️",
terminate = "⏹️",
}
if vim.env["TERM"] == "xterm-kitty" then
M.debug_control_icons = {
disconnect = "",
pause = "",
play = "",
run_last = "",
step_back = "",
step_into = "",
step_out = "",
step_over = "",
terminate = "",
}
end
return M return M