Skip to content

Commit 2f0a7ee

Browse files
authored
Merge pull request #4679 from Tyriar/4663
Reduce repetition with internal terminal types and inherit docs from API
2 parents 1a3e14a + a6b67fb commit 2f0a7ee

File tree

7 files changed

+12
-111
lines changed

7 files changed

+12
-111
lines changed

src/browser/Terminal.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -920,7 +920,7 @@ export class Terminal extends CoreTerminal implements ITerminal {
920920
return this.buffer.markers;
921921
}
922922

923-
public addMarker(cursorYOffset: number): IMarker {
923+
public registerMarker(cursorYOffset: number): IMarker {
924924
return this.buffer.addMarker(this.buffer.ybase + this.buffer.y + cursorYOffset);
925925
}
926926

src/browser/TestUtils.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ export class MockTerminal implements ITerminal {
5252
public coreService!: ICoreService;
5353
public optionsService!: IOptionsService;
5454
public unicodeService!: IUnicodeService;
55-
public addMarker(cursorYOffset: number): IMarker {
55+
public registerMarker(cursorYOffset: number): IMarker {
5656
throw new Error('Method not implemented.');
5757
}
5858
public selectLines(start: number, end: number): void {

src/browser/Types.d.ts

Lines changed: 7 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,19 @@
33
* @license MIT
44
*/
55

6-
import { IDecorationOptions, IDecoration, IDisposable, IMarker } from 'xterm';
6+
import { IDecorationOptions, IDecoration, IDisposable, IMarker, Terminal as ITerminalApi } from 'xterm';
77
import { IEvent } from 'common/EventEmitter';
88
import { ICoreTerminal, CharData, ITerminalOptions, IColor } from 'common/Types';
99
import { IMouseService, IRenderService } from './services/Services';
1010
import { IBuffer } from 'common/buffer/Types';
1111
import { IFunctionIdentifier, IParams } from 'common/parser/Types';
1212

13-
export interface ITerminal extends IPublicTerminal, ICoreTerminal {
14-
element: HTMLElement | undefined;
13+
/**
14+
* A portion of the public API that are implemented identially internally and simply passed through.
15+
*/
16+
type InternalPassthroughApis = Omit<ITerminalApi, 'buffer' | 'parser' | 'unicode' | 'modes' | 'writeln' | 'loadAddon'>;
17+
18+
export interface ITerminal extends InternalPassthroughApis, ICoreTerminal {
1519
screenElement: HTMLElement | undefined;
1620
browser: IBrowser;
1721
buffer: IBuffer;
@@ -28,78 +32,6 @@ export interface ITerminal extends IPublicTerminal, ICoreTerminal {
2832
cancel(ev: Event, force?: boolean): boolean | void;
2933
}
3034

31-
// Portions of the public API that are required by the internal Terminal
32-
export interface IPublicTerminal extends IDisposable {
33-
textarea: HTMLTextAreaElement | undefined;
34-
rows: number;
35-
cols: number;
36-
buffer: IBuffer;
37-
markers: IMarker[];
38-
onCursorMove: IEvent<void>;
39-
onData: IEvent<string>;
40-
onBinary: IEvent<string>;
41-
onKey: IEvent<{ key: string, domEvent: KeyboardEvent }>;
42-
onLineFeed: IEvent<void>;
43-
onScroll: IEvent<number>;
44-
onSelectionChange: IEvent<void>;
45-
onRender: IEvent<{ start: number, end: number }>;
46-
onResize: IEvent<{ cols: number, rows: number }>;
47-
onWriteParsed: IEvent<void>;
48-
onTitleChange: IEvent<string>;
49-
onBell: IEvent<void>;
50-
blur(): void;
51-
focus(): void;
52-
resize(columns: number, rows: number): void;
53-
open(parent: HTMLElement): void;
54-
attachCustomKeyEventHandler(customKeyEventHandler: (event: KeyboardEvent) => boolean): void;
55-
registerCsiHandler(id: IFunctionIdentifier, callback: (params: IParams) => boolean | Promise<boolean>): IDisposable;
56-
registerDcsHandler(id: IFunctionIdentifier, callback: (data: string, param: IParams) => boolean | Promise<boolean>): IDisposable;
57-
registerEscHandler(id: IFunctionIdentifier, callback: () => boolean | Promise<boolean>): IDisposable;
58-
registerOscHandler(ident: number, callback: (data: string) => boolean | Promise<boolean>): IDisposable;
59-
registerLinkProvider(linkProvider: ILinkProvider): IDisposable;
60-
registerCharacterJoiner(handler: (text: string) => [number, number][]): number;
61-
deregisterCharacterJoiner(joinerId: number): void;
62-
addMarker(cursorYOffset: number): IMarker;
63-
registerDecoration(decorationOptions: IDecorationOptions): IDecoration | undefined;
64-
hasSelection(): boolean;
65-
getSelection(): string;
66-
getSelectionPosition(): IBufferRange | undefined;
67-
clearSelection(): void;
68-
select(column: number, row: number, length: number): void;
69-
selectAll(): void;
70-
selectLines(start: number, end: number): void;
71-
dispose(): void;
72-
/**
73-
* Scroll the display of the terminal
74-
* @param amount The number of lines to scroll down (negative scroll up).
75-
*/
76-
scrollLines(amount: number): void;
77-
/**
78-
* Scroll the display of the terminal by a number of pages.
79-
* @param pageCount The number of pages to scroll (negative scrolls up).
80-
*/
81-
scrollPages(pageCount: number): void;
82-
/**
83-
* Scrolls the display of the terminal to the top.
84-
*/
85-
scrollToTop(): void;
86-
/**
87-
* Scrolls the display of the terminal to the bottom.
88-
*/
89-
scrollToBottom(): void;
90-
/**
91-
* Scrolls to a line within the buffer.
92-
* @param line The 0-based line index to scroll to.
93-
*/
94-
scrollToLine(line: number): void;
95-
clear(): void;
96-
write(data: string | Uint8Array, callback?: () => void): void;
97-
paste(data: string): void;
98-
refresh(start: number, end: number): void;
99-
clearTextureAtlas(): void;
100-
reset(): void;
101-
}
102-
10335
export type CustomKeyEventHandler = (event: KeyboardEvent) => boolean;
10436

10537
export type LineData = CharData[];

src/browser/public/Terminal.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ export class Terminal extends Disposable implements ITerminalApi {
161161
}
162162
public registerMarker(cursorYOffset: number = 0): IMarker {
163163
this._verifyIntegers(cursorYOffset);
164-
return this._core.addMarker(cursorYOffset);
164+
return this._core.registerMarker(cursorYOffset);
165165
}
166166
public registerDecoration(decorationOptions: IDecorationOptions): IDecoration | undefined {
167167
this._checkProposedApi();

src/common/Types.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ export interface ICoreTerminal {
1717
optionsService: IOptionsService;
1818
unicodeService: IUnicodeService;
1919
buffers: IBufferSet;
20-
options: ITerminalOptions;
20+
options: Required<ITerminalOptions>;
2121
registerCsiHandler(id: IFunctionIdentifier, callback: (params: IParams) => boolean | Promise<boolean>): IDisposable;
2222
registerDcsHandler(id: IFunctionIdentifier, callback: (data: string, param: IParams) => boolean | Promise<boolean>): IDisposable;
2323
registerEscHandler(id: IFunctionIdentifier, callback: () => boolean | Promise<boolean>): IDisposable;

src/headless/Terminal.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
import { DEFAULT_ATTR_DATA } from 'common/buffer/BufferLine';
2525
import { IBuffer } from 'common/buffer/Types';
2626
import { CoreTerminal } from 'common/CoreTerminal';
27-
import { EventEmitter, forwardEvent, IEvent } from 'common/EventEmitter';
27+
import { EventEmitter, forwardEvent } from 'common/EventEmitter';
2828
import { ITerminalOptions as IInitializedTerminalOptions } from 'common/services/Services';
2929
import { IMarker, ITerminalOptions, ScrollSource } from 'common/Types';
3030

src/headless/Types.d.ts

Lines changed: 0 additions & 31 deletions
This file was deleted.

0 commit comments

Comments
 (0)