From cd3dcc52b26a8b3d18f5756e2fc683ba6cf28a99 Mon Sep 17 00:00:00 2001 From: Daniel Imms <2193314+Tyriar@users.noreply.github.com> Date: Sun, 31 May 2026 14:35:08 -0700 Subject: [PATCH] Colocate buffer types in buffer/Types.ts The import/no-cycle refactor had moved IBuffer, IBufferSet, and related cell/line types into src/common/Types.ts, with buffer/Types.ts only re-exporting them. That inverted the natural module boundary and made buffer code depend on the top-level types hub. Define buffer-owned types in buffer/Types.ts instead: - CharData, IExtendedAttrs, IAttributeData, ICellData, IBufferLine - IMarker, IBuffer, IBufferSet, BufferIndex Restore UnderlineStyle to buffer/Constants.ts (used by IExtendedAttrs) and remove those definitions from Types.ts. buffer/Types.ts imports only what it needs from outside the buffer layer: ICircularList and ICharset from Types, IDisposable from Lifecycle, IEvent from Event, and UnderlineStyle from Constants. Types.ts does not import buffer/Types.ts, so the previous Types <-> buffer cycle stays broken. Update imports across common, browser, headless, addons, and tests to use common/buffer/Types for buffer types rather than common/Types. Co-authored-by: Cursor --- addons/addon-image/src/Types.ts | 3 +- addons/addon-serialize/src/SerializeAddon.ts | 3 +- addons/addon-webgl/src/CellColorResolver.ts | 2 +- addons/addon-webgl/src/WebglRenderer.ts | 2 +- src/browser/OscLinkProvider.test.ts | 3 +- src/browser/OscLinkProvider.ts | 2 +- src/browser/Terminal.test.ts | 2 +- src/browser/TestUtils.test.ts | 4 +- src/browser/Types.ts | 4 +- .../dom/DomRendererRowFactory.test.ts | 2 +- .../renderer/dom/DomRendererRowFactory.ts | 3 +- .../services/CharacterJoinerService.test.ts | 2 +- .../services/CharacterJoinerService.ts | 2 +- src/browser/services/SelectionService.test.ts | 3 +- src/browser/services/SelectionService.ts | 4 +- src/common/CoreTerminal.ts | 4 +- src/common/InputHandler.test.ts | 3 +- src/common/InputHandler.ts | 4 +- src/common/TestUtils.test.ts | 4 +- src/common/Types.ts | 198 ------------------ src/common/buffer/AttributeData.ts | 3 +- src/common/buffer/Buffer.ts | 4 +- src/common/buffer/BufferLine.test.ts | 2 +- src/common/buffer/BufferLine.ts | 2 +- src/common/buffer/BufferReflow.ts | 2 +- src/common/buffer/BufferSet.ts | 3 +- src/common/buffer/CellData.ts | 2 +- src/common/buffer/Constants.ts | 9 +- src/common/buffer/Marker.ts | 4 +- src/common/buffer/Types.ts | 194 ++++++++++++++++- src/common/public/BufferLineApiView.ts | 2 +- src/common/services/BufferService.ts | 3 +- src/common/services/DecorationService.test.ts | 2 +- src/common/services/OscLinkService.ts | 3 +- src/common/services/Services.ts | 4 +- src/headless/Terminal.ts | 4 +- test/playwright/TestUtils.ts | 3 +- 37 files changed, 253 insertions(+), 247 deletions(-) diff --git a/addons/addon-image/src/Types.ts b/addons/addon-image/src/Types.ts index 19a1acca1..53d357a97 100644 --- a/addons/addon-image/src/Types.ts +++ b/addons/addon-image/src/Types.ts @@ -9,7 +9,8 @@ import { IDisposable, IMarker, Terminal } from '@xterm/xterm'; import { Attributes, BgFlags, Content, ExtFlags, UnderlineStyle } from 'common/buffer/Constants'; import type { AttributeData } from 'common/buffer/AttributeData'; import type { IParams, IDcsHandler, IOscHandler, IApcHandler, IEscapeSequenceParser } from 'common/parser/Types'; -import type { IBufferLine, IExtendedAttrs, IInputHandler } from 'common/Types'; +import type { IInputHandler } from 'common/Types'; +import type { IBufferLine, IExtendedAttrs } from 'common/buffer/Types'; import type { ITerminal, ReadonlyColorSet } from 'browser/Types'; import type { IRenderDimensions } from 'browser/renderer/shared/Types'; import type { ICoreBrowserService, IRenderService, IThemeService } from 'browser/services/Services'; diff --git a/addons/addon-serialize/src/SerializeAddon.ts b/addons/addon-serialize/src/SerializeAddon.ts index 4980c8eda..0aad8e1d6 100644 --- a/addons/addon-serialize/src/SerializeAddon.ts +++ b/addons/addon-serialize/src/SerializeAddon.ts @@ -7,7 +7,8 @@ import type { IBuffer, IBufferCell, IBufferRange, ITerminalAddon, Terminal } from '@xterm/xterm'; import type { IHTMLSerializeOptions, SerializeAddon as ISerializeApi, ISerializeOptions, ISerializeRange } from '@xterm/addon-serialize'; -import { IAttributeData, IColor } from 'common/Types'; +import { IColor } from 'common/Types'; +import { IAttributeData } from 'common/buffer/Types'; import { DEFAULT_ANSI_COLORS } from 'browser/Types'; import { UnderlineStyle } from 'common/buffer/Constants'; diff --git a/addons/addon-webgl/src/CellColorResolver.ts b/addons/addon-webgl/src/CellColorResolver.ts index 3a4661cc3..49fdf5b1b 100644 --- a/addons/addon-webgl/src/CellColorResolver.ts +++ b/addons/addon-webgl/src/CellColorResolver.ts @@ -3,7 +3,7 @@ import { ICoreBrowserService, IThemeService } from 'browser/services/Services'; import { ReadonlyColorSet } from 'browser/Types'; import { Attributes, BgFlags, ExtFlags, FgFlags, NULL_CELL_CODE, UnderlineStyle } from 'common/buffer/Constants'; import { IDecorationService, IOptionsService } from 'common/services/Services'; -import { ICellData } from 'common/Types'; +import { ICellData } from 'common/buffer/Types'; import { Terminal } from '@xterm/xterm'; import { rgba } from 'common/Color'; import { treatGlyphAsBackgroundColor } from 'browser/renderer/shared/RendererUtils'; diff --git a/addons/addon-webgl/src/WebglRenderer.ts b/addons/addon-webgl/src/WebglRenderer.ts index 9c2f459df..264bfda6e 100644 --- a/addons/addon-webgl/src/WebglRenderer.ts +++ b/addons/addon-webgl/src/WebglRenderer.ts @@ -10,7 +10,7 @@ import { CursorBlinkStateManager } from './CursorBlinkStateManager'; import { observeDevicePixelDimensions } from './DevicePixelObserver'; import { IRenderDimensions, IRenderer, IRequestRedrawEvent } from 'browser/renderer/shared/Types'; import { ICharSizeService, ICharacterJoinerService, ICoreBrowserService, IThemeService } from 'browser/services/Services'; -import { CharData, IBufferLine, ICellData } from 'common/Types'; +import { CharData, IBufferLine, ICellData } from 'common/buffer/Types'; import { AttributeData } from 'common/buffer/AttributeData'; import { CellData } from 'common/buffer/CellData'; import { Attributes, Content, FgFlags, NULL_CELL_CHAR, NULL_CELL_CODE } from 'common/buffer/Constants'; diff --git a/src/browser/OscLinkProvider.test.ts b/src/browser/OscLinkProvider.test.ts index 2693f9ddd..0356bcfdc 100644 --- a/src/browser/OscLinkProvider.test.ts +++ b/src/browser/OscLinkProvider.test.ts @@ -8,7 +8,8 @@ import { OscLinkProvider } from './OscLinkProvider'; import { ILink } from './Types'; import { createCellData, MockBufferService, MockOptionsService } from '../common/TestUtils.test'; import { IBufferService, IOscLinkService } from '../common/services/Services'; -import { IBufferLine, IOscLinkData } from '../common/Types'; +import { IOscLinkData } from '../common/Types'; +import { IBufferLine } from '../common/buffer/Types'; class TestOscLinkService implements IOscLinkService { public serviceBrand: any; diff --git a/src/browser/OscLinkProvider.ts b/src/browser/OscLinkProvider.ts index d52d68c08..9fdef1561 100644 --- a/src/browser/OscLinkProvider.ts +++ b/src/browser/OscLinkProvider.ts @@ -6,7 +6,7 @@ import { IBufferRange, ILink } from './Types'; import { ILinkProvider } from './services/Services'; import { CellData } from '../common/buffer/CellData'; -import { IBufferLine } from '../common/Types'; +import { IBufferLine } from '../common/buffer/Types'; import { IBufferService, IOptionsService, IOscLinkService } from '../common/services/Services'; export class OscLinkProvider implements ILinkProvider { diff --git a/src/browser/Terminal.test.ts b/src/browser/Terminal.test.ts index 38165b84f..a98ddf865 100644 --- a/src/browser/Terminal.test.ts +++ b/src/browser/Terminal.test.ts @@ -9,7 +9,7 @@ import { assert } from 'chai'; import { DEFAULT_ATTR_DATA } from '../common/buffer/BufferLine'; import { CellData } from '../common/buffer/CellData'; import { MockUnicodeService, createCellData } from '../common/TestUtils.test'; -import { IMarker } from '../common/Types'; +import { IMarker } from '../common/buffer/Types'; const INIT_COLS = 80; const INIT_ROWS = 24; diff --git a/src/browser/TestUtils.test.ts b/src/browser/TestUtils.test.ts index ee5423eea..d99c7244b 100644 --- a/src/browser/TestUtils.test.ts +++ b/src/browser/TestUtils.test.ts @@ -7,8 +7,8 @@ import { IDisposable, IMarker, ILinkProvider, IDecorationOptions, IDecoration, I import { ICharacterJoinerService, ICharSizeService, ICoreBrowserService, IMouseService, IRenderService, ISelectionService, IThemeService } from './services/Services'; import { IRenderDimensions, IRenderer, IRequestRedrawEvent } from './renderer/shared/Types'; import { IColorSet, ITerminal, ILinkifier2, IBrowser, IViewport, ICompositionHelper, CharacterJoinerHandler, IBufferRange, ReadonlyColorSet, IBufferElementProvider } from './Types'; -import { IBuffer, IBufferSet } from '../common/buffer/Types'; -import { IBufferLine, ICellData, IAttributeData, ICircularList, XtermListener, ICharset, ITerminalOptions, ColorIndex } from '../common/Types'; +import { IAttributeData, IBuffer, IBufferLine, IBufferSet, ICellData } from '../common/buffer/Types'; +import { ICircularList, XtermListener, ICharset, ITerminalOptions, ColorIndex } from '../common/Types'; import { Buffer } from '../common/buffer/Buffer'; import * as Browser from '../common/Platform'; import { CoreBrowserTerminal } from './CoreBrowserTerminal'; diff --git a/src/browser/Types.ts b/src/browser/Types.ts index 0c454c118..497afcf53 100644 --- a/src/browser/Types.ts +++ b/src/browser/Types.ts @@ -3,9 +3,9 @@ * @license MIT */ -import { CharData, IColor, ITerminalOptions } from '../common/Types'; +import { IColor, ITerminalOptions } from '../common/Types'; +import { CharData, IBuffer } from '../common/buffer/Types'; import { ICoreTerminal } from '../common/CoreTerminal'; -import { IBuffer } from '../common/buffer/Types'; import { IDisposable, IRenderDimensions as IRenderDimensionsApi, Terminal as ITerminalApi } from '@xterm/xterm'; import { channels, css } from '../common/Color'; import type { IEvent } from '../common/Event'; diff --git a/src/browser/renderer/dom/DomRendererRowFactory.test.ts b/src/browser/renderer/dom/DomRendererRowFactory.test.ts index 732766ccc..ade53f461 100644 --- a/src/browser/renderer/dom/DomRendererRowFactory.test.ts +++ b/src/browser/renderer/dom/DomRendererRowFactory.test.ts @@ -9,7 +9,7 @@ import { DomRendererRowFactory } from './DomRendererRowFactory'; import { NULL_CELL_CODE, NULL_CELL_WIDTH, NULL_CELL_CHAR, DEFAULT_ATTR, FgFlags, BgFlags, Attributes, UnderlineStyle } from '../../../common/buffer/Constants'; import { BufferLine, DEFAULT_ATTR_DATA } from '../../../common/buffer/BufferLine'; import { BufferLineStringCache } from '../../../common/buffer/BufferLineStringCache'; -import { IBufferLine } from '../../../common/Types'; +import { IBufferLine } from '../../../common/buffer/Types'; import { CellData } from '../../../common/buffer/CellData'; import { MockCoreService, MockDecorationService, MockOptionsService, createCellData, NULL_CELL_DATA } from '../../../common/TestUtils.test'; import { MockCharacterJoinerService, MockCoreBrowserService, MockThemeService } from '../../TestUtils.test'; diff --git a/src/browser/renderer/dom/DomRendererRowFactory.ts b/src/browser/renderer/dom/DomRendererRowFactory.ts index baa5af801..6ae089a43 100644 --- a/src/browser/renderer/dom/DomRendererRowFactory.ts +++ b/src/browser/renderer/dom/DomRendererRowFactory.ts @@ -3,7 +3,8 @@ * @license MIT */ -import { IBufferLine, ICellData, IColor } from '../../../common/Types'; +import { IColor } from '../../../common/Types'; +import { IBufferLine, ICellData } from '../../../common/buffer/Types'; import { INVERTED_DEFAULT_COLOR } from '../shared/Constants'; import { WHITESPACE_CELL_CHAR, Attributes } from '../../../common/buffer/Constants'; import { CellData } from '../../../common/buffer/CellData'; diff --git a/src/browser/services/CharacterJoinerService.test.ts b/src/browser/services/CharacterJoinerService.test.ts index 1dc3db334..2e73f035b 100644 --- a/src/browser/services/CharacterJoinerService.test.ts +++ b/src/browser/services/CharacterJoinerService.test.ts @@ -8,7 +8,7 @@ import { ICharacterJoinerService } from './Services'; import { CharacterJoinerService } from './CharacterJoinerService'; import { BufferLine } from '../../common/buffer/BufferLine'; import { BufferLineStringCache } from '../../common/buffer/BufferLineStringCache'; -import { IBufferLine } from '../../common/Types'; +import { IBufferLine } from '../../common/buffer/Types'; import { CellData } from '../../common/buffer/CellData'; import { MockBufferService, createCellData } from '../../common/TestUtils.test'; diff --git a/src/browser/services/CharacterJoinerService.ts b/src/browser/services/CharacterJoinerService.ts index 67ee70748..e1da0bd28 100644 --- a/src/browser/services/CharacterJoinerService.ts +++ b/src/browser/services/CharacterJoinerService.ts @@ -3,7 +3,7 @@ * @license MIT */ -import { IBufferLine, ICellData, CharData } from '../../common/Types'; +import { CharData, IBufferLine, ICellData } from '../../common/buffer/Types'; import { ICharacterJoiner } from '../Types'; import { AttributeData } from '../../common/buffer/AttributeData'; import { WHITESPACE_CELL_CHAR, Content } from '../../common/buffer/Constants'; diff --git a/src/browser/services/SelectionService.test.ts b/src/browser/services/SelectionService.test.ts index b48a4ee38..1f65e909e 100644 --- a/src/browser/services/SelectionService.test.ts +++ b/src/browser/services/SelectionService.test.ts @@ -6,14 +6,13 @@ import { assert } from 'chai'; import { SelectionService, SelectionMode } from './SelectionService'; import { SelectionModel } from '../selection/SelectionModel'; -import { IBufferLine } from '../../common/Types'; +import { IBuffer, IBufferLine } from '../../common/buffer/Types'; import { MockBufferService, MockOptionsService, MockCoreService, MockMouseStateService, createCellData } from '../../common/TestUtils.test'; import { BufferLine } from '../../common/buffer/BufferLine'; import { BufferLineStringCache } from '../../common/buffer/BufferLineStringCache'; import { IBufferService, IOptionsService } from '../../common/services/Services'; import { MockCoreBrowserService, MockMouseService, MockRenderService } from '../TestUtils.test'; import { CellData } from '../../common/buffer/CellData'; -import { IBuffer } from '../../common/buffer/Types'; import { IRenderService } from './Services'; const TEST_STRING_CACHE = new BufferLineStringCache(); diff --git a/src/browser/services/SelectionService.ts b/src/browser/services/SelectionService.ts index d6b015b61..576bdc525 100644 --- a/src/browser/services/SelectionService.ts +++ b/src/browser/services/SelectionService.ts @@ -11,10 +11,10 @@ import { ISelectionRedrawRequestEvent, ISelectionRequestScrollLinesEvent } from import { ICoreBrowserService, IMouseCoordsService, IRenderService, ISelectionService } from './Services'; import { Disposable, MutableDisposable, toDisposable } from '../../common/Lifecycle'; import * as Browser from '../../common/Platform'; -import { IBufferLine, ICellData, IDisposable } from '../../common/Types'; +import { IDisposable } from '../../common/Types'; +import { IBuffer, IBufferLine, ICellData } from '../../common/buffer/Types'; import { getRangeLength } from '../../common/buffer/BufferRange'; import { CellData } from '../../common/buffer/CellData'; -import { IBuffer } from '../../common/buffer/Types'; import { IBufferService, ICoreService, IMouseStateService, IOptionsService } from '../../common/services/Services'; import { Emitter } from '../../common/Event'; diff --git a/src/common/CoreTerminal.ts b/src/common/CoreTerminal.ts index 920de796f..cf16c1e14 100644 --- a/src/common/CoreTerminal.ts +++ b/src/common/CoreTerminal.ts @@ -26,7 +26,8 @@ import { InstantiationService } from './services/InstantiationService'; import { LogService } from './services/LogService'; import { BufferService, BufferServiceConstants } from './services/BufferService'; import { OptionsService } from './services/OptionsService'; -import { IDisposable, IAttributeData, IScrollEvent, ITerminalOptions, IParams } from './Types'; +import { IDisposable, IScrollEvent, ITerminalOptions, IParams } from './Types'; +import { IAttributeData, IBufferSet } from './buffer/Types'; import { CoreService } from './services/CoreService'; import { MouseStateService } from './services/MouseStateService'; import { UnicodeV6 } from './input/UnicodeV6'; @@ -34,7 +35,6 @@ import { UnicodeService } from './services/UnicodeService'; import { CharsetService } from './services/CharsetService'; import { updateWindowsModeWrappedState } from './WindowsMode'; import { IFunctionIdentifier } from './parser/Types'; -import { IBufferSet } from './buffer/Types'; import { InputHandler } from './InputHandler'; import { WriteBuffer } from './input/WriteBuffer'; import { OscLinkService } from './services/OscLinkService'; diff --git a/src/common/InputHandler.test.ts b/src/common/InputHandler.test.ts index 20d685e91..3cfc9e019 100644 --- a/src/common/InputHandler.test.ts +++ b/src/common/InputHandler.test.ts @@ -5,7 +5,8 @@ import { assert } from 'chai'; import { InputHandler } from './InputHandler'; -import { IBufferLine, IAttributeData, IColorEvent, ColorRequestType, SpecialColorIndex } from './Types'; +import { IColorEvent, ColorRequestType, SpecialColorIndex } from './Types'; +import { IAttributeData, IBufferLine } from './buffer/Types'; import { DEFAULT_ATTR_DATA } from './buffer/BufferLine'; import { CellData } from './buffer/CellData'; import { Attributes, BgFlags, UnderlineStyle } from './buffer/Constants'; diff --git a/src/common/InputHandler.ts b/src/common/InputHandler.ts index f7ab9c435..9d725cd1b 100644 --- a/src/common/InputHandler.ts +++ b/src/common/InputHandler.ts @@ -4,7 +4,8 @@ * @license MIT */ -import { IInputHandler, IAttributeData, IDisposable, IWindowOptions, IColorEvent, IParseStack, ColorIndex, ColorRequestType, SpecialColorIndex } from './Types'; +import { IInputHandler, IDisposable, IWindowOptions, IColorEvent, IParseStack, ColorIndex, ColorRequestType, SpecialColorIndex } from './Types'; +import { IAttributeData, IBuffer } from './buffer/Types'; import { C0, C1 } from './data/EscapeSequences'; import { CHARSETS, DEFAULT_CHARSET } from './data/Charsets'; import { EscapeSequenceParser } from './parser/EscapeSequenceParser'; @@ -20,7 +21,6 @@ import { UnicodeService } from './services/UnicodeService'; import { OscHandler } from './parser/OscParser'; import { DcsHandler } from './parser/DcsParser'; import { ApcHandler } from './parser/ApcParser'; -import { IBuffer } from './buffer/Types'; import { parseColor } from './input/XParseColor'; import { Emitter } from './Event'; import { XTERM_VERSION } from './Version'; diff --git a/src/common/TestUtils.test.ts b/src/common/TestUtils.test.ts index 3ae6db77d..bedfa6ba1 100644 --- a/src/common/TestUtils.test.ts +++ b/src/common/TestUtils.test.ts @@ -6,9 +6,9 @@ import { IBufferService, ICoreService, ILogService, IOptionsService, ITerminalOptions, IMouseStateService, ICharsetService, UnicodeCharProperties, UnicodeCharWidth, IUnicodeService, IUnicodeVersionProvider, LogLevelEnum, IDecorationService, IInternalDecoration, IOscLinkService, type IBufferResizeEvent } from './services/Services'; import { UnicodeService } from './services/UnicodeService'; import { DEFAULT_OPTIONS } from './services/OptionsService'; -import { IBufferSet, IBuffer } from './buffer/Types'; +import { IAttributeData, IBuffer, IBufferLine, IBufferSet, IExtendedAttrs } from './buffer/Types'; import { BufferSet } from './buffer/BufferSet'; -import { IDecPrivateModes, ICoreMouseEvent, CoreMouseEventType, ICharset, IModes, IAttributeData, IOscLinkData, IDisposable, IBufferLine, IExtendedAttrs } from './Types'; +import { IDecPrivateModes, ICoreMouseEvent, CoreMouseEventType, ICharset, IModes, IOscLinkData, IDisposable } from './Types'; import { UnicodeV6 } from './input/UnicodeV6'; import { IDecorationOptions, IDecoration } from '@xterm/xterm'; import { Emitter, type IEvent } from './Event'; diff --git a/src/common/Types.ts b/src/common/Types.ts index 5b7b42bb2..c2416c6c9 100644 --- a/src/common/Types.ts +++ b/src/common/Types.ts @@ -41,15 +41,6 @@ export interface IParams { getSubParamsAll(): {[idx: number]: Int32Array}; } -export const enum UnderlineStyle { - NONE = 0, - SINGLE = 1, - DOUBLE = 2, - CURLY = 3, - DOTTED = 4, - DASHED = 5 -} - export interface IDisposable { dispose(): void; } @@ -126,24 +117,12 @@ export interface ICharset { [key: string]: string | undefined; } -export type CharData = [attr: number, char: string, width: number, code: number]; - export interface IColor { readonly css: string; readonly rgba: number; // 32-bit int with rgba in each byte } export type IColorRGB = [red: number, green: number, blue: number]; -export interface IExtendedAttrs { - ext: number; - underlineStyle: UnderlineStyle; - underlineColor: number; - underlineVariantOffset: number; - urlId: number; - clone(): IExtendedAttrs; - isEmpty(): boolean; -} - /** * Tracks the current hyperlink. Since these are treated as extended attirbutes, these get passed on * to the linkifier when anything is printed. Doing it this way ensures that even when the cursor @@ -155,183 +134,6 @@ export interface IOscLinkData { uri: string; } -/** - * An object that represents all attributes of a cell. - */ -export interface IAttributeData { - /** - * "fg" is a 32-bit unsigned integer that stores the foreground color of the cell in the 24 least - * significant bits and additional flags in the remaining 8 bits. - */ - fg: number; - /** - * "bg" is a 32-bit unsigned integer that stores the background color of the cell in the 24 least - * significant bits and additional flags in the remaining 8 bits. - */ - bg: number; - /** - * "extended", aka "ext", stores extended attributes beyond those available in fg and bg. This - * data is optional on a cell and encodes less common data. - */ - extended: IExtendedAttrs; - - clone(): IAttributeData; - - // flags - isInverse(): number; - isBold(): number; - isUnderline(): number; - isBlink(): number; - isInvisible(): number; - isItalic(): number; - isDim(): number; - isStrikethrough(): number; - isProtected(): number; - isOverline(): number; - - /** - * The color mode of the foreground color which determines how to decode {@link getFgColor}, - * possible values include {@link Attributes.CM_DEFAULT}, {@link Attributes.CM_P16}, - * {@link Attributes.CM_P256} and {@link Attributes.CM_RGB}. - */ - getFgColorMode(): number; - /** - * The color mode of the background color which determines how to decode {@link getBgColor}, - * possible values include {@link Attributes.CM_DEFAULT}, {@link Attributes.CM_P16}, - * {@link Attributes.CM_P256} and {@link Attributes.CM_RGB}. - */ - getBgColorMode(): number; - isFgRGB(): boolean; - isBgRGB(): boolean; - isFgPalette(): boolean; - isBgPalette(): boolean; - isFgDefault(): boolean; - isBgDefault(): boolean; - isAttributeDefault(): boolean; - - /** - * Gets an integer representation of the foreground color, how to decode the color depends on the - * color mode {@link getFgColorMode}. - */ - getFgColor(): number; - /** - * Gets an integer representation of the background color, how to decode the color depends on the - * color mode {@link getBgColorMode}. - */ - getBgColor(): number; - - // extended attrs - hasExtendedAttrs(): number; - updateExtended(): void; - getUnderlineColor(): number; - getUnderlineColorMode(): number; - isUnderlineColorRGB(): boolean; - isUnderlineColorPalette(): boolean; - isUnderlineColorDefault(): boolean; - getUnderlineStyle(): number; - getUnderlineVariantOffset(): number; -} - -/** Cell data */ -export interface ICellData extends IAttributeData { - content: number; - combinedData: string; - isCombined(): number; - getWidth(): number; - getChars(): string; - getCode(): number; - setFromCharData(value: CharData): void; - getAsCharData(): CharData; -} - -/** - * Interface for a line in the terminal buffer. - */ -export interface IBufferLine { - length: number; - isWrapped: boolean; - get(index: number): CharData; - set(index: number, value: CharData): void; - loadCell(index: number, cell: ICellData): ICellData; - setCell(index: number, cell: ICellData): void; - setCellFromCodepoint(index: number, codePoint: number, width: number, attrs: IAttributeData): void; - addCodepointToCell(index: number, codePoint: number, width: number): void; - insertCells(pos: number, n: number, ch: ICellData): void; - deleteCells(pos: number, n: number, fill: ICellData): void; - replaceCells(start: number, end: number, fill: ICellData, respectProtect?: boolean): void; - resize(cols: number, fill: ICellData): boolean; - cleanupMemory(): number; - fill(fillCellData: ICellData, respectProtect?: boolean): void; - copyFrom(line: IBufferLine): void; - clone(): IBufferLine; - getTrimmedLength(): number; - getNoBgTrimmedLength(): number; - translateToString(trimRight?: boolean, startCol?: number, endCol?: number, outColumns?: number[]): string; - - /* direct access to cell attrs */ - getWidth(index: number): number; - hasWidth(index: number): number; - getFg(index: number): number; - getBg(index: number): number; - hasContent(index: number): number; - getCodePoint(index: number): number; - isCombined(index: number): number; - getString(index: number): string; -} - -export interface IMarker extends IDisposable { - readonly id: number; - readonly isDisposed: boolean; - readonly line: number; - onDispose: IEvent; -} - -export interface IBuffer { - readonly lines: ICircularList; - ydisp: number; - ybase: number; - y: number; - x: number; - tabs: any; - scrollBottom: number; - scrollTop: number; - hasScrollback: boolean; - savedY: number; - savedX: number; - savedCharset: ICharset | undefined; - savedCharsets: (ICharset | undefined)[]; - savedGlevel: number; - savedOriginMode: boolean; - savedWraparoundMode: boolean; - savedCurAttrData: IAttributeData; - isCursorInViewport: boolean; - markers: IMarker[]; - translateBufferLineToString(lineIndex: number, trimRight: boolean, startCol?: number, endCol?: number): string; - getWrappedRangeForLine(y: number): { first: number, last: number }; - nextStop(x?: number): number; - prevStop(x?: number): number; - getBlankLine(attr: IAttributeData, isWrapped?: boolean): IBufferLine; - getNullCell(attr?: IAttributeData): ICellData; - getWhitespaceCell(attr?: IAttributeData): ICellData; - addMarker(y: number): IMarker; - clearMarkers(y: number): void; - clearAllMarkers(): void; -} - -export interface IBufferSet extends IDisposable { - alt: IBuffer; - normal: IBuffer; - active: IBuffer; - - onBufferActivate: IEvent<{ activeBuffer: IBuffer, inactiveBuffer: IBuffer }>; - - activateNormalBuffer(): void; - activateAltBuffer(fillAttr?: IAttributeData): void; - reset(): void; - resize(newCols: number, newRows: number): void; - setupTabStops(i?: number): void; -} - export interface IModes { insertMode: boolean; } diff --git a/src/common/buffer/AttributeData.ts b/src/common/buffer/AttributeData.ts index c9c940f93..3bcb22a00 100644 --- a/src/common/buffer/AttributeData.ts +++ b/src/common/buffer/AttributeData.ts @@ -3,7 +3,8 @@ * @license MIT */ -import { IAttributeData, IColorRGB, IExtendedAttrs } from '../Types'; +import { IColorRGB } from '../Types'; +import { IAttributeData, IExtendedAttrs } from './Types'; import { Attributes, FgFlags, BgFlags, UnderlineStyle, ExtFlags } from './Constants'; export class AttributeData implements IAttributeData { diff --git a/src/common/buffer/Buffer.ts b/src/common/buffer/Buffer.ts index 83479f422..be3df09b1 100644 --- a/src/common/buffer/Buffer.ts +++ b/src/common/buffer/Buffer.ts @@ -6,7 +6,8 @@ import { CircularList, IInsertEvent } from '../CircularList'; import { Disposable, toDisposable } from '../Lifecycle'; import { IdleTaskQueue } from '../TaskQueue'; -import { IAttributeData, IBufferLine, ICellData, ICharset } from '../Types'; +import { ICharset } from '../Types'; +import { IAttributeData, IBuffer, IBufferLine, ICellData } from './Types'; import { ExtendedAttrs } from './AttributeData'; import { BufferLine, DEFAULT_ATTR_DATA } from './BufferLine'; import { BufferLineStringCache } from './BufferLineStringCache'; @@ -14,7 +15,6 @@ import { getWrappedLineTrimmedLength, reflowLargerApplyNewLayout, reflowLargerCr import { CellData } from './CellData'; import { NULL_CELL_CHAR, NULL_CELL_CODE, NULL_CELL_WIDTH, WHITESPACE_CELL_CHAR, WHITESPACE_CELL_CODE, WHITESPACE_CELL_WIDTH } from './Constants'; import { Marker } from './Marker'; -import { IBuffer } from './Types'; import { DEFAULT_CHARSET } from '../data/Charsets'; import { IBufferService, ILogService, IOptionsService } from '../services/Services'; diff --git a/src/common/buffer/BufferLine.test.ts b/src/common/buffer/BufferLine.test.ts index 3658611cb..7fc12ad76 100644 --- a/src/common/buffer/BufferLine.test.ts +++ b/src/common/buffer/BufferLine.test.ts @@ -6,7 +6,7 @@ import { NULL_CELL_CHAR, NULL_CELL_WIDTH, NULL_CELL_CODE, DEFAULT_ATTR, Content, import { BufferLine } from './BufferLine'; import { BufferLineStringCache } from './BufferLineStringCache'; import { CellData } from './CellData'; -import { CharData, IBufferLine, ICellData } from '../Types'; +import { CharData, IBufferLine, ICellData } from './Types'; import { assert } from 'chai'; import { AttributeData } from './AttributeData'; import { createCellData, NULL_CELL_DATA, extendedAttributes } from '../TestUtils.test'; diff --git a/src/common/buffer/BufferLine.ts b/src/common/buffer/BufferLine.ts index f927f76fc..4b6f6e8bb 100644 --- a/src/common/buffer/BufferLine.ts +++ b/src/common/buffer/BufferLine.ts @@ -3,7 +3,7 @@ * @license MIT */ -import { CharData, IAttributeData, IBufferLine, ICellData, IExtendedAttrs } from '../Types'; +import { CharData, IAttributeData, IBufferLine, ICellData, IExtendedAttrs } from './Types'; import { AttributeData } from './AttributeData'; import { CellData } from './CellData'; import { Attributes, BgFlags, CHAR_DATA_ATTR_INDEX, CHAR_DATA_CHAR_INDEX, CHAR_DATA_WIDTH_INDEX, Content, NULL_CELL_CHAR, NULL_CELL_CODE, NULL_CELL_WIDTH, WHITESPACE_CELL_CHAR } from './Constants'; diff --git a/src/common/buffer/BufferReflow.ts b/src/common/buffer/BufferReflow.ts index d94739c30..2c0fb74ba 100644 --- a/src/common/buffer/BufferReflow.ts +++ b/src/common/buffer/BufferReflow.ts @@ -5,7 +5,7 @@ import { BufferLine } from './BufferLine'; import { CircularList } from '../CircularList'; -import { IBufferLine, ICellData } from '../Types'; +import { IBufferLine, ICellData } from './Types'; export interface INewLayoutResult { layout: number[]; diff --git a/src/common/buffer/BufferSet.ts b/src/common/buffer/BufferSet.ts index 87b123386..4ea2cee8d 100644 --- a/src/common/buffer/BufferSet.ts +++ b/src/common/buffer/BufferSet.ts @@ -4,9 +4,8 @@ */ import { Disposable, MutableDisposable } from '../Lifecycle'; -import { IAttributeData } from '../Types'; import { Buffer } from './Buffer'; -import { IBuffer, IBufferSet } from './Types'; +import { IAttributeData, IBuffer, IBufferSet } from './Types'; import { IBufferService, ILogService, IOptionsService } from '../services/Services'; import { Emitter } from '../Event'; diff --git a/src/common/buffer/CellData.ts b/src/common/buffer/CellData.ts index 18f04a30e..3c738f77f 100644 --- a/src/common/buffer/CellData.ts +++ b/src/common/buffer/CellData.ts @@ -3,7 +3,7 @@ * @license MIT */ -import { CharData, ICellData, IExtendedAttrs } from '../Types'; +import { CharData, ICellData, IExtendedAttrs } from './Types'; import { stringFromCodePoint } from '../input/TextDecoder'; import { CHAR_DATA_CHAR_INDEX, CHAR_DATA_WIDTH_INDEX, CHAR_DATA_ATTR_INDEX, Content } from './Constants'; import { AttributeData, ExtendedAttrs } from './AttributeData'; diff --git a/src/common/buffer/Constants.ts b/src/common/buffer/Constants.ts index 12b2d7ad4..5ce075cf7 100644 --- a/src/common/buffer/Constants.ts +++ b/src/common/buffer/Constants.ts @@ -147,4 +147,11 @@ export const enum ExtFlags { VARIANT_OFFSET = 0xE0000000 } -export { UnderlineStyle } from '../Types'; +export const enum UnderlineStyle { + NONE = 0, + SINGLE = 1, + DOUBLE = 2, + CURLY = 3, + DOTTED = 4, + DASHED = 5 +} diff --git a/src/common/buffer/Marker.ts b/src/common/buffer/Marker.ts index e69699c1b..ed5124add 100644 --- a/src/common/buffer/Marker.ts +++ b/src/common/buffer/Marker.ts @@ -3,9 +3,9 @@ * @license MIT */ -import { IDisposable, IMarker } from '../Types'; +import { dispose, IDisposable } from '../Lifecycle'; +import { IMarker } from './Types'; import { Emitter } from '../Event'; -import { dispose } from '../Lifecycle'; export class Marker implements IMarker { private static _nextId = 1; diff --git a/src/common/buffer/Types.ts b/src/common/buffer/Types.ts index d5bee5efd..174defb9b 100644 --- a/src/common/buffer/Types.ts +++ b/src/common/buffer/Types.ts @@ -3,7 +3,199 @@ * @license MIT */ -export type { IBuffer, IBufferSet } from '../Types'; +import type { IEvent } from '../Event'; +import type { ICircularList, ICharset } from '../Types'; +import type { IDisposable } from '../Lifecycle'; +import type { UnderlineStyle } from './Constants'; // BufferIndex denotes a position in the buffer: [rowIndex, colIndex] export type BufferIndex = [number, number]; + +export type CharData = [attr: number, char: string, width: number, code: number]; + +export interface IExtendedAttrs { + ext: number; + underlineStyle: UnderlineStyle; + underlineColor: number; + underlineVariantOffset: number; + urlId: number; + clone(): IExtendedAttrs; + isEmpty(): boolean; +} + +/** + * An object that represents all attributes of a cell. + */ +export interface IAttributeData { + /** + * "fg" is a 32-bit unsigned integer that stores the foreground color of the cell in the 24 least + * significant bits and additional flags in the remaining 8 bits. + */ + fg: number; + /** + * "bg" is a 32-bit unsigned integer that stores the background color of the cell in the 24 least + * significant bits and additional flags in the remaining 8 bits. + */ + bg: number; + /** + * "extended", aka "ext", stores extended attributes beyond those available in fg and bg. This + * data is optional on a cell and encodes less common data. + */ + extended: IExtendedAttrs; + + clone(): IAttributeData; + + // flags + isInverse(): number; + isBold(): number; + isUnderline(): number; + isBlink(): number; + isInvisible(): number; + isItalic(): number; + isDim(): number; + isStrikethrough(): number; + isProtected(): number; + isOverline(): number; + + /** + * The color mode of the foreground color which determines how to decode {@link getFgColor}, + * possible values include {@link Attributes.CM_DEFAULT}, {@link Attributes.CM_P16}, + * {@link Attributes.CM_P256} and {@link Attributes.CM_RGB}. + */ + getFgColorMode(): number; + /** + * The color mode of the background color which determines how to decode {@link getBgColor}, + * possible values include {@link Attributes.CM_DEFAULT}, {@link Attributes.CM_P16}, + * {@link Attributes.CM_P256} and {@link Attributes.CM_RGB}. + */ + getBgColorMode(): number; + isFgRGB(): boolean; + isBgRGB(): boolean; + isFgPalette(): boolean; + isBgPalette(): boolean; + isFgDefault(): boolean; + isBgDefault(): boolean; + isAttributeDefault(): boolean; + + /** + * Gets an integer representation of the foreground color, how to decode the color depends on the + * color mode {@link getFgColorMode}. + */ + getFgColor(): number; + /** + * Gets an integer representation of the background color, how to decode the color depends on the + * color mode {@link getBgColorMode}. + */ + getBgColor(): number; + + // extended attrs + hasExtendedAttrs(): number; + updateExtended(): void; + getUnderlineColor(): number; + getUnderlineColorMode(): number; + isUnderlineColorRGB(): boolean; + isUnderlineColorPalette(): boolean; + isUnderlineColorDefault(): boolean; + getUnderlineStyle(): number; + getUnderlineVariantOffset(): number; +} + +/** Cell data */ +export interface ICellData extends IAttributeData { + content: number; + combinedData: string; + isCombined(): number; + getWidth(): number; + getChars(): string; + getCode(): number; + setFromCharData(value: CharData): void; + getAsCharData(): CharData; +} + +/** + * Interface for a line in the terminal buffer. + */ +export interface IBufferLine { + length: number; + isWrapped: boolean; + get(index: number): CharData; + set(index: number, value: CharData): void; + loadCell(index: number, cell: ICellData): ICellData; + setCell(index: number, cell: ICellData): void; + setCellFromCodepoint(index: number, codePoint: number, width: number, attrs: IAttributeData): void; + addCodepointToCell(index: number, codePoint: number, width: number): void; + insertCells(pos: number, n: number, ch: ICellData): void; + deleteCells(pos: number, n: number, fill: ICellData): void; + replaceCells(start: number, end: number, fill: ICellData, respectProtect?: boolean): void; + resize(cols: number, fill: ICellData): boolean; + cleanupMemory(): number; + fill(fillCellData: ICellData, respectProtect?: boolean): void; + copyFrom(line: IBufferLine): void; + clone(): IBufferLine; + getTrimmedLength(): number; + getNoBgTrimmedLength(): number; + translateToString(trimRight?: boolean, startCol?: number, endCol?: number, outColumns?: number[]): string; + + /* direct access to cell attrs */ + getWidth(index: number): number; + hasWidth(index: number): number; + getFg(index: number): number; + getBg(index: number): number; + hasContent(index: number): number; + getCodePoint(index: number): number; + isCombined(index: number): number; + getString(index: number): string; +} + +export interface IMarker extends IDisposable { + readonly id: number; + readonly isDisposed: boolean; + readonly line: number; + onDispose: IEvent; +} + +export interface IBuffer { + readonly lines: ICircularList; + ydisp: number; + ybase: number; + y: number; + x: number; + tabs: any; + scrollBottom: number; + scrollTop: number; + hasScrollback: boolean; + savedY: number; + savedX: number; + savedCharset: ICharset | undefined; + savedCharsets: (ICharset | undefined)[]; + savedGlevel: number; + savedOriginMode: boolean; + savedWraparoundMode: boolean; + savedCurAttrData: IAttributeData; + isCursorInViewport: boolean; + markers: IMarker[]; + translateBufferLineToString(lineIndex: number, trimRight: boolean, startCol?: number, endCol?: number): string; + getWrappedRangeForLine(y: number): { first: number, last: number }; + nextStop(x?: number): number; + prevStop(x?: number): number; + getBlankLine(attr: IAttributeData, isWrapped?: boolean): IBufferLine; + getNullCell(attr?: IAttributeData): ICellData; + getWhitespaceCell(attr?: IAttributeData): ICellData; + addMarker(y: number): IMarker; + clearMarkers(y: number): void; + clearAllMarkers(): void; +} + +export interface IBufferSet extends IDisposable { + alt: IBuffer; + normal: IBuffer; + active: IBuffer; + + onBufferActivate: IEvent<{ activeBuffer: IBuffer, inactiveBuffer: IBuffer }>; + + activateNormalBuffer(): void; + activateAltBuffer(fillAttr?: IAttributeData): void; + reset(): void; + resize(newCols: number, newRows: number): void; + setupTabStops(i?: number): void; +} diff --git a/src/common/public/BufferLineApiView.ts b/src/common/public/BufferLineApiView.ts index ecffd1fbb..bd822bfb5 100644 --- a/src/common/public/BufferLineApiView.ts +++ b/src/common/public/BufferLineApiView.ts @@ -4,7 +4,7 @@ */ import { CellData } from '../buffer/CellData'; -import { IBufferLine, ICellData } from '../Types'; +import { IBufferLine, ICellData } from '../buffer/Types'; import { IBufferCell as IBufferCellApi, IBufferLine as IBufferLineApi } from '@xterm/xterm'; export class BufferLineApiView implements IBufferLineApi { diff --git a/src/common/services/BufferService.ts b/src/common/services/BufferService.ts index 5135e7786..21b0a163a 100644 --- a/src/common/services/BufferService.ts +++ b/src/common/services/BufferService.ts @@ -4,9 +4,8 @@ */ import { Disposable } from '../Lifecycle'; -import { IAttributeData, IBufferLine } from '../Types'; +import { IAttributeData, IBuffer, IBufferLine, IBufferSet } from '../buffer/Types'; import { BufferSet } from '../buffer/BufferSet'; -import { IBuffer, IBufferSet } from '../buffer/Types'; import { IBufferService, ILogService, IOptionsService, type IBufferResizeEvent } from './Services'; import { Emitter } from '../Event'; diff --git a/src/common/services/DecorationService.test.ts b/src/common/services/DecorationService.test.ts index 71299d330..61a7668fc 100644 --- a/src/common/services/DecorationService.test.ts +++ b/src/common/services/DecorationService.test.ts @@ -5,7 +5,7 @@ import { assert } from 'chai'; import { DecorationLineCache, DecorationService } from './DecorationService'; -import { IMarker } from '../Types'; +import { IMarker } from '../buffer/Types'; import { Disposable } from '../Lifecycle'; import { Emitter } from '../Event'; import { MockLogService, MockBufferService, MockOptionsService } from '../TestUtils.test'; diff --git a/src/common/services/OscLinkService.ts b/src/common/services/OscLinkService.ts index e28f4cfc8..605e85002 100644 --- a/src/common/services/OscLinkService.ts +++ b/src/common/services/OscLinkService.ts @@ -3,7 +3,8 @@ * @license MIT */ import { IBufferService, IOscLinkService } from './Services'; -import { IMarker, IOscLinkData } from '../Types'; +import { IOscLinkData } from '../Types'; +import { IMarker } from '../buffer/Types'; export class OscLinkService implements IOscLinkService { public serviceBrand: any; diff --git a/src/common/services/Services.ts b/src/common/services/Services.ts index 5308f843d..cd1bc9cd4 100644 --- a/src/common/services/Services.ts +++ b/src/common/services/Services.ts @@ -4,8 +4,8 @@ */ import type { IDecoration, IDecorationOptions, ILinkHandler, ILogger, IWindowsPty, IOverviewRulerOptions } from '@xterm/xterm'; -import { CoreMouseEncoding, CoreMouseEventType, CursorInactiveStyle, CursorStyle, IAttributeData, ICharset, IColor, ICoreMouseEvent, ICoreMouseProtocol, IDecPrivateModes, IDisposable, IKittyKeyboardState, IModes, IOscLinkData, IWindowOptions } from '../Types'; -import { IBuffer, IBufferSet } from '../buffer/Types'; +import { CoreMouseEncoding, CoreMouseEventType, CursorInactiveStyle, CursorStyle, ICharset, IColor, ICoreMouseEvent, ICoreMouseProtocol, IDecPrivateModes, IDisposable, IKittyKeyboardState, IModes, IOscLinkData, IWindowOptions } from '../Types'; +import { IAttributeData, IBuffer, IBufferSet } from '../buffer/Types'; import { createDecorator, IServiceIdentifier } from './ServiceRegistry'; import type { Emitter, IEvent } from '../Event'; diff --git a/src/headless/Terminal.ts b/src/headless/Terminal.ts index 4d4266d19..4d90cc03e 100644 --- a/src/headless/Terminal.ts +++ b/src/headless/Terminal.ts @@ -22,9 +22,9 @@ */ import { DEFAULT_ATTR_DATA } from '../common/buffer/BufferLine'; -import { IBuffer } from '../common/buffer/Types'; +import { IBuffer, IMarker } from '../common/buffer/Types'; import { CoreTerminal } from '../common/CoreTerminal'; -import { IMarker, ITerminalOptions } from '../common/Types'; +import { ITerminalOptions } from '../common/Types'; import { Emitter, EventUtils } from '../common/Event'; export class Terminal extends CoreTerminal { diff --git a/test/playwright/TestUtils.ts b/test/playwright/TestUtils.ts index 05f3a8e31..2a44c3592 100644 --- a/test/playwright/TestUtils.ts +++ b/test/playwright/TestUtils.ts @@ -7,7 +7,8 @@ import { Browser, JSHandle, Page } from '@playwright/test'; import { deepStrictEqual, strictEqual } from 'assert'; import type { IRenderDimensions as IRenderDimensionsInternal } from '../../src/browser/renderer/shared/Types'; import type { IRenderService } from '../../src/browser/services/Services'; -import type { IDisposable, IMarker } from '../../src/common/Types'; +import type { IDisposable } from '../../src/common/Types'; +import type { IMarker } from '../../src/common/buffer/Types'; import type { ICoreTerminal } from '../../src/common/CoreTerminal'; import * as playwright from '@playwright/test'; import { IBuffer, IBufferCell, IBufferLine, IBufferNamespace, IBufferRange, IDecoration, IDecorationOptions, IModes, IRenderDimensions, ITerminalInitOnlyOptions, ITerminalOptions, Terminal } from '@xterm/xterm';