-
Notifications
You must be signed in to change notification settings - Fork 9
feat: nerd icons support #5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,3 +1,7 @@ | ||
| .claude | ||
| mdc | ||
| dist/ | ||
| QWEN.md | ||
| prompts/ | ||
| .gitignore | ||
| .qwen | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,72 @@ | ||
| package panel | ||
|
|
||
| import ( | ||
| "path/filepath" | ||
| "strings" | ||
| "unicode/utf8" | ||
|
|
||
| "github.com/kooler/MiddayCommander/internal/config" | ||
| ) | ||
|
|
||
| // IconResolver resolves file/directory names to Nerd Font icons based on | ||
| // configuration. It is immutable after creation and safe for concurrent use. | ||
| type IconResolver struct { | ||
| enabled bool | ||
| folder string | ||
| file string | ||
| extIcons map[string]string | ||
| } | ||
|
|
||
| // NewIconResolver creates a resolver from the given icon configuration. | ||
| // If cfg.Enabled is false, the resolver will return empty strings. | ||
| func NewIconResolver(cfg config.IconsConfig) IconResolver { | ||
| if !cfg.Enabled { | ||
| return IconResolver{} | ||
| } | ||
| r := IconResolver{ | ||
| enabled: true, | ||
| folder: cfg.Folder, | ||
| file: cfg.File, | ||
| extIcons: cfg.Extensions, | ||
| } | ||
| if r.folder == "" { | ||
| r.folder = "\uF07B" // nf-fa-folder | ||
| } | ||
| if r.file == "" { | ||
| r.file = "\uF016" // nf-fa-file | ||
| } | ||
| if r.extIcons == nil { | ||
| r.extIcons = make(map[string]string) | ||
| } | ||
| return r | ||
| } | ||
|
|
||
| // ResolveIcon returns the Nerd Font icon for the given entry. | ||
| // Returns an empty string if icons are disabled or no match is found. | ||
| // isDir determines whether to use the folder icon or extension-based lookup. | ||
| func (r IconResolver) ResolveIcon(name string, isDir bool) string { | ||
| if !r.enabled { | ||
| return "" | ||
| } | ||
| if isDir { | ||
| return r.folder | ||
| } | ||
| ext := strings.TrimPrefix(filepath.Ext(name), ".") | ||
| if ext == "" { | ||
| return r.file | ||
| } | ||
| if icon, ok := r.extIcons[strings.ToLower(ext)]; ok { | ||
| return icon | ||
| } | ||
|
Comment on lines
+58
to
+60
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Setting a user extension to "" produces a broken row. A user who wants to disable the default icon for .go by writing go = "" will get:
Lets pick one of:
|
||
| return r.file | ||
| } | ||
|
|
||
| // IconWidth returns the display width (in characters/rune count) of the icon | ||
| // that would be rendered for the given entry. Returns 0 if icons are disabled. | ||
| func (r IconResolver) IconWidth(name string, isDir bool) int { | ||
| icon := r.ResolveIcon(name, isDir) | ||
| if icon == "" { | ||
| return 0 | ||
| } | ||
| return utf8.RuneCountInString(icon) | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Many Nerd Font glyphs render as 2 terminal cells (East-Asian Wide / ambiguous-width in some terminals, and several nf-md-* / nf-custom-* glyphs are definitively 2 cells). utf8.RuneCountInString always returns 1 for a single-rune icon and will miscount those, causing the name column to be off by one. Probably better to use |
||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
gitnoreception :-)
Probably a mistake.