-
Notifications
You must be signed in to change notification settings - Fork 37.2k
render xterm instead of html for the chat terminal output #278684
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
14e4eed
2e2448a
1e9135a
b3a58a2
130d862
6ec21ef
8bd0bac
d93fa22
ef9ea67
201015e
3a84c57
928d333
8beee67
11893d6
db19c94
0dcf9db
0d2609f
49c7df4
0a1d251
aaec56f
45b4b7c
536d3bd
e0ddb45
cf6f18a
1a6bd99
7c64b49
14292bd
88ae085
c373654
4dc64ce
16783b2
97c9a27
957415f
584733a
7b2d6e6
5c7565b
aa2f8d6
84bce02
149a652
013dd12
7328205
865f6db
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,97 @@ | ||
| /*--------------------------------------------------------------------------------------------- | ||
| * Copyright (c) Microsoft Corporation. All rights reserved. | ||
| * Licensed under the MIT License. See License.txt in the project root for license information. | ||
| *--------------------------------------------------------------------------------------------*/ | ||
|
|
||
| import { Disposable } from '../../../../base/common/lifecycle.js'; | ||
| import type { ITerminalCommand } from '../../../../platform/terminal/common/capabilities/capabilities.js'; | ||
| import { ITerminalService, type IDetachedTerminalInstance } from './terminal.js'; | ||
| import { DetachedProcessInfo } from './detachedTerminal.js'; | ||
| import { XtermTerminal } from './xterm/xtermTerminal.js'; | ||
| import { TERMINAL_BACKGROUND_COLOR } from '../common/terminalColorRegistry.js'; | ||
| import { PANEL_BACKGROUND } from '../../../common/theme.js'; | ||
|
|
||
| interface IDetachedTerminalCommandMirror { | ||
| attach(container: HTMLElement): Promise<void>; | ||
| renderCommand(): Promise<{ lineCount?: number } | undefined>; | ||
| } | ||
|
|
||
| /** | ||
| * Mirrors a terminal command's output into a detached terminal instance. | ||
| * Used in the chat terminal tool progress part to show command output for example. | ||
| */ | ||
| export class DetachedTerminalCommandMirror extends Disposable implements IDetachedTerminalCommandMirror { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We want some unit tests for this, they'll be a lot more important in the next PR though. Basically they should write stuff to |
||
| private _detachedTerminal: Promise<IDetachedTerminalInstance>; | ||
| private _attachedContainer?: HTMLElement; | ||
|
|
||
| constructor( | ||
| private readonly _xtermTerminal: XtermTerminal, | ||
| private readonly _command: ITerminalCommand, | ||
| @ITerminalService private readonly _terminalService: ITerminalService, | ||
| ) { | ||
| super(); | ||
| this._detachedTerminal = this._createTerminal(); | ||
| } | ||
|
|
||
| async attach(container: HTMLElement): Promise<void> { | ||
meganrogge marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| const terminal = await this._detachedTerminal; | ||
| if (this._attachedContainer !== container) { | ||
| container.classList.add('chat-terminal-output-terminal'); | ||
| terminal.attachToElement(container); | ||
| this._attachedContainer = container; | ||
| } | ||
| } | ||
|
|
||
| async renderCommand(): Promise<{ lineCount?: number } | undefined> { | ||
| const vt = await this._getCommandOutputAsVT(); | ||
| if (!vt) { | ||
| return undefined; | ||
| } | ||
| if (!vt.text) { | ||
| return { lineCount: 0 }; | ||
| } | ||
| const detached = await this._detachedTerminal; | ||
| detached.xterm.write(vt.text); | ||
| return { lineCount: vt.lineCount }; | ||
| } | ||
|
|
||
| private async _getCommandOutputAsVT(): Promise<{ text: string; lineCount: number } | undefined> { | ||
| const executedMarker = this._command.executedMarker; | ||
| const endMarker = this._command.endMarker; | ||
| if (!executedMarker || executedMarker.isDisposed || !endMarker || endMarker.isDisposed) { | ||
| return undefined; | ||
| } | ||
|
|
||
| const startLine = executedMarker.line; | ||
| const endLine = endMarker.line - 1; | ||
| const lineCount = Math.max(endLine - startLine + 1, 0); | ||
|
|
||
| const text = await this._xtermTerminal.getRangeAsVT(executedMarker, endMarker, true); | ||
| if (!text) { | ||
| return { text: '', lineCount: 0 }; | ||
| } | ||
|
|
||
| return { text, lineCount }; | ||
| } | ||
|
|
||
| private async _createTerminal(): Promise<IDetachedTerminalInstance> { | ||
| const detached = await this._terminalService.createDetachedTerminal({ | ||
| cols: this._xtermTerminal.raw!.cols, | ||
| rows: 10, | ||
meganrogge marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| readonly: true, | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We'll want this to forward data events when the content is streamed. |
||
| processInfo: new DetachedProcessInfo({ initialCwd: '' }), | ||
meganrogge marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| disableOverviewRuler: true, | ||
| colorProvider: { | ||
| getBackgroundColor: theme => { | ||
| const terminalBackground = theme.getColor(TERMINAL_BACKGROUND_COLOR); | ||
| if (terminalBackground) { | ||
| return terminalBackground; | ||
| } | ||
| return theme.getColor(PANEL_BACKGROUND); | ||
| }, | ||
| } | ||
| }); | ||
| return this._register(detached); | ||
| } | ||
meganrogge marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| } | ||
Uh oh!
There was an error while loading. Please reload this page.