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 = {
-- Ignore warnings about config. Turn these on when switching major versions
notify = false,
icons = {
mappings = require("icons").nerd_font,
},
},
version = utils.map_version_rule({
[">=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.run_last, { desc = "Run last" })
local icons = require("icons")
-- Set dap signs
vim.fn.sign_define(
"DapBreakpoint",
{ text = utils.debug_icons.breakpoint, texthl = "", linehl = "", numhl = "" }
{ text = icons.debug_icons.breakpoint, texthl = "", linehl = "", numhl = "" }
)
vim.fn.sign_define(
"DapLogPoint",
{ text = utils.debug_icons.log_point, texthl = "", linehl = "", numhl = "" }
{ text = icons.debug_icons.log_point, texthl = "", linehl = "", numhl = "" }
)
vim.fn.sign_define(
"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(
"DapBreakpointRejected",
{ text = utils.debug_icons.breakpoint_rejected, texthl = "", linehl = "", numhl = "" }
{ text = icons.debug_icons.breakpoint_rejected, texthl = "", linehl = "", numhl = "" }
)
end,
lazy = true,
@ -284,7 +289,7 @@ return {
current_frame = ">",
},
controls = {
icons = utils.debug_control_icons,
icons = require("icons").debug_control_icons,
},
})
local dap, dapui = require("dap"), require("dapui")

View File

@ -21,7 +21,7 @@ function M.config_lsp_ui()
end
-- 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
vim.fn.sign_define(hl, { text = icon, texthl = hl, numhl = hl })
end
@ -30,7 +30,7 @@ function M.config_lsp_ui()
trouble.setup({
fold_open = "",
fold_closed = "",
icons = false,
icons = require("icons").nerd_font,
use_diagnostic_signs = true,
})
end)

View File

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

View File

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

View File

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