@@ -3,6 +3,7 @@ import { ANSI } from './enum/ansi';
3
3
import { PromptElement } from './promptElement' ;
4
4
import { PropertiesState , defaultPropertiesState } from './promptElementProperties' ;
5
5
import { COLORS } from './enum/color' ;
6
+ import { findNerdFontGlyphByCode } from './enum/nerdfontglyph' ;
6
7
7
8
/**
8
9
* Thrown when the prompt parser encounters an error.
@@ -370,6 +371,9 @@ export function parsePrompt(ps1: string, promptCommand: string): PromptElement[]
370
371
let operatingSystemCommand : boolean = false ;
371
372
372
373
while ( cursor < ps1 . length ) {
374
+ // we need to segment graphemes to handle Nerd Font glyphs consisting of multiple code units correctly
375
+ const grapheme = new Intl . Segmenter ( ) . segment ( ps1 . slice ( cursor ) ) [ Symbol . iterator ] ( ) . next ( ) . value ?. segment ?? '' ;
376
+
373
377
// unparameterized elements are the most common, so we check them first
374
378
const unparameterizedElement = readUnparameterized ( ps1 , cursor ) ;
375
379
if ( unparameterizedElement !== null ) {
@@ -507,6 +511,14 @@ export function parsePrompt(ps1: string, promptCommand: string): PromptElement[]
507
511
508
512
elements . push ( applyState ( element , propertiesState ) ) ;
509
513
}
514
+ // manual handling of Nerd Font glyphs
515
+ else if ( findNerdFontGlyphByCode ( grapheme . codePointAt ( 0 ) ?? 0 ) !== undefined ) {
516
+ const glyph = findNerdFontGlyphByCode ( grapheme . codePointAt ( 0 ) ?? 0 ) ! ;
517
+ const element = new PromptElement ( getPromptElementTypeByNameUnsafe ( 'Nerd Font Glyph' ) ) ;
518
+ element . parameters . glyph = glyph . name ;
519
+ elements . push ( applyState ( element , propertiesState ) ) ;
520
+ cursor += grapheme . length ;
521
+ }
510
522
// manual handling of custom text element (fallback)
511
523
else {
512
524
// we create text elements with single characters only because the next char might be a special character
0 commit comments