ParamsArray to Types.ts

This commit is contained in:
Jörg Breitbart
2019-07-04 12:12:11 +02:00
parent 69dcabbfce
commit 6bcd8e3bfd
4 changed files with 11 additions and 9 deletions
@@ -3,14 +3,13 @@
* @license MIT
*/
import { IDcsHandler, IParsingState, IParams } from 'common/parser/Types';
import { IDcsHandler, IParsingState, IParams, ParamsArray } from 'common/parser/Types';
import { EscapeSequenceParser, TransitionTable, VT500_TRANSITION_TABLE } from 'common/parser/EscapeSequenceParser';
import * as chai from 'chai';
import { StringToUtf32, stringFromCodePoint } from 'common/input/TextDecoder';
import { ParserState } from 'common/parser/Constants';
import { Params } from 'common/parser/Params';
type ParamsArray = (number | number[])[];
function r(a: number, b: number): string[] {
let c = b - a;
@@ -30,7 +29,7 @@ class TestEscapeSequenceParser extends EscapeSequenceParser {
this._osc = value;
}
public get params(): ParamsArray {
return this._params.toArray() as ParamsArray;
return this._params.toArray();
}
public set params(value: ParamsArray) {
this._params = Params.fromArray(value);
+2 -1
View File
@@ -4,6 +4,7 @@
*/
import { assert } from 'chai';
import { Params } from 'common/parser/Params';
import { ParamsArray } from 'common/parser/Types';
class TestParams extends Params {
public get subParams(): Int32Array {
@@ -108,7 +109,7 @@ describe('Params', () => {
assert.deepEqual(params.toArray(), [1, [2, 3], 12345, [-1]]);
});
it('Params.fromArray --> toArray', () => {
let data: (number | number[])[] = [];
let data: ParamsArray = [];
assert.deepEqual(Params.fromArray(data).toArray(), data);
data = [1, [2, 3], 12345, [-1]];
assert.deepEqual(Params.fromArray(data).toArray(), data);
+4 -4
View File
@@ -2,7 +2,7 @@
* Copyright (c) 2019 The xterm.js authors. All rights reserved.
* @license MIT
*/
import { IParams } from 'common/parser/Types';
import { IParams, ParamsArray } from 'common/parser/Types';
// max value supported for a single param/subparam (clamped to positive int32 range)
const MAX_VALUE = 0x7FFFFFFF;
@@ -57,7 +57,7 @@ export class Params implements IParams {
/**
* Create a `Params` type from JS array representation.
*/
public static fromArray(values: (number | number[])[]): Params {
public static fromArray(values: ParamsArray): Params {
const params = new Params();
if (!values.length) {
return params;
@@ -112,8 +112,8 @@ export class Params implements IParams {
* sequence: "1;2:3:4;5::6"
* array : [1, 2, [3, 4], 5, [-1, 6]]
*/
public toArray(): (number | number[])[] {
const res: (number | number[])[] = [];
public toArray(): ParamsArray {
const res: ParamsArray = [];
for (let i = 0; i < this.length; ++i) {
res.push(this.params[i]);
const start = this._subParamsIdx[i] >> 8;
+3 -1
View File
@@ -16,6 +16,8 @@ export interface IParamsConstructor {
fromArray(values: (number | number[])[]): IParams;
}
export type ParamsArray = (number | number[])[];
export interface IParams {
/** from ctor */
maxLength: number;
@@ -27,7 +29,7 @@ export interface IParams {
/** methods */
clone(): IParams;
toArray(): (number | number[])[];
toArray(): ParamsArray;
reset(): void;
addParam(value: number): void;
addSubParam(value: number): void;