Skip to content
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

ITerminalOptions: Make fields required #4004

Merged
merged 3 commits into from
Sep 2, 2022
Merged
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
4 changes: 2 additions & 2 deletions addons/xterm-addon-canvas/src/atlas/CharAtlasCache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { BaseCharAtlas } from './BaseCharAtlas';
import { DynamicCharAtlas } from './DynamicCharAtlas';
import { ICharAtlasConfig } from './Types';
import { IColorSet } from 'browser/Types';
import { ITerminalOptions } from 'common/services/Services';
import { ITerminalOptions } from 'xterm';

interface ICharAtlasCacheEntry {
atlas: BaseCharAtlas;
Expand All @@ -25,7 +25,7 @@ const charAtlasCache: ICharAtlasCacheEntry[] = [];
* one that is in use by another terminal.
*/
export function acquireCharAtlas(
options: ITerminalOptions,
options: Required<ITerminalOptions>,
rendererId: number,
colors: IColorSet,
scaledCharWidth: number,
Expand Down
4 changes: 2 additions & 2 deletions addons/xterm-addon-canvas/src/atlas/CharAtlasUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
import { ICharAtlasConfig } from './Types';
import { DEFAULT_COLOR } from 'common/buffer/Constants';
import { IColorSet, IPartialColorSet } from 'browser/Types';
import { ITerminalOptions } from 'common/services/Services';
import { ITerminalOptions } from 'xterm';

export function generateConfig(scaledCharWidth: number, scaledCharHeight: number, options: ITerminalOptions, colors: IColorSet): ICharAtlasConfig {
export function generateConfig(scaledCharWidth: number, scaledCharHeight: number, options: Required<ITerminalOptions>, colors: IColorSet): ICharAtlasConfig {
// null out some fields that don't matter
const clonedColors: IPartialColorSet = {
foreground: colors.foreground,
Expand Down
6 changes: 3 additions & 3 deletions addons/xterm-addon-webgl/src/WebglRenderer.ts
Original file line number Diff line number Diff line change
Expand Up @@ -622,18 +622,18 @@ export class WebglRenderer extends Disposable implements IRenderer {
// Calculate the scaled cell height, if lineHeight is _not_ 1, the resulting value will be
// floored since lineHeight can never be lower then 1, this guarentees the scaled cell height
// will always be larger than scaled char height.
this.dimensions.scaledCellHeight = Math.floor(this.dimensions.scaledCharHeight * this._terminal.options.lineHeight!);
this.dimensions.scaledCellHeight = Math.floor(this.dimensions.scaledCharHeight * this._terminal.options.lineHeight);

// Calculate the y offset within a cell that glyph should draw at in order for it to be centered
// correctly within the cell.
this.dimensions.scaledCharTop = this._terminal.options.lineHeight === 1 ? 0 : Math.round((this.dimensions.scaledCellHeight - this.dimensions.scaledCharHeight) / 2);

// Calculate the scaled cell width, taking the letterSpacing into account.
this.dimensions.scaledCellWidth = this.dimensions.scaledCharWidth + Math.round(this._terminal.options.letterSpacing!);
this.dimensions.scaledCellWidth = this.dimensions.scaledCharWidth + Math.round(this._terminal.options.letterSpacing);

// Calculate the x offset with a cell that text should draw from in order for it to be centered
// correctly within the cell.
this.dimensions.scaledCharLeft = Math.floor(this._terminal.options.letterSpacing! / 2);
this.dimensions.scaledCharLeft = Math.floor(this._terminal.options.letterSpacing / 2);

// Recalculate the canvas dimensions, the scaled dimensions define the actual number of pixel in
// the canvas
Expand Down
20 changes: 10 additions & 10 deletions addons/xterm-addon-webgl/src/atlas/CharAtlasUtils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,21 +32,21 @@ export function generateConfig(scaledCellWidth: number, scaledCellHeight: number
contrastCache: colors.contrastCache
};
return {
customGlyphs: terminal.options.customGlyphs!,
customGlyphs: terminal.options.customGlyphs,
devicePixelRatio: window.devicePixelRatio,
letterSpacing: terminal.options.letterSpacing!,
lineHeight: terminal.options.lineHeight!,
letterSpacing: terminal.options.letterSpacing,
lineHeight: terminal.options.lineHeight,
scaledCellWidth,
scaledCellHeight,
scaledCharWidth,
scaledCharHeight,
fontFamily: terminal.options.fontFamily!,
fontSize: terminal.options.fontSize!,
fontWeight: terminal.options.fontWeight as FontWeight,
fontWeightBold: terminal.options.fontWeightBold as FontWeight,
allowTransparency: terminal.options.allowTransparency!,
drawBoldTextInBrightColors: terminal.options.drawBoldTextInBrightColors!,
minimumContrastRatio: terminal.options.minimumContrastRatio!,
fontFamily: terminal.options.fontFamily,
fontSize: terminal.options.fontSize,
fontWeight: terminal.options.fontWeight,
fontWeightBold: terminal.options.fontWeightBold,
allowTransparency: terminal.options.allowTransparency,
drawBoldTextInBrightColors: terminal.options.drawBoldTextInBrightColors,
minimumContrastRatio: terminal.options.minimumContrastRatio,
colors: clonedColors
};
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ export class CursorRenderLayer extends BaseRenderLayer {
private _renderBarCursor(terminal: Terminal, x: number, y: number, cell: ICellData): void {
this._ctx.save();
this._ctx.fillStyle = this._colors.cursor.css;
this._fillLeftLineAtCell(x, y, terminal.options.cursorWidth!);
this._fillLeftLineAtCell(x, y, terminal.options.cursorWidth);
this._ctx.restore();
}

Expand Down
2 changes: 1 addition & 1 deletion demo/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -344,7 +344,7 @@ function initOptions(term: TerminalType): void {
];
const stringOptions = {
cursorStyle: ['block', 'underline', 'bar'],
fastScrollModifier: ['alt', 'ctrl', 'shift', undefined],
fastScrollModifier: ['none', 'alt', 'ctrl', 'shift'],
fontFamily: null,
fontWeight: ['normal', 'bold', '100', '200', '300', '400', '500', '600', '700', '800', '900'],
fontWeightBold: ['normal', 'bold', '100', '200', '300', '400', '500', '600', '700', '800', '900'],
Expand Down
2 changes: 1 addition & 1 deletion src/browser/TestUtils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ export class MockTerminal implements ITerminal {
public renderer!: IRenderer;
public linkifier2!: ILinkifier2;
public isFocused!: boolean;
public options: ITerminalOptions = {};
public options!: Required<ITerminalOptions>;
public element!: HTMLElement;
public screenElement!: HTMLElement;
public rowContainer!: HTMLElement;
Expand Down
2 changes: 1 addition & 1 deletion src/browser/Types.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ export interface ITerminal extends IPublicTerminal, ICoreTerminal {
browser: IBrowser;
buffer: IBuffer;
viewport: IViewport | undefined;
options: ITerminalOptions;
options: Required<ITerminalOptions>;
linkifier2: ILinkifier2;

onBlur: IEvent<void>;
Expand Down
4 changes: 2 additions & 2 deletions src/browser/public/Terminal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export class Terminal implements ITerminalApi {
private _addonManager: AddonManager;
private _parser: IParser | undefined;
private _buffer: BufferNamespaceApi | undefined;
private _publicOptions: ITerminalOptions;
private _publicOptions: Required<ITerminalOptions>;

constructor(options?: ITerminalOptions) {
this._core = new TerminalCore(options);
Expand Down Expand Up @@ -123,7 +123,7 @@ export class Terminal implements ITerminalApi {
wraparoundMode: m.wraparound
};
}
public get options(): ITerminalOptions {
public get options(): Required<ITerminalOptions> {
return this._publicOptions;
}
public set options(options: ITerminalOptions) {
Expand Down
2 changes: 1 addition & 1 deletion src/common/CoreTerminal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ export abstract class CoreTerminal extends Disposable implements ICoreTerminal {
public get cols(): number { return this._bufferService.cols; }
public get rows(): number { return this._bufferService.rows; }
public get buffers(): IBufferSet { return this._bufferService.buffers; }
public get options(): ITerminalOptions { return this.optionsService.options; }
public get options(): Required<ITerminalOptions> { return this.optionsService.options; }
public set options(options: ITerminalOptions) {
for (const key in options) {
this.optionsService.options[key] = options[key];
Expand Down
4 changes: 2 additions & 2 deletions src/common/TestUtils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,8 @@ export class MockLogService implements ILogService {

export class MockOptionsService implements IOptionsService {
public serviceBrand: any;
public readonly rawOptions: ITerminalOptions = clone(DEFAULT_OPTIONS);
public options: ITerminalOptions = this.rawOptions;
public readonly rawOptions: Required<ITerminalOptions> = clone(DEFAULT_OPTIONS);
public options: Required<ITerminalOptions> = this.rawOptions;
public onOptionChange: IEvent<string> = new EventEmitter<string>().event;
constructor(testOptions?: Partial<ITerminalOptions>) {
if (testOptions) {
Expand Down
8 changes: 4 additions & 4 deletions src/common/services/OptionsService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { EventEmitter, IEvent } from 'common/EventEmitter';
import { isMac } from 'common/Platform';
import { CursorStyle } from 'common/Types';

export const DEFAULT_OPTIONS: Readonly<ITerminalOptions> = {
export const DEFAULT_OPTIONS: Readonly<Required<ITerminalOptions>> = {
cols: 80,
rows: 24,
cursorBlink: false,
Expand Down Expand Up @@ -46,16 +46,16 @@ export const DEFAULT_OPTIONS: Readonly<ITerminalOptions> = {
convertEol: false,
termName: 'xterm',
cancelEvents: false,
overviewRulerWidth: undefined
overviewRulerWidth: 0
};

const FONT_WEIGHT_OPTIONS: Extract<FontWeight, string>[] = ['normal', 'bold', '100', '200', '300', '400', '500', '600', '700', '800', '900'];

export class OptionsService implements IOptionsService {
public serviceBrand: any;

public readonly rawOptions: ITerminalOptions;
public options: ITerminalOptions;
public readonly rawOptions: Required<ITerminalOptions>;
public options: Required<ITerminalOptions>;

private _onOptionChange = new EventEmitter<string>();
public get onOptionChange(): IEvent<string> { return this._onOptionChange.event; }
Expand Down
74 changes: 37 additions & 37 deletions src/common/services/Services.ts
Original file line number Diff line number Diff line change
Expand Up @@ -194,8 +194,8 @@ export interface IOptionsService {
* single options without any validation as we trust TypeScript to enforce correct usage
* internally.
*/
readonly rawOptions: Readonly<ITerminalOptions>;
readonly options: ITerminalOptions;
readonly rawOptions: Required<ITerminalOptions>;
readonly options: Required<ITerminalOptions>;

readonly onOptionChange: IEvent<string>;
}
Expand All @@ -204,41 +204,41 @@ export type FontWeight = 'normal' | 'bold' | '100' | '200' | '300' | '400' | '50
export type LogLevel = 'debug' | 'info' | 'warn' | 'error' | 'off';

export interface ITerminalOptions {
allowProposedApi: boolean;
allowTransparency: boolean;
altClickMovesCursor: boolean;
cols: number;
convertEol: boolean;
cursorBlink: boolean;
cursorStyle: CursorStyle;
cursorWidth: number;
customGlyphs: boolean;
disableStdin: boolean;
drawBoldTextInBrightColors: boolean;
fastScrollModifier: 'alt' | 'ctrl' | 'shift' | undefined;
fastScrollSensitivity: number;
fontSize: number;
fontFamily: string;
fontWeight: FontWeight;
fontWeightBold: FontWeight;
letterSpacing: number;
lineHeight: number;
linkHandler: ILinkHandler | null;
logLevel: LogLevel;
macOptionIsMeta: boolean;
macOptionClickForcesSelection: boolean;
minimumContrastRatio: number;
rightClickSelectsWord: boolean;
rows: number;
screenReaderMode: boolean;
scrollback: number;
scrollSensitivity: number;
smoothScrollDuration: number;
tabStopWidth: number;
theme: ITheme;
windowsMode: boolean;
windowOptions: IWindowOptions;
wordSeparator: string;
allowProposedApi?: boolean;
allowTransparency?: boolean;
altClickMovesCursor?: boolean;
cols?: number;
convertEol?: boolean;
cursorBlink?: boolean;
cursorStyle?: CursorStyle;
cursorWidth?: number;
customGlyphs?: boolean;
disableStdin?: boolean;
drawBoldTextInBrightColors?: boolean;
fastScrollModifier?: 'none' | 'alt' | 'ctrl' | 'shift';
fastScrollSensitivity?: number;
fontSize?: number;
fontFamily?: string;
fontWeight?: FontWeight;
fontWeightBold?: FontWeight;
letterSpacing?: number;
lineHeight?: number;
linkHandler?: ILinkHandler | null;
logLevel?: LogLevel;
macOptionIsMeta?: boolean;
macOptionClickForcesSelection?: boolean;
minimumContrastRatio?: number;
rightClickSelectsWord?: boolean;
rows?: number;
screenReaderMode?: boolean;
scrollback?: number;
scrollSensitivity?: number;
smoothScrollDuration?: number;
tabStopWidth?: number;
theme?: ITheme;
windowsMode?: boolean;
windowOptions?: IWindowOptions;
wordSeparator?: string;
overviewRulerWidth?: number;

[key: string]: any;
Expand Down
2 changes: 1 addition & 1 deletion src/headless/Terminal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ import { IMarker, ITerminalOptions, ScrollSource } from 'common/Types';

export class Terminal extends CoreTerminal {
// TODO: We should remove options once components adopt optionsService
public get options(): IInitializedTerminalOptions { return this.optionsService.options; }
public get options(): Required<IInitializedTerminalOptions> { return this.optionsService.options; }

private _onBell = new EventEmitter<void>();
public get onBell(): IEvent<void> { return this._onBell.event; }
Expand Down
4 changes: 2 additions & 2 deletions src/headless/public/Terminal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export class Terminal implements ITerminalApi {
private _addonManager: AddonManager;
private _parser: IParser | undefined;
private _buffer: BufferNamespaceApi | undefined;
private _publicOptions: ITerminalOptions;
private _publicOptions: Required<ITerminalOptions>;

constructor(options?: ITerminalOptions & ITerminalInitOnlyOptions) {
this._core = new TerminalCore(options);
Expand Down Expand Up @@ -123,7 +123,7 @@ export class Terminal implements ITerminalApi {
wraparoundMode: m.wraparound
};
}
public get options(): ITerminalOptions {
public get options(): Required<ITerminalOptions> {
return this._publicOptions;
}
public set options(options: ITerminalOptions) {
Expand Down
9 changes: 7 additions & 2 deletions typings/xterm-headless.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ declare module 'xterm-headless' {
/**
* The modifier key hold to multiply scroll speed.
*/
fastScrollModifier?: 'alt' | 'ctrl' | 'shift' | undefined;
fastScrollModifier?: 'none' | 'alt' | 'ctrl' | 'shift';

/**
* The spacing in whole pixels between characters.
Expand Down Expand Up @@ -538,6 +538,11 @@ declare module 'xterm-headless' {
* ```typescript
* console.log(terminal.options.fontSize);
* ```
*/
get options(): Required<ITerminalOptions>;

/**
* Gets or sets the terminal options. This supports setting multiple options.
*
* @example Set a single option
* ```typescript
Expand All @@ -552,7 +557,7 @@ declare module 'xterm-headless' {
* };
* ```
*/
options: ITerminalOptions;
set options(options: ITerminalOptions);

/**
* Natural language strings that can be localized.
Expand Down
11 changes: 8 additions & 3 deletions typings/xterm.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ declare module 'xterm' {
/**
* The modifier key hold to multiply scroll speed.
*/
fastScrollModifier?: 'alt' | 'ctrl' | 'shift' | undefined;
fastScrollModifier?: 'none' | 'alt' | 'ctrl' | 'shift';

/**
* The scroll speed multiplier used for fast scrolling.
Expand Down Expand Up @@ -708,6 +708,11 @@ declare module 'xterm' {
* ```typescript
* console.log(terminal.options.fontSize);
* ```
*/
get options(): Required<ITerminalOptions>;

/**
* Gets or sets the terminal options. This supports setting multiple options.
*
* @example Set a single option
* ```typescript
Expand All @@ -722,7 +727,7 @@ declare module 'xterm' {
* };
* ```
*/
options: ITerminalOptions;
set options(options: ITerminalOptions);

/**
* Natural language strings that can be localized.
Expand Down Expand Up @@ -1077,7 +1082,7 @@ declare module 'xterm' {
/**
* An object representing a range within the viewport of the terminal.
*/
export interface IViewportRange {
export interface IViewportRange {
/**
* The start of the range.
*/
Expand Down