Skip to content

Commit 11014ec

Browse files
committed
Status bar item for prompt, look below cursor line
1 parent 7bad7aa commit 11014ec

File tree

3 files changed

+53
-2
lines changed

3 files changed

+53
-2
lines changed

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55

66
import { Event } from 'vs/base/common/event';
77
import { IDisposable } from 'vs/base/common/lifecycle';
8+
import type { IPromptInputModel } from 'vs/platform/terminal/common/capabilities/commandDetection/promptInputModel';
89
import { ICurrentPartialCommand } from 'vs/platform/terminal/common/capabilities/commandDetection/terminalCommand';
910
import { ITerminalOutputMatch, ITerminalOutputMatcher } from 'vs/platform/terminal/common/terminal';
1011
import { ReplayEntry } from 'vs/platform/terminal/common/terminalProcess';
@@ -161,6 +162,7 @@ export interface IBufferMarkCapability {
161162

162163
export interface ICommandDetectionCapability {
163164
readonly type: TerminalCapability.CommandDetection;
165+
readonly promptInputModel: IPromptInputModel;
164166
readonly commands: readonly ITerminalCommand[];
165167
/** The command currently being executed, otherwise undefined. */
166168
readonly executingCommand: string | undefined;

src/vs/platform/terminal/common/capabilities/commandDetection/promptInputModel.ts

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,11 +130,23 @@ export class PromptInputModel extends Disposable implements IPromptInputModel {
130130
// TODO: Detect continuation
131131
// For pwsh: (Get-PSReadLineOption).ContinuationPrompt
132132
// TODO: Wide/emoji length support
133-
this._cursorIndex = Math.max(this._value.length - lineText.length + buffer.cursorX, 0);
133+
this._cursorIndex = Math.max(this._value.length - lineText.length - (this._continuationPrompt?.length ?? 0) + buffer.cursorX, 0);
134134
}
135135
}
136136
}
137137

138+
// TODO: Check below the cursor for continuations
139+
for (let y = absoluteCursorY + 1; y < buffer.baseY + this._xterm.rows; y++) {
140+
let lineText = buffer.getLine(y)?.translateToString(true);
141+
if (lineText) {
142+
// TODO: Detect line continuation if it's not set
143+
if (this._continuationPrompt && lineText.startsWith(this._continuationPrompt)) {
144+
lineText = lineText.substring(this._continuationPrompt.length);
145+
}
146+
this._value += `\n${lineText}`;
147+
}
148+
}
149+
138150
if (this._logService.getLevel() === LogLevel.Trace) {
139151
this._logService.trace(`PromptInputModel#_sync: Input="${this._value.substring(0, this._cursorIndex)}|${this.value.substring(this._cursorIndex)}"`);
140152
}

src/vs/workbench/contrib/terminalContrib/developer/browser/terminal.developer.contribution.ts

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ import { TerminalContextKeys } from 'vs/workbench/contrib/terminal/common/termin
2525
import type { Terminal } from '@xterm/xterm';
2626
import { ITerminalCommand, TerminalCapability } from 'vs/platform/terminal/common/capabilities/capabilities';
2727
import { getWindow } from 'vs/base/browser/dom';
28+
import { IStatusbarService, StatusbarAlignment, type IStatusbarEntry, type IStatusbarEntryAccessor } from 'vs/workbench/services/statusbar/browser/statusbar';
2829

2930
registerTerminalAction({
3031
id: TerminalCommandId.ShowTextureAtlas,
@@ -121,19 +122,36 @@ class DevModeContribution extends Disposable implements ITerminalContribution {
121122
private readonly _activeDevModeDisposables = new MutableDisposable();
122123
private _currentColor = 0;
123124

125+
private _statusbarEntry: IStatusbarEntry | undefined;
126+
private _statusbarEntryAccessor: IStatusbarEntryAccessor | undefined;
127+
124128
constructor(
125129
private readonly _instance: ITerminalInstance,
126130
processManager: ITerminalProcessManager,
127131
widgetManager: TerminalWidgetManager,
128132
@IConfigurationService private readonly _configurationService: IConfigurationService,
129133
@ITerminalConfigurationService private readonly _terminalConfigurationService: ITerminalConfigurationService,
134+
@IStatusbarService private readonly _statusbarService: IStatusbarService,
130135
) {
131136
super();
132137
this._register(this._configurationService.onDidChangeConfiguration(e => {
133138
if (e.affectsConfiguration(TerminalSettingId.DevMode)) {
134139
this._updateDevMode();
135140
}
136141
}));
142+
143+
setTimeout(() => {
144+
const commandDetection = this._instance.capabilities.get(TerminalCapability.CommandDetection)
145+
if (commandDetection) {
146+
// TODO: Listen to capability add
147+
// TODO: Add util for when capability is available?
148+
commandDetection.promptInputModel.onDidChangeInput(() => {
149+
// TODO: Create a status bar item sync
150+
// TODO: Only show focused instance status bar item
151+
this._updateDevMode();
152+
});
153+
}
154+
}, 2000);
137155
}
138156

139157
xtermReady(xterm: IXtermTerminal & { raw: Terminal }): void {
@@ -145,7 +163,26 @@ class DevModeContribution extends Disposable implements ITerminalContribution {
145163
const devMode: boolean = this._isEnabled();
146164
this._xterm?.raw.element?.classList.toggle('dev-mode', devMode);
147165

148-
// Text area syncing
166+
const promptInputModel = this._instance.capabilities.get(TerminalCapability.CommandDetection)?.promptInputModel
167+
if (promptInputModel) {
168+
// Text area syncing
169+
const promptInput = promptInputModel.value.replaceAll('\n', '\u23CE');
170+
this._statusbarEntry = {
171+
name: localize('terminalDevMode', 'Terminal Dev Mode'),
172+
text: `$(terminal) ${promptInput.substring(0, promptInputModel.cursorIndex)}|${promptInput.substring(promptInputModel.cursorIndex)}`,
173+
// tooltip: localize('nonResponsivePtyHost', "The connection to the terminal's pty host process is unresponsive, terminals may stop working. Click to manually restart the pty host."),
174+
ariaLabel: localize('ptyHostStatus.ariaLabel', 'test'),
175+
// command: TerminalCommandId.RestartPtyHost,
176+
kind: 'warning'
177+
};
178+
if (!this._statusbarEntryAccessor) {
179+
console.log('1');
180+
this._statusbarEntryAccessor = this._statusbarService.addEntry(this._statusbarEntry, 'terminal.promptInput', StatusbarAlignment.LEFT);
181+
} else {
182+
console.log('2');
183+
this._statusbarEntryAccessor.update(this._statusbarEntry);
184+
}
185+
}
149186
if (this._xterm?.raw.textarea) {
150187
const font = this._terminalConfigurationService.getFont(getWindow(this._xterm.raw.textarea));
151188
this._xterm.raw.textarea.style.fontFamily = font.fontFamily;

0 commit comments

Comments
 (0)