@@ -3,6 +3,7 @@ import { ANSI } from './enum/ansi';
33import { PromptElement } from './promptElement' ;
44import { PropertiesState , defaultPropertiesState } from './promptElementProperties' ;
55import { COLORS } from './enum/color' ;
6+ import { findNerdFontGlyphByCode } from './enum/nerdfontglyph' ;
67
78/**
89 * Thrown when the prompt parser encounters an error.
@@ -370,6 +371,9 @@ export function parsePrompt(ps1: string, promptCommand: string): PromptElement[]
370371 let operatingSystemCommand : boolean = false ;
371372
372373 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+
373377 // unparameterized elements are the most common, so we check them first
374378 const unparameterizedElement = readUnparameterized ( ps1 , cursor ) ;
375379 if ( unparameterizedElement !== null ) {
@@ -507,6 +511,14 @@ export function parsePrompt(ps1: string, promptCommand: string): PromptElement[]
507511
508512 elements . push ( applyState ( element , propertiesState ) ) ;
509513 }
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+ }
510522 // manual handling of custom text element (fallback)
511523 else {
512524 // we create text elements with single characters only because the next char might be a special character
0 commit comments