Skip to content

fit the terminal into custom dimensions #4925

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions addons/addon-fit/src/FitAddon.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ export class FitAddon implements ITerminalAddon , IFitApi {

public dispose(): void {}

public fit(): void {
const dims = this.proposeDimensions();
public fit(rect: object | undefined): void {
const dims = this.proposeDimensions(rect);
if (!dims || !this._terminal || isNaN(dims.cols) || isNaN(dims.rows)) {
return;
}
Expand All @@ -47,7 +47,7 @@ export class FitAddon implements ITerminalAddon , IFitApi {
}
}

public proposeDimensions(): ITerminalDimensions | undefined {
public proposeDimensions(rect: object | undefined): ITerminalDimensions | undefined {
if (!this._terminal) {
return undefined;
}
Expand All @@ -68,8 +68,8 @@ export class FitAddon implements ITerminalAddon , IFitApi {
0 : core.viewport.scrollBarWidth;

const parentElementStyle = window.getComputedStyle(this._terminal.element.parentElement);
const parentElementHeight = parseInt(parentElementStyle.getPropertyValue('height'));
const parentElementWidth = Math.max(0, parseInt(parentElementStyle.getPropertyValue('width')));
const parentElementHeight = (rect && rect.height) ? rect.height : parseInt(parentElementStyle.getPropertyValue('height'));
const parentElementWidth = (rect && rect.width) ? rect.width : Math.max(0, parseInt(parentElementStyle.getPropertyValue('width')));
const elementStyle = window.getComputedStyle(this._terminal.element);
const elementPadding = {
top: parseInt(elementStyle.getPropertyValue('padding-top')),
Expand Down
4 changes: 2 additions & 2 deletions addons/addon-fit/typings/addon-fit.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,12 +30,12 @@ declare module '@xterm/addon-fit' {
/**
* Resizes the terminal to the dimensions of its containing element.
*/
public fit(): void;
public fit(rect: object): void;

/**
* Gets the proposed dimensions that will be used for a fit.
*/
public proposeDimensions(): ITerminalDimensions | undefined;
public proposeDimensions(rect: object): ITerminalDimensions | undefined;
}

/**
Expand Down