Skip to content

Commit bc21e49

Browse files
terminal: expose onKey event
The commit exposes the terminal `onKey` event from xterm. Signed-off-by: vince-fugnitto <[email protected]>
1 parent c1a87c1 commit bc21e49

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

packages/terminal/src/browser/base/terminal-widget.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,9 @@ export abstract class TerminalWidget extends BaseWidget {
8080
/** Event that fires when the terminal size changed */
8181
abstract onSizeChanged: Event<{ cols: number; rows: number; }>;
8282

83+
/** Event that fires when the terminal receives a key event. */
84+
abstract onKey: Event<{ key: string, domEvent: KeyboardEvent }>;
85+
8386
/** Event that fires when the terminal input data */
8487
abstract onData: Event<string>;
8588

packages/terminal/src/browser/terminal-widget-impl.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,6 +91,9 @@ export class TerminalWidgetImpl extends TerminalWidget implements StatefulWidget
9191
protected readonly onDataEmitter = new Emitter<string>();
9292
readonly onData: Event<string> = this.onDataEmitter.event;
9393

94+
protected readonly onKeyEmitter = new Emitter<{ key: string, domEvent: KeyboardEvent }>();
95+
readonly onKey: Event<{ key: string, domEvent: KeyboardEvent }> = this.onKeyEmitter.event;
96+
9497
protected readonly toDisposeOnConnect = new DisposableCollection();
9598

9699
@postConstruct()
@@ -213,6 +216,7 @@ export class TerminalWidgetImpl extends TerminalWidget implements StatefulWidget
213216
this.toDispose.push(this.onDidOpenFailureEmitter);
214217
this.toDispose.push(this.onSizeChangedEmitter);
215218
this.toDispose.push(this.onDataEmitter);
219+
this.toDispose.push(this.onKeyEmitter);
216220

217221
const touchEndListener = (event: TouchEvent) => {
218222
if (this.node.contains(event.target as Node)) {
@@ -242,6 +246,10 @@ export class TerminalWidgetImpl extends TerminalWidget implements StatefulWidget
242246
this.onDataEmitter.fire(data);
243247
}));
244248

249+
this.toDispose.push(this.term.onKey(data => {
250+
this.onKeyEmitter.fire(data);
251+
}));
252+
245253
for (const contribution of this.terminalContributionProvider.getContributions()) {
246254
contribution.onCreate(this);
247255
}

0 commit comments

Comments
 (0)