9
9
<div class =" ps1" :class =" { dark: darkMode }" >
10
10
<span >{{ ps1 }}</span >
11
11
</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 >
12
17
<div class =" hint" v-if =" hasElement('Advanced Git Prompt')" >
13
18
The <code >Advanced Git Prompt</code > element requires some extra work: Copy the
14
19
<a
@@ -179,13 +184,24 @@ function generatePS1(elements: PromptElement[]): string {
179
184
// the initial state of the properties is that all colors and attributes are not set
180
185
// this might actually be false if any escape codes are printed before the prompt but we ignore that
181
186
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 ;
182
189
183
190
const commands: string [] = [];
184
191
const outputElements: string [] = [];
185
192
186
193
elements .forEach ((element ) => {
187
194
if (! element .type .visible ) {
188
195
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
+
189
205
// skip any handling of escape sequences for invisible elements as they are not affected by them
190
206
// for instance, if two elements with identical properties are separated by only invisible elements, we do not
191
207
// need to insert any reset escape codes in between them
@@ -209,15 +225,20 @@ function generatePS1(elements: PromptElement[]): string {
209
225
};
210
226
211
227
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
+
212
235
if (element .type .command ) {
213
236
const commandVariable = ` PS1_CMD${commands .length + 1 } ` ;
214
237
commands .push (` ${commandVariable }=$(${element .type .char (element .parameters )}) ` );
215
- outputElements .push (` ${ escapeCodes }$ \{ ${commandVariable }} ` );
238
+ outputElements .push (` $\{ ${commandVariable }} ` );
216
239
} else {
217
- outputElements .push (` ${escapeCodes }${ element .type .char (element .parameters )} ` );
240
+ outputElements .push (` ${element .type .char (element .parameters )} ` );
218
241
}
219
-
220
- propertiesState = newPropertiesState ;
221
242
});
222
243
223
244
// reset all attributes at the end if there are any set
0 commit comments