import { Event } from "../../../../base/common/event.js"; import { Disposable } from "../../../../base/common/lifecycle.js"; import type { ITerminalCommand } from "../../../../platform/terminal/common/capabilities/capabilities.js"; import { type IChatTerminalOutputPosition, type IDetachedTerminalInstance } from "./terminal.js"; import { ITerminalService } from "./terminal.service.js"; import { XtermTerminal } from "@codingame/monaco-vscode-xterm-addons-common/vscode/vs/workbench/contrib/terminal/browser/xterm/xtermTerminal"; import { IContextKeyService } from "../../../../platform/contextkey/common/contextkey.service.js"; import type { IChatTerminalToolInvocationData } from "../../chat/common/chatService/chatService.js"; import type { ITerminalFont } from "../common/terminal.js"; /** * Computes the maximum column width of content in a terminal buffer. * Iterates through each line and finds the rightmost non-empty cell. * * @param buffer The buffer to measure * @param cols The terminal column count (used to clamp line length) * @returns The maximum column width (number of columns used), or 0 if all lines are empty */ export declare function computeMaxBufferColumnWidth(buffer: { readonly length: number; getLine(y: number): { readonly length: number; getCell(x: number): { getChars(): string; } | undefined; } | undefined; }, cols: number): number; /** * Checks if two VT strings match around a boundary where we would slice. * This is an efficient O(1) check that verifies a small window of characters * before the slice point to detect if the VT sequences have diverged (common on Windows). * * @param newVT The new VT text to compare. * @param oldVT The old VT text to compare against. * @param slicePoint The point where we would slice. Must be <= both string lengths. * @param windowSize The number of characters before slicePoint to check (default 50). * @returns True if the boundary matches, false if VT sequences have diverged. */ export declare function vtBoundaryMatches(newVT: string, oldVT: string, slicePoint: number, windowSize?: number): boolean; export interface IDetachedTerminalCommandMirrorRenderResult { lineCount?: number; maxColumnWidth?: number; } interface IDetachedTerminalCommandMirror { attach(container: HTMLElement): Promise; renderCommand(): Promise; layout(widthPx: number, reflow?: boolean): Promise; getRowHeightPx(): number | undefined; onDidUpdate: Event; onDidInput: Event; onDidChangeRowHeight: Event; } /** * Computes the number of columns a chat terminal mirror should use to fill the available width * of its container, using the same cell math as {@link getXtermScaledDimensions}. * * @param availableWidthPx The container width in CSS pixels. * @param font The terminal font with measured char metrics. * @param devicePixelRatio The window's device pixel ratio. * @param horizontalChromePx Horizontal space the DOM chrome takes from the container width, * measured from computed styles when available; defaults to the static estimate. * @returns The column count, or the default fallback when the width or font is unmeasurable. */ export declare function computeChatTerminalMirrorCols(availableWidthPx: number, font: ITerminalFont, devicePixelRatio: number, horizontalChromePx?: number): number; /** * Enables cursor line reflow on a mirror's terminal. The mirror is a readonly output preview * with no prompt line to protect, so resize reflow should re-wrap the cursor line like any * other line (xterm skips it by default). */ export declare function enableCursorLineReflow(detached: IDetachedTerminalInstance): void; /** * Computes the number of rendered rows occupied by a terminal snapshot. * The cursor line is included when it contains content and excluded when it * is the empty line after a trailing newline. */ export declare function computeSnapshotLineCount(buffer: { readonly baseY: number; readonly cursorY: number; getLine(y: number): { translateToString(trimRight?: boolean): string; } | undefined; }, lineCount?: number): number; export declare function getCommandOutputSnapshot(xtermTerminal: XtermTerminal, command: ITerminalCommand, log?: (reason: "fallback" | "primary", error: unknown) => void): Promise<{ text: string; 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. */ export declare class DetachedTerminalCommandMirror extends Disposable implements IDetachedTerminalCommandMirror { private readonly _xtermTerminal; private readonly _command; private readonly _terminalService; private readonly _contextKeyService; private _detachedTerminal; private _detachedTerminalPromise; private _attachedContainer; private readonly _streamingDisposables; private readonly _onDidUpdateEmitter; readonly onDidUpdate: Event; private readonly _onDidInputEmitter; readonly onDidInput: Event; private readonly _onDidChangeRowHeightEmitter; readonly onDidChangeRowHeight: Event; private _renderListenerInstalled; private _lastObservedRowHeight; private _lastVT; private _lineCount; private _maxColumnWidth; private _lastUpToDateCursorY; private _lowestDirtyCursorY; private _flushPromise; private _dirtyScheduled; private _isStreaming; private _sourceRaw; constructor(_xtermTerminal: XtermTerminal, _command: ITerminalCommand, _terminalService: ITerminalService, _contextKeyService: IContextKeyService); attach(container: HTMLElement): Promise; /** * The height in CSS pixels of one rendered row of this mirror, or undefined until the * detached terminal exists. Reflects the renderer's actual cell metrics once it has * rendered, so box-height math matches what xterm paints. */ getRowHeightPx(): number | undefined; private _installFirstRenderListener; private _notifyRowHeightIfChanged; renderCommand(): Promise; /** * Resizes the mirror to fill the given width, relying on xterm's native resize reflow to * re-wrap soft-wrapped lines. No-op when the resulting cols are unchanged. The column * count derives from the mirror's own xterm font metrics, which reflect the actual * renderer cell size rather than a configuration-based estimate. When reflow is disabled, * the mirror uses the source terminal's cols instead of filling the width. */ layout(widthPx: number, reflow?: boolean): Promise; private _getCommandOutputAsVT; private _getRenderedLineCount; private _computeMaxColumnWidth; private _getOrCreateTerminal; private _startStreaming; private _stopStreaming; private _handleCursorEvent; private _scheduleFlush; private _flushDirtyRange; private _doFlushDirtyRange; private _getAbsoluteCursorY; /** * Checks if the new VT text matches the old VT around the boundary where we would slice. */ private _vtBoundaryMatches; } /** * Mirrors a terminal output snapshot into a detached terminal instance. * Used when the terminal has been disposed of but we still want to show the output. */ export declare class DetachedTerminalSnapshotMirror extends Disposable { private readonly _getTheme; private readonly _terminalService; private readonly _contextKeyService; private _detachedTerminal; private _resolvedTerminal; private _attachedContainer; private _output; private _outputPosition; private _container; private readonly _renderSequencer; private _outputVersion; private _renderedVersion; private _lastRenderedLineCount; private _lastRenderedMaxColumnWidth; private _lastRenderedText; private _lastRenderedPosition; /** Where in the stream the terminal's content starts, which precedes the retained output once the stream drops output the terminal still shows. */ private _renderedStart; private readonly _onDidChangeRowHeightEmitter; readonly onDidChangeRowHeight: Event; private _renderListenerInstalled; private _lastObservedRowHeight; /** * @param scrollback The rows of scrollback to keep, or `undefined` for the * `terminal.integrated.scrollback` setting. */ constructor(output: IChatTerminalToolInvocationData["terminalCommandOutput"] | undefined, _getTheme: () => IChatTerminalToolInvocationData["terminalTheme"] | undefined, scrollback: number | undefined, _terminalService: ITerminalService, _contextKeyService: IContextKeyService); /** * The height in CSS pixels of one rendered row of this mirror, or undefined until the * detached terminal exists. Reflects the renderer's actual cell metrics once it has * rendered, so box-height math matches what xterm paints. */ getRowHeightPx(): number | undefined; private _getTerminal; /** * @param position Where `output` sits in a stream that drops its oldest output, so a render * writes only what was appended since the last one. */ setOutput(output: IChatTerminalToolInvocationData["terminalCommandOutput"] | undefined, position?: IChatTerminalOutputPosition): void; attach(container: HTMLElement): Promise; render(): Promise<{ lineCount?: number; maxColumnWidth?: number; } | undefined>; /** * Resizes the mirror to fill the given width, relying on xterm's native resize reflow to * re-wrap soft-wrapped lines. No-op when the resulting cols are unchanged. The column * count derives from the mirror's own xterm font metrics, which reflect the actual * renderer cell size rather than a configuration-based estimate. When reflow is disabled, * the mirror uses its initial fallback cols instead of filling the width. */ layout(widthPx: number, reflow?: boolean): Promise<{ lineCount?: number; maxColumnWidth?: number; } | undefined>; private _render; /** Returns the part of `text` appended since the last render, or `undefined` when the output was replaced and must be rewritten. */ private _getAppendedText; /** * Returns what this mirror can scroll back through, followed by anything `text` appended since the last render, * when the mirror still shows output that its stream has dropped from `text`. Otherwise returns `undefined`, * since `text` holds everything the mirror shows. */ getScrollbackText(text: string, position: IChatTerminalOutputPosition): string | undefined; private _computeMaxColumnWidth; private _shouldComputeMaxColumnWidth; private _applyTheme; } export {};