Skip to content

Commit ffdcc0c

Browse files
committed
Support Nerd Fonts and add a NF Glyph element
Resolves #33
1 parent 0deeab6 commit ffdcc0c

File tree

9 files changed

+43266
-22
lines changed

9 files changed

+43266
-22
lines changed

package-lock.json

Lines changed: 30 additions & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
"@heroicons/vue": "^2.2.0",
1212
"core-js": "^3.43.0",
1313
"d3-time-format": "^4.1.0",
14+
"fuse.js": "^7.1.0",
15+
"lodash.debounce": "^4.0.8",
1416
"pinia": "^3.0.3",
1517
"pinia-plugin-persistedstate": "^4.3.0",
1618
"vue": "^3.5.16",
@@ -19,6 +21,7 @@
1921
},
2022
"devDependencies": {
2123
"@types/d3-time-format": "^4.0.3",
24+
"@types/lodash.debounce": "^4.0.9",
2225
"@typescript-eslint/eslint-plugin": "^8.7.0",
2326
"@typescript-eslint/parser": "^8.7.0",
2427
"@vue/cli-plugin-babel": "^5.0.8",

src/components/output/PS1Variable.vue

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,7 @@
2020
href="https://github.com/git/git/blob/master/contrib/completion/git-prompt.sh"
2121
target="_blank"
2222
rel="noopener noreferrer"
23-
>
24-
<code>git-prompt.sh</code>
25-
</a>
23+
><code>git-prompt.sh</code></a>
2624
file to your home directory and <code>source</code> it in your <code>~/.bashrc</code> file
2725
(as described in <code>git-prompt.sh</code>).
2826
By default the status will only contain the current branch name, however you can include more information using
@@ -34,11 +32,18 @@
3432
href="https://www.gnu.org/software/bash/manual/html_node/Bash-Variables.html#index-PROMPT_005fDIRTRIM"
3533
target="_blank"
3634
rel="noopener noreferrer"
37-
>
38-
<code>PROMPT_DIRTRIM</code>
39-
</a>
35+
><code>PROMPT_DIRTRIM</code></a>
4036
environment variable in your <code>~/.bashrc</code> file.
4137
</div>
38+
<div class="hint" v-if="hasElement('Nerd Font Glyph')">
39+
For <code>Nerd Font Glyph</code> elements to be properly displayed, you need to have a
40+
<a
41+
href="https://www.nerdfonts.com/"
42+
target="_blank"
43+
rel="noopener noreferrer"
44+
>Nerd Font</a>
45+
installed and configured in your terminal.
46+
</div>
4247
</template>
4348

4449
<script lang="ts">
@@ -306,14 +311,15 @@ export default defineComponent({
306311

307312
<style lang="sass" scoped>
308313
@import "@/assets/sass/_variables.sass"
314+
@import "https://www.nerdfonts.com/assets/css/webfont.css"
309315
310316
.ps1
311317
display: inline-block
312318
margin: 0.5em 0 1em 0
313319
padding: 1em
314320
color: $color-background
315321
background-color: $color-foreground
316-
font-family: 'Roboto Mono', 'Noto Sans Mono', monospace
322+
font-family: 'NerdFontsSymbols Nerd Font', 'Roboto Mono', 'Noto Sans Mono', monospace
317323
line-height: 1.5
318324
min-height: 1.5em
319325
word-break: break-all

src/components/output/PromptPreview.vue

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,14 +197,15 @@ export default defineComponent({
197197

198198
<style lang="sass" scoped>
199199
@import "@/assets/sass/_variables.sass"
200+
@import "https://www.nerdfonts.com/assets/css/webfont.css"
200201
201202
h3
202203
display: inline-block
203204
204205
.preview
205206
display: inline-block
206207
margin: 1em 0 2em 0
207-
font-family: 'Roboto Mono', 'Noto Sans Mono', monospace
208+
font-family: 'NerdFontsSymbols Nerd Font', 'Roboto Mono', 'Noto Sans Mono', monospace
208209
text-align: left
209210
line-height: 1.5
210211
min-height: 1.5em

src/components/prompteditor/AddedPromptElement.vue

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,12 +97,13 @@ export default defineComponent({
9797
<style lang="sass" scoped>
9898
@use "sass:color"
9999
@import "@/assets/sass/_variables.sass"
100+
@import "https://www.nerdfonts.com/assets/css/webfont.css"
100101
101102
.selected
102103
// darken the background color because the delete icon has the same color
103104
background-color: color.adjust($color-accent, $lightness: -15%)
104105
105106
.parameter
106107
vertical-align: middle
107-
font-family: monospace
108+
font-family: 'NerdFontsSymbols Nerd Font', monospace
108109
</style>

src/components/prompteditor/PromptElements.vue

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,6 +124,7 @@ export default defineComponent({
124124

125125
<style lang="sass" scoped>
126126
@import "@/assets/sass/_variables.sass"
127+
@import "https://www.nerdfonts.com/assets/css/webfont.css"
127128
128129
.sortable-ghost
129130
opacity: 0.4
@@ -142,7 +143,7 @@ hr
142143
width: 90%
143144
max-width: 24em
144145
font-size: 1.1em
145-
font-family: monospace
146+
font-family: 'NerdFontsSymbols Nerd Font', monospace
146147
margin-top: 0.1em
147148
margin-bottom: 0.8em
148149

src/components/properties/ElementProperties.vue

Lines changed: 85 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -11,11 +11,11 @@
1111
<legend>{{ parameter.label }}</legend>
1212
<label v-if="parameter.unselectLabel !== undefined" :for="`parameter_none_${parameter.id}`">
1313
<input
14-
type="radio"
15-
:id="`parameter_none_${parameter.id}`"
16-
:name="parameter.id"
17-
value=""
18-
v-model="element.parameters[parameter.id]"
14+
type="radio"
15+
:id="`parameter_none_${parameter.id}`"
16+
:name="parameter.id"
17+
value=""
18+
v-model="element.parameters[parameter.id]"
1919
/>
2020
{{ parameter.unselectLabel }}<br />
2121
</label>
@@ -51,6 +51,19 @@
5151
v-model="element.parameters[parameter.id]"
5252
/>
5353
</template>
54+
<template v-if="element.type.name === 'Nerd Font Glyph'">
55+
<ul class="nerd-font-glyph-suggestions">
56+
<li
57+
v-for="glyph in nerdFontGlyphSuggestions"
58+
:key="glyph.name"
59+
:class="{ selected: element.parameters.glyph === glyph.name }"
60+
>
61+
<button type="button" :title="glyph.name" @click="setTextParameter(parameter.id, glyph.name)">
62+
<i :class="`nf ${glyph.name}`"></i>
63+
</button>
64+
</li>
65+
</ul>
66+
</template>
5467
</label>
5568
</div>
5669
<div class="properties_color" v-if="element.type.visible">
@@ -152,6 +165,8 @@ import prompt from '@/lib/prompt';
152165
import { Color } from '@/lib/enum/color';
153166
import { PromptElement } from '@/lib/promptElement';
154167
import darkMode from '@/lib/darkMode';
168+
import { fuzzySearchNerdFontGlyphs, NerdFontGlyph } from '@/lib/enum/nerdfontglyph';
169+
import debounce from 'lodash.debounce';
155170
import EmptyState from '../base/EmptyState.vue';
156171
import ColorPicker from '../ui/ColorPicker.vue';
157172
import IconButton from '../ui/IconButton.vue';
@@ -180,6 +195,10 @@ export default defineComponent({
180195
* Setting any of the properties will modify this (and only this) element.
181196
*/
182197
element: prompt.refs().selectedElement,
198+
/**
199+
* Nerd Font glyph suggestions based on the current parameter input value.
200+
*/
201+
nerdFontGlyphSuggestions: [] as NerdFontGlyph[],
183202
};
184203
},
185204
computed: {
@@ -200,6 +219,17 @@ export default defineComponent({
200219
},
201220
},
202221
methods: {
222+
/**
223+
* Sets the value of a text parameter for the currently selected element.
224+
*
225+
* @param parameterId the ID of the parameter to set
226+
* @param value the value to set for the parameter
227+
*/
228+
setTextParameter(parameterId: string, value: string) {
229+
if (this.element && this.element.parameters) {
230+
this.element.parameters[parameterId] = value;
231+
}
232+
},
203233
/**
204234
* Sets the foreground color of the currently selected element.
205235
*
@@ -233,12 +263,38 @@ export default defineComponent({
233263
prompt.state().push(element);
234264
}
235265
},
266+
/**
267+
* Updates the list of Nerd Font glyph suggestions based on the provided name.
268+
*
269+
* @param name the name of the Nerd Font glyph to search for
270+
*/
271+
updateNerdFontGlyphSuggestions(name: string) {
272+
this.nerdFontGlyphSuggestions = fuzzySearchNerdFontGlyphs(name);
273+
},
274+
/**
275+
* Debounced version of `updateNerdFontGlyphSuggestions` to avoid excessive calls while typing.
276+
*/
277+
// eslint-disable-next-line @typescript-eslint/no-unused-vars
278+
updateNerdFontGlyphSuggestionsDebounced(name: string) {
279+
// This will be replaced in `created()`
280+
},
281+
},
282+
created() {
283+
this.updateNerdFontGlyphSuggestionsDebounced = debounce(this.updateNerdFontGlyphSuggestions, 50);
284+
},
285+
watch: {
286+
'element.parameters.glyph': function watchGlyphParameter(newVal: string) {
287+
if (this.element && this.element.type.name === 'Nerd Font Glyph') {
288+
this.updateNerdFontGlyphSuggestionsDebounced(newVal || '');
289+
}
290+
},
236291
},
237292
});
238293
</script>
239294

240295
<style lang="sass" scoped>
241296
@import "@/assets/sass/_variables.sass"
297+
@import "https://www.nerdfonts.com/assets/css/webfont.css"
242298
243299
.properties-wrapper
244300
text-align: left
@@ -278,6 +334,7 @@ input[type="text"]
278334
width: 20em
279335
padding: 0.2em 0.4em
280336
margin-top: 0.2em
337+
font-family: 'NerdFontsSymbols Nerd Font', monospace
281338
282339
input.color-picker-btn
283340
vertical-align: middle
@@ -290,4 +347,27 @@ input.color-picker-btn
290347
291348
input[disabled]
292349
opacity: 0.7
350+
351+
.nerd-font-glyph-suggestions
352+
list-style: none
353+
padding: 0
354+
margin: 1em 0 0
355+
356+
li
357+
display: inline-block
358+
margin: 0.1em
359+
360+
&.selected
361+
color: $color-accent
362+
363+
button
364+
font-size: 1.5em
365+
padding: 0.2em
366+
background: none
367+
border: none
368+
color: inherit
369+
cursor: pointer
370+
371+
i
372+
vertical-align: middle
293373
</style>

0 commit comments

Comments
 (0)