99 <div class =" ps1" :class =" { dark: darkMode }" >
1010 <span >{{ ps1 }}</span >
1111 </div >
12+ <div class =" hint" v-if =" hasElement('Set Window Title')" >
13+ Elements between the <code >Set Window Title</code > and the next <code >Bell</code > element are used to modify the
14+ window title of the terminal, if supported.
15+ Any styling properties of those elements are ignored.
16+ </div >
1217 <div class =" hint" v-if =" hasElement('Advanced Git Prompt')" >
1318 The <code >Advanced Git Prompt</code > element requires some extra work: Copy the
1419 <a
@@ -179,13 +184,24 @@ function generatePS1(elements: PromptElement[]): string {
179184 // the initial state of the properties is that all colors and attributes are not set
180185 // this might actually be false if any escape codes are printed before the prompt but we ignore that
181186 let propertiesState: PropertiesState = defaultPropertiesState ();
187+ // whether an operating system command ('Set Window Title') has been encountered and awaits an ending bell
188+ let operatingSystemCommand: boolean = false ;
182189
183190 const commands: string [] = [];
184191 const outputElements: string [] = [];
185192
186193 elements .forEach ((element ) => {
187194 if (! element .type .visible ) {
188195 outputElements .push (element .type .char (element .parameters ));
196+
197+ if (element .type .name === ' Set Window Title' ) {
198+ operatingSystemCommand = true ;
199+ } else if (element .type .name === ' Bell' && operatingSystemCommand ) {
200+ operatingSystemCommand = false ;
201+ // end of non-printable operating system command
202+ outputElements .push (' \\ ]' );
203+ }
204+
189205 // skip any handling of escape sequences for invisible elements as they are not affected by them
190206 // for instance, if two elements with identical properties are separated by only invisible elements, we do not
191207 // need to insert any reset escape codes in between them
@@ -209,15 +225,20 @@ function generatePS1(elements: PromptElement[]): string {
209225 };
210226
211227 const escapeCodes = generateEscapeCodes (propertiesState , newPropertiesState );
228+
229+ // ignore escape codes within operating system commands
230+ if (! operatingSystemCommand ) {
231+ outputElements .push (escapeCodes );
232+ propertiesState = newPropertiesState ;
233+ }
234+
212235 if (element .type .command ) {
213236 const commandVariable = ` PS1_CMD${commands .length + 1 } ` ;
214237 commands .push (` ${commandVariable }=$(${element .type .char (element .parameters )}) ` );
215- outputElements .push (` ${ escapeCodes }$ \{ ${commandVariable }} ` );
238+ outputElements .push (` $\{ ${commandVariable }} ` );
216239 } else {
217- outputElements .push (` ${escapeCodes }${ element .type .char (element .parameters )} ` );
240+ outputElements .push (` ${element .type .char (element .parameters )} ` );
218241 }
219-
220- propertiesState = newPropertiesState ;
221242 });
222243
223244 // reset all attributes at the end if there are any set
0 commit comments