local devicons = require("nvim-web-devicons") local M = {} local configured_icons = {} local function escape_statusline(text) return (text:gsub("%%", "%%%%")) end ---Replace the configured filetype icon overrides. ---@param icons table function M.set_icons(icons) configured_icons = icons end ---Render the filetype box, including an icon when one is available. ---@param filetype string ---@return string? component function M.render(filetype) if filetype == "" then return nil end local icon = configured_icons[filetype] if icon == nil then icon = devicons.get_icon_by_filetype(filetype) end local display = filetype if icon and icon ~= "" then display = icon .. " " .. display end return ("%%#StatusFiletype# %s %%*"):format(escape_statusline(display)) end return M