Merge branch 'master' into parser_colon_notation
This commit is contained in:
@@ -3,7 +3,7 @@
|
||||
* @license MIT
|
||||
*/
|
||||
|
||||
import { IBufferService, IOptionsService, ITerminalOptions, IPartialTerminalOptions } from 'common/services/Services';
|
||||
import { IBufferService, ICoreService, IOptionsService, ITerminalOptions, IPartialTerminalOptions } from 'common/services/Services';
|
||||
import { IEvent, EventEmitter } from 'common/EventEmitter';
|
||||
import { clone } from 'common/Clone';
|
||||
import { DEFAULT_OPTIONS } from 'common/services/OptionsService';
|
||||
@@ -27,6 +27,12 @@ export class MockBufferService implements IBufferService {
|
||||
reset(): void {}
|
||||
}
|
||||
|
||||
export class MockCoreService implements ICoreService {
|
||||
onData: IEvent<string> = new EventEmitter<string>().event;
|
||||
onUserInput: IEvent<void> = new EventEmitter<void>().event;
|
||||
triggerDataEvent(data: string, wasUserInput?: boolean): void {}
|
||||
}
|
||||
|
||||
export class MockOptionsService implements IOptionsService {
|
||||
options: ITerminalOptions = clone(DEFAULT_OPTIONS);
|
||||
onOptionChange: IEvent<string> = new EventEmitter<string>().event;
|
||||
|
||||
@@ -0,0 +1,43 @@
|
||||
/**
|
||||
* Copyright (c) 2019 The xterm.js authors. All rights reserved.
|
||||
* @license MIT
|
||||
*/
|
||||
|
||||
import { ICoreService, IOptionsService, IBufferService } from 'common/services/Services';
|
||||
import { EventEmitter, IEvent } from 'common/EventEmitter';
|
||||
|
||||
export class CoreService implements ICoreService {
|
||||
private _onData = new EventEmitter<string>();
|
||||
public get onData(): IEvent<string> { return this._onData.event; }
|
||||
private _onUserInput = new EventEmitter<void>();
|
||||
public get onUserInput(): IEvent<void> { return this._onUserInput.event; }
|
||||
|
||||
constructor(
|
||||
// TODO: Move this into a service
|
||||
private readonly _scrollToBottom: () => void,
|
||||
private readonly _bufferService: IBufferService,
|
||||
private readonly _optionsService: IOptionsService
|
||||
) {
|
||||
}
|
||||
|
||||
public triggerDataEvent(data: string, wasUserInput: boolean = false): void {
|
||||
// Prevents all events to pty process if stdin is disabled
|
||||
if (this._optionsService.options.disableStdin) {
|
||||
return;
|
||||
}
|
||||
|
||||
// Input is being sent to the terminal, the terminal should focus the prompt.
|
||||
const buffer = this._bufferService.buffer;
|
||||
if (buffer.ybase !== buffer.ydisp) {
|
||||
this._scrollToBottom();
|
||||
}
|
||||
|
||||
// Fire onUserInput so listeners can react as well (eg. clear selection)
|
||||
if (wasUserInput) {
|
||||
this._onUserInput.fire();
|
||||
}
|
||||
|
||||
// Fire onData API
|
||||
this._onData.fire(data);
|
||||
}
|
||||
}
|
||||
@@ -46,7 +46,8 @@ export const DEFAULT_OPTIONS: ITerminalOptions = Object.freeze({
|
||||
screenKeys: false,
|
||||
debug: false,
|
||||
cancelEvents: false,
|
||||
useFlowControl: false
|
||||
useFlowControl: false,
|
||||
wordSeparator: ' ()[]{}\'"'
|
||||
});
|
||||
|
||||
/**
|
||||
@@ -99,6 +100,7 @@ export class OptionsService implements IOptionsService {
|
||||
case 'fontWeight':
|
||||
case 'fontWeightBold':
|
||||
case 'rendererType':
|
||||
case 'wordSeparator':
|
||||
if (!value) {
|
||||
value = DEFAULT_OPTIONS[key];
|
||||
}
|
||||
|
||||
Vendored
+17
@@ -18,6 +18,21 @@ export interface IBufferService {
|
||||
reset(): void;
|
||||
}
|
||||
|
||||
export interface ICoreService {
|
||||
readonly onData: IEvent<string>;
|
||||
readonly onUserInput: IEvent<void>;
|
||||
|
||||
/**
|
||||
* Triggers the onData event in the public API.
|
||||
* @param data The data that is being emitted.
|
||||
* @param wasFromUser Whether the data originated from the user (as opposed to
|
||||
* resulting from parsing incoming data). When true this will also:
|
||||
* - Scroll to the bottom of the buffer.s
|
||||
* - Fire the `onUserInput` event (so selection can be cleared).
|
||||
*/
|
||||
triggerDataEvent(data: string, wasUserInput?: boolean): void;
|
||||
}
|
||||
|
||||
export interface IOptionsService {
|
||||
readonly options: ITerminalOptions;
|
||||
|
||||
@@ -56,6 +71,7 @@ export interface IPartialTerminalOptions {
|
||||
tabStopWidth?: number;
|
||||
theme?: ITheme;
|
||||
windowsMode?: boolean;
|
||||
wordSeparator?: string;
|
||||
}
|
||||
|
||||
export interface ITerminalOptions {
|
||||
@@ -91,6 +107,7 @@ export interface ITerminalOptions {
|
||||
screenKeys: boolean;
|
||||
termName: string;
|
||||
useFlowControl: boolean;
|
||||
wordSeparator?: string;
|
||||
}
|
||||
|
||||
export interface ITheme {
|
||||
|
||||
Reference in New Issue
Block a user