fix(ci): luacats support
This commit is contained in:
parent
747e7b6222
commit
6a8668fab5
6 changed files with 121 additions and 0 deletions
|
|
@ -232,6 +232,16 @@ iTerm2 ~
|
|||
|
||||
Preferences > Profiles > Text > Non-ASCII Font > select Nonicons
|
||||
|
||||
==============================================================================
|
||||
COMMANDS *nonicons-commands*
|
||||
|
||||
*:NoniconsHiTest*
|
||||
`:NoniconsHiTest`
|
||||
Open a scratch buffer listing every icon in the nonicons font alongside
|
||||
its name, Unicode codepoint, and which extensions / filenames / filetypes
|
||||
map to it. Use this to visually verify that glyphs render correctly and
|
||||
that resolution tables point to the intended icons.
|
||||
|
||||
==============================================================================
|
||||
HEALTH CHECK *nonicons-health*
|
||||
|
||||
|
|
|
|||
85
lua/nonicons/hi-test.lua
Normal file
85
lua/nonicons/hi-test.lua
Normal file
|
|
@ -0,0 +1,85 @@
|
|||
local mapping = require('nonicons.mapping')
|
||||
local resolve = require('nonicons.resolve')
|
||||
|
||||
---@param name string
|
||||
---@return string
|
||||
local function char(name)
|
||||
local code = mapping[name]
|
||||
if code then
|
||||
return vim.fn.nr2char(code)
|
||||
end
|
||||
return '?'
|
||||
end
|
||||
|
||||
---@param t table<string, any>
|
||||
---@return string[]
|
||||
local function sorted_keys(t)
|
||||
local keys = {}
|
||||
for k in pairs(t) do
|
||||
keys[#keys + 1] = k
|
||||
end
|
||||
table.sort(keys)
|
||||
return keys
|
||||
end
|
||||
|
||||
---@param t table<string, string>
|
||||
---@return table<string, string[]>
|
||||
local function invert(t)
|
||||
local inv = {}
|
||||
for k, v in pairs(t) do
|
||||
inv[v] = inv[v] or {}
|
||||
inv[v][#inv[v] + 1] = k
|
||||
end
|
||||
for _, list in pairs(inv) do
|
||||
table.sort(list)
|
||||
end
|
||||
return inv
|
||||
end
|
||||
|
||||
return function()
|
||||
local lines = {} ---@type string[]
|
||||
|
||||
local ext_by_icon = invert(resolve.ext_map)
|
||||
local fname_by_icon = invert(resolve.filename_map)
|
||||
local ft_by_icon = invert(resolve.ft_map)
|
||||
|
||||
local icon_names = sorted_keys(mapping)
|
||||
|
||||
lines[#lines + 1] = 'nonicons.nvim — icon reference'
|
||||
lines[#lines + 1] = string.rep('=', 72)
|
||||
lines[#lines + 1] = ''
|
||||
lines[#lines + 1] = string.format(' %-4s %-28s %-7s %s', 'ICON', 'NAME', 'CODE', 'MAPPED FROM')
|
||||
lines[#lines + 1] = string.rep('-', 72)
|
||||
|
||||
for _, name in ipairs(icon_names) do
|
||||
local sources = {} ---@type string[]
|
||||
if ext_by_icon[name] then
|
||||
for _, ext in ipairs(ext_by_icon[name]) do
|
||||
sources[#sources + 1] = 'ext:' .. ext
|
||||
end
|
||||
end
|
||||
if fname_by_icon[name] then
|
||||
for _, fname in ipairs(fname_by_icon[name]) do
|
||||
sources[#sources + 1] = 'file:' .. fname
|
||||
end
|
||||
end
|
||||
if ft_by_icon[name] then
|
||||
for _, ft in ipairs(ft_by_icon[name]) do
|
||||
sources[#sources + 1] = 'ft:' .. ft
|
||||
end
|
||||
end
|
||||
|
||||
local src_str = #sources > 0 and table.concat(sources, ', ') or ''
|
||||
lines[#lines + 1] = string.format(' %s %-28s U+%04X %s', char(name), name, mapping[name], src_str)
|
||||
end
|
||||
|
||||
lines[#lines + 1] = ''
|
||||
lines[#lines + 1] = string.format('%d icons total', #icon_names)
|
||||
|
||||
local buf = vim.api.nvim_create_buf(false, true)
|
||||
vim.api.nvim_buf_set_lines(buf, 0, -1, false, lines)
|
||||
vim.bo[buf].modifiable = false
|
||||
vim.bo[buf].buftype = 'nofile'
|
||||
vim.bo[buf].bufhidden = 'wipe'
|
||||
vim.api.nvim_set_current_buf(buf)
|
||||
end
|
||||
|
|
@ -24,8 +24,11 @@ local function ensure_initialized()
|
|||
initialized = true
|
||||
end
|
||||
|
||||
---@type table<string, integer>
|
||||
M.mapping = require('nonicons.mapping')
|
||||
|
||||
---@param name string Icon name
|
||||
---@return string? glyph
|
||||
function M.get(name)
|
||||
local code = M.mapping[name]
|
||||
if code then
|
||||
|
|
@ -40,6 +43,9 @@ function M.apply()
|
|||
end
|
||||
end
|
||||
|
||||
---@param name string? Filename (e.g. `'init.lua'`)
|
||||
---@param ext string? File extension (e.g. `'lua'`)
|
||||
---@return string? glyph
|
||||
function M.get_icon(name, ext)
|
||||
local key = require('nonicons.resolve').resolve_name(name, ext)
|
||||
if key then
|
||||
|
|
@ -47,6 +53,8 @@ function M.get_icon(name, ext)
|
|||
end
|
||||
end
|
||||
|
||||
---@param ft string Vim filetype
|
||||
---@return string? glyph
|
||||
function M.get_icon_by_filetype(ft)
|
||||
local key = require('nonicons.resolve').resolve_filetype(ft)
|
||||
if key then
|
||||
|
|
|
|||
|
|
@ -1,6 +1,8 @@
|
|||
local mapping = require('nonicons.mapping')
|
||||
local resolve_mod = require('nonicons.resolve')
|
||||
|
||||
---@param name string
|
||||
---@return string?
|
||||
local function char(name)
|
||||
local code = mapping[name]
|
||||
if code then
|
||||
|
|
@ -8,8 +10,12 @@ local function char(name)
|
|||
end
|
||||
end
|
||||
|
||||
---@type string
|
||||
local fallback_icon
|
||||
|
||||
---@param name string?
|
||||
---@param ext string?
|
||||
---@return string
|
||||
local function resolve(name, ext)
|
||||
local key = resolve_mod.resolve_name(name, ext)
|
||||
if key then
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
local M = {}
|
||||
|
||||
---@type table<string, string>
|
||||
M.ext_map = {
|
||||
lua = 'lua',
|
||||
luac = 'lua',
|
||||
|
|
@ -287,6 +288,7 @@ M.ext_map = {
|
|||
mojo = 'code',
|
||||
}
|
||||
|
||||
---@type table<string, string>
|
||||
M.filename_map = {
|
||||
['dockerfile'] = 'docker',
|
||||
['containerfile'] = 'docker',
|
||||
|
|
@ -421,6 +423,7 @@ M.filename_map = {
|
|||
['code_of_conduct.md'] = 'book',
|
||||
}
|
||||
|
||||
---@type table<string, string>
|
||||
M.ft_map = {
|
||||
typescriptreact = 'react',
|
||||
javascriptreact = 'react',
|
||||
|
|
@ -434,6 +437,9 @@ M.ft_map = {
|
|||
latex = 'book',
|
||||
}
|
||||
|
||||
---@param name string? Filename (e.g. `'init.lua'`)
|
||||
---@param ext string? File extension (e.g. `'lua'`)
|
||||
---@return string? icon_name
|
||||
function M.resolve_name(name, ext)
|
||||
if ext and M.ext_map[ext] then
|
||||
return M.ext_map[ext]
|
||||
|
|
@ -459,6 +465,8 @@ function M.resolve_name(name, ext)
|
|||
end
|
||||
end
|
||||
|
||||
---@param ft string? Vim filetype
|
||||
---@return string? icon_name
|
||||
function M.resolve_filetype(ft)
|
||||
if not ft then
|
||||
return
|
||||
|
|
|
|||
|
|
@ -4,3 +4,7 @@ end
|
|||
vim.g.loaded_nonicons = 1
|
||||
|
||||
require('nonicons').apply()
|
||||
|
||||
vim.api.nvim_create_user_command('NoniconsHiTest', function()
|
||||
require('nonicons.hi-test')()
|
||||
end, { desc = 'nonicons: display all icons' })
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue