Skip to content

Commit ed3dca0

Browse files
authored
Merge pull request microsoft#154513 from microsoft/tyriar/152645
Don't write initialText new line when echo is false
2 parents 62cd4c5 + 1eb2480 commit ed3dca0

File tree

4 files changed

+39
-13
lines changed

4 files changed

+39
-13
lines changed

src/vs/platform/terminal/common/terminal.ts

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -443,11 +443,11 @@ export interface IShellLaunchConfig {
443443

444444
/**
445445
* A string including ANSI escape sequences that will be written to the terminal emulator
446-
* _before_ the terminal process has launched, a trailing \n is added at the end of the string.
447-
* This allows for example the terminal instance to display a styled message as the first line
448-
* of the terminal. Use \x1b over \033 or \e for the escape control character.
446+
* _before_ the terminal process has launched, when a string is specified, a trailing \n is
447+
* added at the end. This allows for example the terminal instance to display a styled message
448+
* as the first line of the terminal. Use \x1b over \033 or \e for the escape control character.
449449
*/
450-
initialText?: string;
450+
initialText?: string | { text: string; trailingNewLine: boolean };
451451

452452
/**
453453
* Custom PTY/pseudoterminal process to use.

src/vs/platform/terminal/node/ptyService.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ export class PtyService extends Disposable implements IPtyService {
190190
executableEnv,
191191
options
192192
};
193-
const persistentProcess = new PersistentTerminalProcess(id, process, workspaceId, workspaceName, shouldPersist, cols, rows, processLaunchOptions, unicodeVersion, this._reconnectConstants, this._logService, isReviving ? shellLaunchConfig.initialText : undefined, rawReviveBuffer, shellLaunchConfig.icon, shellLaunchConfig.color, shellLaunchConfig.name, shellLaunchConfig.fixedDimensions);
193+
const persistentProcess = new PersistentTerminalProcess(id, process, workspaceId, workspaceName, shouldPersist, cols, rows, processLaunchOptions, unicodeVersion, this._reconnectConstants, this._logService, isReviving && typeof shellLaunchConfig.initialText === 'string' ? shellLaunchConfig.initialText : undefined, rawReviveBuffer, shellLaunchConfig.icon, shellLaunchConfig.color, shellLaunchConfig.name, shellLaunchConfig.fixedDimensions);
194194
process.onDidChangeProperty(property => this._onDidChangeProperty.fire({ id, property }));
195195
process.onProcessExit(event => {
196196
persistentProcess.dispose();

src/vs/workbench/contrib/tasks/browser/terminalTaskSystem.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1157,7 +1157,10 @@ export class TerminalTaskSystem extends Disposable implements ITaskSystem {
11571157
}, 'Executing task: {0}', commandLine), { excludeLeadingNewLine: true }) + this.taskShellIntegrationOutputSequence;
11581158
}
11591159
} else {
1160-
shellLaunchConfig.initialText = this.taskShellIntegrationStartSequence + this.taskShellIntegrationOutputSequence;
1160+
shellLaunchConfig.initialText = {
1161+
text: this.taskShellIntegrationStartSequence + this.taskShellIntegrationOutputSequence,
1162+
trailingNewLine: false
1163+
};
11611164
}
11621165
} else {
11631166
const commandExecutable = (task.command.runtime !== RuntimeType.CustomExecution) ? CommandString.value(command) : undefined;
@@ -1197,7 +1200,10 @@ export class TerminalTaskSystem extends Disposable implements ITaskSystem {
11971200
}, 'Executing task: {0}', `${shellLaunchConfig.executable} ${getArgsToEcho(shellLaunchConfig.args)}`), { excludeLeadingNewLine: true }) + this.taskShellIntegrationOutputSequence;
11981201
}
11991202
} else {
1200-
shellLaunchConfig.initialText = this.taskShellIntegrationStartSequence + this.taskShellIntegrationOutputSequence;
1203+
shellLaunchConfig.initialText = {
1204+
text: this.taskShellIntegrationStartSequence + this.taskShellIntegrationOutputSequence,
1205+
trailingNewLine: false
1206+
};
12011207
}
12021208
}
12031209

src/vs/workbench/contrib/terminal/browser/terminalInstance.ts

Lines changed: 26 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -698,7 +698,7 @@ export class TerminalInstance extends Disposable implements ITerminalInstance {
698698
// Write initial text, deferring onLineFeed listener when applicable to avoid firing
699699
// onLineData events containing initialText
700700
if (this._shellLaunchConfig.initialText) {
701-
this.xterm.raw.writeln(this._shellLaunchConfig.initialText, () => {
701+
this._writeInitialText(this.xterm, () => {
702702
lineDataEventAddon.onLineData(e => this._onLineData.fire(e));
703703
});
704704
} else {
@@ -1821,29 +1821,49 @@ export class TerminalInstance extends Disposable implements ITerminalInstance {
18211821
}
18221822
}
18231823

1824+
private _writeInitialText(xterm: XtermTerminal, callback?: () => void): void {
1825+
if (!this._shellLaunchConfig.initialText) {
1826+
callback?.();
1827+
return;
1828+
}
1829+
const text = typeof this._shellLaunchConfig.initialText === 'string'
1830+
? this._shellLaunchConfig.initialText
1831+
: this._shellLaunchConfig.initialText?.text;
1832+
if (typeof this._shellLaunchConfig.initialText === 'string') {
1833+
xterm.raw.writeln(text, callback);
1834+
} else {
1835+
if (this._shellLaunchConfig.initialText.trailingNewLine) {
1836+
xterm.raw.writeln(text, callback);
1837+
} else {
1838+
xterm.raw.write(text, callback);
1839+
}
1840+
}
1841+
}
1842+
18241843
async reuseTerminal(shell: IShellLaunchConfig, reset: boolean = false): Promise<void> {
18251844
// Unsubscribe any key listener we may have.
18261845
this._pressAnyKeyToCloseListener?.dispose();
18271846
this._pressAnyKeyToCloseListener = undefined;
18281847

1829-
if (this.xterm) {
1848+
const xterm = this.xterm;
1849+
if (xterm) {
18301850
if (!reset) {
18311851
// Ensure new processes' output starts at start of new line
1832-
await new Promise<void>(r => this.xterm!.raw.write('\n\x1b[G', r));
1852+
await new Promise<void>(r => xterm.raw.write('\n\x1b[G', r));
18331853
}
18341854

18351855
// Print initialText if specified
18361856
if (shell.initialText) {
1837-
await new Promise<void>(r => this.xterm!.raw.writeln(shell.initialText!, r));
1857+
await new Promise<void>(r => this._writeInitialText(xterm, r));
18381858
}
18391859

18401860
// Clean up waitOnExit state
18411861
if (this._isExiting && this._shellLaunchConfig.waitOnExit) {
1842-
this.xterm.raw.options.disableStdin = false;
1862+
xterm.raw.options.disableStdin = false;
18431863
this._isExiting = false;
18441864
}
18451865
if (reset) {
1846-
this.xterm.clearDecorations();
1866+
xterm.clearDecorations();
18471867
}
18481868
}
18491869

0 commit comments

Comments
 (0)