Skip to content

Commit 443945c

Browse files
authored
feat: add nerd font support (#350)
Signed-off-by: Chapman Pendery <[email protected]>
1 parent 19fc284 commit 443945c

File tree

3 files changed

+60
-0
lines changed

3 files changed

+60
-0
lines changed

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,14 @@ key = "escape"
109109

110110
Key names are matched against the Node.js [keypress](https://nodejs.org/api/readline.html#readlineemitkeypresseventsstream-interface) events.
111111

112+
### NerdFonts
113+
114+
If you are using a [NerdFont](https://www.nerdfonts.com/) patched font, you can enable the NerdFonts support in your config file:
115+
116+
```toml
117+
useNerdFont = true
118+
```
119+
112120
## Contributing
113121

114122
This project welcomes contributions and suggestions. Most contributions require you to agree to a

src/runtime/suggestion.ts

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import { Suggestion, SuggestionBlob } from "./model.js";
1010
import log from "../utils/log.js";
1111
import { escapePath } from "./utils.js";
1212
import { addPathSeparator, getPathDirname, removePathSeparator, Shell } from "../utils/shell.js";
13+
import { getConfig } from "../utils/config.js";
1314

1415
export enum SuggestionIcons {
1516
File = "📄",
@@ -22,12 +23,55 @@ export enum SuggestionIcons {
2223
Special = "⭐",
2324
Default = "📀",
2425
}
26+
export const NerdFontIcons = {
27+
alert: "\udb80\udc27",
28+
android: "\ue70e",
29+
apple: "\ue711",
30+
asterisk: "\uf069",
31+
aws: "\ue7ad",
32+
azure: "\ue754",
33+
box: "\uf1b2",
34+
carrot: "\uef3b",
35+
characters: "\udb82\udf34",
36+
commandkey: "\udb81\ude33",
37+
commit: "\ue729",
38+
cpu: "\uf4bc",
39+
database: "\ue706",
40+
discord: "\uf1ff",
41+
docker: "\ue7b0",
42+
firebase: "\ue787",
43+
flag: "\udb80\udd4f",
44+
gcloud: "\udb84\uddf6",
45+
git: "\ue702",
46+
github: "\ue709",
47+
gitlab: "\ue7eb",
48+
gradle: "\ue7f2",
49+
heroku: "\ue77b",
50+
invite: "\udb83\udebb",
51+
kubernetes: "\ue81d",
52+
netlify: "\ue83c",
53+
node: "\ued0d",
54+
npm: "\ued0e",
55+
slack: "\ue8a4",
56+
string: "\udb84\udc21",
57+
twitter: "\uf099",
58+
vercel: "\ue8d3",
59+
yarn: "\ue8ec",
60+
};
2561

2662
const getIcon = (icon: string | undefined, suggestionType: Fig.SuggestionType | undefined): string => {
2763
// eslint-disable-next-line no-control-regex
2864
if (icon && /[^\u0000-\u00ff]/.test(icon)) {
2965
return icon;
3066
}
67+
if (icon && icon.startsWith("fig://icon?type=") && getConfig().useNerdFont) {
68+
const iconType = icon.split("fig://icon?type=")[1].toLowerCase();
69+
const iconUtf = NerdFontIcons[iconType as keyof typeof NerdFontIcons];
70+
if (iconUtf != null && iconUtf !== "") {
71+
return iconUtf;
72+
}
73+
}
74+
3175
switch (suggestionType) {
3276
case "arg":
3377
return SuggestionIcons.Argument;

src/utils/config.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ type Config = {
2828
specs?: {
2929
path?: string[];
3030
};
31+
useNerdFont: boolean;
3132
};
3233

3334
const bindingSchema: JSONSchemaType<Binding> = {
@@ -68,6 +69,11 @@ const configSchema = {
6869
path: specPathsSchema,
6970
},
7071
},
72+
useNerdFont: {
73+
type: "boolean",
74+
nullable: true,
75+
default: false,
76+
},
7177
},
7278
additionalProperties: false,
7379
};
@@ -87,6 +93,7 @@ let globalConfig: Config = {
8793
acceptSuggestion: { key: "tab" },
8894
dismissSuggestions: { key: "escape" },
8995
},
96+
useNerdFont: false,
9097
};
9198

9299
export const getConfig = (): Config => globalConfig;
@@ -114,6 +121,7 @@ export const loadConfig = async (program: Command) => {
114121
specs: {
115122
path: [...(config?.specs?.path ?? []), ...(config?.specs?.path ?? [])],
116123
},
124+
useNerdFont: config?.useNerdFont ?? false,
117125
};
118126
}
119127
});

0 commit comments

Comments
 (0)