2 * Copyright (c) 2019 The xterm.js authors. All rights reserved.
6 import { ICoreService, ILogService, IOptionsService, IBufferService } from 'common/services/Services';
7 import { EventEmitter, IEvent } from 'common/EventEmitter';
8 import { IDecPrivateModes } from 'common/Types';
9 import { clone } from 'common/Clone';
11 const DEFAULT_DEC_PRIVATE_MODES: IDecPrivateModes = Object.freeze({
12 applicationCursorKeys: false
15 export class CoreService implements ICoreService {
18 public decPrivateModes: IDecPrivateModes;
20 private _onData = new EventEmitter<string>();
21 public get onData(): IEvent<string> { return this._onData.event; }
22 private _onUserInput = new EventEmitter<void>();
23 public get onUserInput(): IEvent<void> { return this._onUserInput.event; }
26 // TODO: Move this into a service
27 private readonly _scrollToBottom: () => void,
28 @IBufferService private readonly _bufferService: IBufferService,
29 @ILogService private readonly _logService: ILogService,
30 @IOptionsService private readonly _optionsService: IOptionsService
32 this.decPrivateModes = clone(DEFAULT_DEC_PRIVATE_MODES);
35 public reset(): void {
36 this.decPrivateModes = clone(DEFAULT_DEC_PRIVATE_MODES);
39 public triggerDataEvent(data: string, wasUserInput: boolean = false): void {
40 // Prevents all events to pty process if stdin is disabled
41 if (this._optionsService.options.disableStdin) {
45 // Input is being sent to the terminal, the terminal should focus the prompt.
46 const buffer = this._bufferService.buffer;
47 if (buffer.ybase !== buffer.ydisp) {
48 this._scrollToBottom();
51 // Fire onUserInput so listeners can react as well (eg. clear selection)
53 this._onUserInput.fire();
57 this._logService.debug(`sending data "${data}"`, () => data.split('').map(e => e.charCodeAt(0)));
58 this._onData.fire(data);