Add dimensions API

Fixes #702
This commit is contained in:
Daniel Imms
2025-12-30 03:58:26 -08:00
parent 00ad3eac40
commit 214289aaab
8 changed files with 183 additions and 18 deletions
+121
View File
@@ -877,6 +877,12 @@ declare module '@xterm/xterm' {
*/
readonly modes: IModes;
/**
* The dimensions of the terminal. This will be undefined before
* {@link open} is called.
*/
readonly dimensions: IRenderDimensions | undefined;
/**
* Gets or sets the terminal options. This supports setting multiple
* options.
@@ -1017,6 +1023,12 @@ declare module '@xterm/xterm' {
*/
onTitleChange: IEvent<string>;
/**
* Adds an event listener for when the terminal's dimensions change.
* @returns an `IDisposable` to stop listening.
*/
onDimensionsChange: IEvent<IRenderDimensions>;
/**
* Unfocus the terminal.
*/
@@ -1969,4 +1981,113 @@ declare module '@xterm/xterm' {
*/
readonly wraparoundMode: boolean;
}
/**
* An object containing a width and height in pixels.
*/
export interface IDimensions {
width: number;
height: number;
}
/**
* An object containing a top and left offset.
*/
export interface IOffset {
top: number;
left: number;
}
/**
* The dimensions of the terminal.
*/
export interface IRenderDimensions {
/**
* Dimensions measured in CSS pixels (ie. device pixels / device pixel
* ratio).
*/
css: {
/**
* The dimensions of the canvas.
*/
canvas: IDimensions;
/**
* The dimensions of a single cell.
*/
cell: IDimensions;
};
/**
* Dimensions measured in actual pixels as rendered to the device.
*/
device: {
/**
* The dimensions of the canvas.
*/
canvas: IDimensions;
/**
* The dimensions of a single cell.
*/
cell: IDimensions;
/**
* The dimensions of a single character within a cell, including its
* offset within the cell.
*/
char: IDimensions & IOffset;
};
}
/**
* An object containing a width and height in pixels.
*/
export interface IDimensions {
width: number;
height: number;
}
/**
* An object containing a top and left offset.
*/
export interface IOffset {
top: number;
left: number;
}
/**
* The dimensions of the terminal, this is constructed and available after
* {@link Terminal.open} is called.
*/
export interface IRenderDimensions {
/**
* Dimensions measured in CSS pixels (ie. device pixels / device pixel
* ratio).
*/
css: {
/**
* The dimensions of the canvas which is the full terminal size.
*/
canvas: IDimensions;
/**
* The dimensions of a single cell.
*/
cell: IDimensions;
};
/**
* Dimensions measured in actual pixels as rendered to the device.
*/
device: {
/**
* The dimensions of the canvas which is the full terminal size.
*/
canvas: IDimensions;
/**
* The dimensions of a single cell.
*/
cell: IDimensions;
/**
* The dimensions of a single character within a cell, including its
* offset within the cell.
*/
char: IDimensions & IOffset;
};
}
}