@@ -3,7 +3,7 @@
|
||||
* @license MIT
|
||||
*/
|
||||
|
||||
import { IBufferService, ICoreService, IOptionsService, ITerminalOptions, IPartialTerminalOptions } from 'common/services/Services';
|
||||
import { IBufferService, ICoreService, ILogService, 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';
|
||||
@@ -36,6 +36,13 @@ export class MockCoreService implements ICoreService {
|
||||
triggerDataEvent(data: string, wasUserInput?: boolean): void {}
|
||||
}
|
||||
|
||||
export class MockLogService implements ILogService {
|
||||
debug(message: any, ...optionalParams: any[]): void {}
|
||||
info(message: any, ...optionalParams: any[]): void {}
|
||||
warn(message: any, ...optionalParams: any[]): void {}
|
||||
error(message: any, ...optionalParams: any[]): void {}
|
||||
}
|
||||
|
||||
export class MockOptionsService implements IOptionsService {
|
||||
options: ITerminalOptions = clone(DEFAULT_OPTIONS);
|
||||
onOptionChange: IEvent<string> = new EventEmitter<string>().event;
|
||||
|
||||
@@ -0,0 +1,78 @@
|
||||
/**
|
||||
* Copyright (c) 2019 The xterm.js authors. All rights reserved.
|
||||
* @license MIT
|
||||
*/
|
||||
|
||||
import { ILogService, IOptionsService } from 'common/services/Services';
|
||||
|
||||
interface IConsole {
|
||||
log(message?: any, ...optionalParams: any[]): void;
|
||||
error(message?: any, ...optionalParams: any[]): void;
|
||||
info(message?: any, ...optionalParams: any[]): void;
|
||||
trace(message?: any, ...optionalParams: any[]): void;
|
||||
warn(message?: any, ...optionalParams: any[]): void;
|
||||
}
|
||||
|
||||
// console is available on both node.js and browser contexts but the common
|
||||
// module doesn't depend on them so we need to explicitly declare it.
|
||||
declare const console: IConsole;
|
||||
|
||||
|
||||
export enum LogLevel {
|
||||
Debug = 0,
|
||||
Info = 1,
|
||||
Warn = 2,
|
||||
Error = 3,
|
||||
Off = 4
|
||||
}
|
||||
|
||||
const optionsKeyToLogLevel: { [key: string]: LogLevel } = {
|
||||
debug: LogLevel.Debug,
|
||||
info: LogLevel.Info,
|
||||
warn: LogLevel.Warn,
|
||||
error: LogLevel.Error,
|
||||
off: LogLevel.Off
|
||||
};
|
||||
|
||||
export class LogService implements ILogService {
|
||||
private _logLevel!: LogLevel;
|
||||
|
||||
constructor(
|
||||
private readonly _optionsService: IOptionsService
|
||||
) {
|
||||
this._updateLogLevel();
|
||||
this._optionsService.onOptionChange(key => {
|
||||
if (key === 'logLevel') {
|
||||
this._updateLogLevel();
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
private _updateLogLevel(): void {
|
||||
this._logLevel = optionsKeyToLogLevel[this._optionsService.options.logLevel];
|
||||
}
|
||||
|
||||
debug(message: any, ...optionalParams: any[]): void {
|
||||
if (this._logLevel <= LogLevel.Debug) {
|
||||
console.log.call(console, message, optionalParams);
|
||||
}
|
||||
}
|
||||
|
||||
info(message: any, ...optionalParams: any[]): void {
|
||||
if (this._logLevel <= LogLevel.Info) {
|
||||
console.info.call(console, message, optionalParams);
|
||||
}
|
||||
}
|
||||
|
||||
warn(message: any, ...optionalParams: any[]): void {
|
||||
if (this._logLevel <= LogLevel.Warn) {
|
||||
console.warn.call(console, message, optionalParams);
|
||||
}
|
||||
}
|
||||
|
||||
error(message: any, ...optionalParams: any[]): void {
|
||||
if (this._logLevel <= LogLevel.Error) {
|
||||
console.error.call(console, message, optionalParams);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -29,6 +29,7 @@ export const DEFAULT_OPTIONS: ITerminalOptions = Object.freeze({
|
||||
fontWeightBold: 'bold',
|
||||
lineHeight: 1.0,
|
||||
letterSpacing: 0,
|
||||
logLevel: 'info',
|
||||
scrollback: 1000,
|
||||
screenReaderMode: false,
|
||||
macOptionIsMeta: false,
|
||||
|
||||
Vendored
+11
-2
@@ -38,6 +38,13 @@ export interface ICoreService {
|
||||
triggerDataEvent(data: string, wasUserInput?: boolean): void;
|
||||
}
|
||||
|
||||
export interface ILogService {
|
||||
debug(message: any, ...optionalParams: any[]): void;
|
||||
info(message: any, ...optionalParams: any[]): void;
|
||||
warn(message: any, ...optionalParams: any[]): void;
|
||||
error(message: any, ...optionalParams: any[]): void;
|
||||
}
|
||||
|
||||
export interface IOptionsService {
|
||||
readonly options: ITerminalOptions;
|
||||
|
||||
@@ -48,7 +55,7 @@ export interface IOptionsService {
|
||||
}
|
||||
|
||||
export type FontWeight = 'normal' | 'bold' | '100' | '200' | '300' | '400' | '500' | '600' | '700' | '800' | '900';
|
||||
|
||||
export type LogLevel = 'debug' | 'info' | 'warn' | 'error' | 'off';
|
||||
export type RendererType = 'dom' | 'canvas';
|
||||
|
||||
export interface IPartialTerminalOptions {
|
||||
@@ -66,6 +73,7 @@ export interface IPartialTerminalOptions {
|
||||
fontWeightBold?: FontWeight;
|
||||
letterSpacing?: number;
|
||||
lineHeight?: number;
|
||||
logLevel?: LogLevel;
|
||||
macOptionIsMeta?: boolean;
|
||||
macOptionClickForcesSelection?: boolean;
|
||||
rendererType?: RendererType;
|
||||
@@ -86,6 +94,7 @@ export interface ITerminalOptions {
|
||||
cols: number;
|
||||
cursorBlink: boolean;
|
||||
cursorStyle: 'block' | 'underline' | 'bar';
|
||||
debug: boolean;
|
||||
disableStdin: boolean;
|
||||
drawBoldTextInBrightColors: boolean;
|
||||
fontSize: number;
|
||||
@@ -94,6 +103,7 @@ export interface ITerminalOptions {
|
||||
fontWeightBold: FontWeight;
|
||||
letterSpacing: number;
|
||||
lineHeight: number;
|
||||
logLevel: LogLevel;
|
||||
macOptionIsMeta: boolean;
|
||||
macOptionClickForcesSelection: boolean;
|
||||
rendererType: RendererType;
|
||||
@@ -109,7 +119,6 @@ export interface ITerminalOptions {
|
||||
[key: string]: any;
|
||||
cancelEvents: boolean;
|
||||
convertEol: boolean;
|
||||
debug: boolean;
|
||||
screenKeys: boolean;
|
||||
termName: string;
|
||||
useFlowControl: boolean;
|
||||
|
||||
Reference in New Issue
Block a user