cleanup interface
This commit is contained in:
@@ -5,6 +5,15 @@
|
|||||||
import { assert } from 'chai';
|
import { assert } from 'chai';
|
||||||
import { Params } from 'common/parser/Params';
|
import { Params } from 'common/parser/Params';
|
||||||
|
|
||||||
|
class TestParams extends Params {
|
||||||
|
public get subParams(): Int16Array {
|
||||||
|
return this._subParams;
|
||||||
|
}
|
||||||
|
public get subParamsLength(): number {
|
||||||
|
return this._subParamsLength;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/** `Params` parser shim */
|
/** `Params` parser shim */
|
||||||
function parse(params: Params, s: string): void {
|
function parse(params: Params, s: string): void {
|
||||||
params.reset();
|
params.reset();
|
||||||
@@ -33,13 +42,13 @@ function parse(params: Params, s: string): void {
|
|||||||
|
|
||||||
describe('Params', () => {
|
describe('Params', () => {
|
||||||
it('should respect ctor args', () => {
|
it('should respect ctor args', () => {
|
||||||
const params = new Params(12, 23);
|
const params = new TestParams(12, 23);
|
||||||
assert.equal(params.params.length, 12);
|
assert.equal(params.params.length, 12);
|
||||||
assert.equal(params.subParams.length, 23);
|
assert.equal(params.subParams.length, 23);
|
||||||
assert.deepEqual(params.toArray(), []);
|
assert.deepEqual(params.toArray(), []);
|
||||||
});
|
});
|
||||||
it('addParam', () => {
|
it('addParam', () => {
|
||||||
const params = new Params();
|
const params = new TestParams();
|
||||||
params.addParam(1);
|
params.addParam(1);
|
||||||
assert.equal(params.length, 1);
|
assert.equal(params.length, 1);
|
||||||
assert.deepEqual(Array.prototype.slice.call(params.params, 0, params.length), [1]);
|
assert.deepEqual(Array.prototype.slice.call(params.params, 0, params.length), [1]);
|
||||||
@@ -51,7 +60,7 @@ describe('Params', () => {
|
|||||||
assert.equal(params.subParamsLength, 0);
|
assert.equal(params.subParamsLength, 0);
|
||||||
});
|
});
|
||||||
it('addSubParam', () => {
|
it('addSubParam', () => {
|
||||||
const params = new Params();
|
const params = new TestParams();
|
||||||
params.addParam(1);
|
params.addParam(1);
|
||||||
params.addSubParam(2);
|
params.addSubParam(2);
|
||||||
params.addSubParam(3);
|
params.addSubParam(3);
|
||||||
@@ -65,7 +74,7 @@ describe('Params', () => {
|
|||||||
assert.deepEqual(params.toArray(), [1, [2, 3], 12345, [-1]]);
|
assert.deepEqual(params.toArray(), [1, [2, 3], 12345, [-1]]);
|
||||||
});
|
});
|
||||||
it('should not add sub params without previous param', () => {
|
it('should not add sub params without previous param', () => {
|
||||||
const params = new Params();
|
const params = new TestParams();
|
||||||
params.addSubParam(2);
|
params.addSubParam(2);
|
||||||
params.addSubParam(3);
|
params.addSubParam(3);
|
||||||
assert.equal(params.length, 0);
|
assert.equal(params.length, 0);
|
||||||
@@ -79,7 +88,7 @@ describe('Params', () => {
|
|||||||
assert.deepEqual(params.toArray(), [1, [2, 3]]);
|
assert.deepEqual(params.toArray(), [1, [2, 3]]);
|
||||||
});
|
});
|
||||||
it('reset', () => {
|
it('reset', () => {
|
||||||
const params = new Params();
|
const params = new TestParams();
|
||||||
params.addParam(1);
|
params.addParam(1);
|
||||||
params.addSubParam(2);
|
params.addSubParam(2);
|
||||||
params.addSubParam(3);
|
params.addSubParam(3);
|
||||||
|
|||||||
+18
-18
@@ -34,14 +34,14 @@ import { IParams } from 'common/parser/Types';
|
|||||||
* - max. value for a single (sub) param is 2^15 (caveat: will overflow to negative values)
|
* - max. value for a single (sub) param is 2^15 (caveat: will overflow to negative values)
|
||||||
* - max. 256 sub params possible
|
* - max. 256 sub params possible
|
||||||
*/
|
*/
|
||||||
export class Params implements IParams {
|
export class Params {
|
||||||
// params store and length
|
// params store and length
|
||||||
public params: Int16Array;
|
public params: Int16Array;
|
||||||
public length: number;
|
public length: number;
|
||||||
|
|
||||||
// sub params store and length
|
// sub params store and length
|
||||||
public subParams: Int16Array;
|
protected _subParams: Int16Array;
|
||||||
public subParamsLength: number;
|
protected _subParamsLength: number;
|
||||||
|
|
||||||
// sub params offsets from param: param idx --> [start, end] offset
|
// sub params offsets from param: param idx --> [start, end] offset
|
||||||
private _subParamsIdx: Uint16Array;
|
private _subParamsIdx: Uint16Array;
|
||||||
@@ -81,8 +81,8 @@ export class Params implements IParams {
|
|||||||
}
|
}
|
||||||
this.params = new Int16Array(maxLength);
|
this.params = new Int16Array(maxLength);
|
||||||
this.length = 0;
|
this.length = 0;
|
||||||
this.subParams = new Int16Array(maxSubParamsLength);
|
this._subParams = new Int16Array(maxSubParamsLength);
|
||||||
this.subParamsLength = 0;
|
this._subParamsLength = 0;
|
||||||
this._subParamsIdx = new Uint16Array(maxLength);
|
this._subParamsIdx = new Uint16Array(maxLength);
|
||||||
this._rejectDigits = false;
|
this._rejectDigits = false;
|
||||||
this._rejectSubDigits = false;
|
this._rejectSubDigits = false;
|
||||||
@@ -95,8 +95,8 @@ export class Params implements IParams {
|
|||||||
const newParams = new Params(this.maxLength, this.maxSubParamsLength);
|
const newParams = new Params(this.maxLength, this.maxSubParamsLength);
|
||||||
newParams.params.set(this.params);
|
newParams.params.set(this.params);
|
||||||
newParams.length = this.length;
|
newParams.length = this.length;
|
||||||
newParams.subParams.set(this.subParams);
|
newParams._subParams.set(this._subParams);
|
||||||
newParams.subParamsLength = this.subParamsLength;
|
newParams._subParamsLength = this._subParamsLength;
|
||||||
newParams._subParamsIdx.set(this._subParamsIdx);
|
newParams._subParamsIdx.set(this._subParamsIdx);
|
||||||
return newParams;
|
return newParams;
|
||||||
}
|
}
|
||||||
@@ -114,7 +114,7 @@ export class Params implements IParams {
|
|||||||
const start = this._subParamsIdx[i] >> 8;
|
const start = this._subParamsIdx[i] >> 8;
|
||||||
const end = this._subParamsIdx[i] & 0xFF;
|
const end = this._subParamsIdx[i] & 0xFF;
|
||||||
if (end - start > 0) {
|
if (end - start > 0) {
|
||||||
res.push(Array.prototype.slice.call(this.subParams, start, end));
|
res.push(Array.prototype.slice.call(this._subParams, start, end));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return res;
|
return res;
|
||||||
@@ -125,7 +125,7 @@ export class Params implements IParams {
|
|||||||
*/
|
*/
|
||||||
public reset(): void {
|
public reset(): void {
|
||||||
this.length = 0;
|
this.length = 0;
|
||||||
this.subParamsLength = 0;
|
this._subParamsLength = 0;
|
||||||
this._rejectDigits = false;
|
this._rejectDigits = false;
|
||||||
this._rejectSubDigits = false;
|
this._rejectSubDigits = false;
|
||||||
}
|
}
|
||||||
@@ -142,7 +142,7 @@ export class Params implements IParams {
|
|||||||
this._rejectDigits = true;
|
this._rejectDigits = true;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
this._subParamsIdx[this.length] = this.subParamsLength << 8 | this.subParamsLength;
|
this._subParamsIdx[this.length] = this._subParamsLength << 8 | this._subParamsLength;
|
||||||
this.params[this.length++] = value;
|
this.params[this.length++] = value;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -154,11 +154,11 @@ export class Params implements IParams {
|
|||||||
* sub parameter will be ignored.
|
* sub parameter will be ignored.
|
||||||
*/
|
*/
|
||||||
public addSubParam(value: number): void {
|
public addSubParam(value: number): void {
|
||||||
if (!this.length || this.subParamsLength >= this.maxSubParamsLength) {
|
if (!this.length || this._subParamsLength >= this.maxSubParamsLength) {
|
||||||
this._rejectSubDigits = true;
|
this._rejectSubDigits = true;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
this.subParams[this.subParamsLength++] = value;
|
this._subParams[this._subParamsLength++] = value;
|
||||||
this._subParamsIdx[this.length - 1]++;
|
this._subParamsIdx[this.length - 1]++;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -178,7 +178,7 @@ export class Params implements IParams {
|
|||||||
const start = this._subParamsIdx[idx] >> 8;
|
const start = this._subParamsIdx[idx] >> 8;
|
||||||
const end = this._subParamsIdx[idx] & 0xFF;
|
const end = this._subParamsIdx[idx] & 0xFF;
|
||||||
if (end - start > 0) {
|
if (end - start > 0) {
|
||||||
return this.subParams.subarray(start, end);
|
return this._subParams.subarray(start, end);
|
||||||
}
|
}
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
@@ -194,7 +194,7 @@ export class Params implements IParams {
|
|||||||
const start = this._subParamsIdx[i] >> 8;
|
const start = this._subParamsIdx[i] >> 8;
|
||||||
const end = this._subParamsIdx[i] & 0xFF;
|
const end = this._subParamsIdx[i] & 0xFF;
|
||||||
if (end - start > 0) {
|
if (end - start > 0) {
|
||||||
result[i] = this.subParams.slice(start, end);
|
result[i] = this._subParams.slice(start, end);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
@@ -218,13 +218,13 @@ export class Params implements IParams {
|
|||||||
* Do not use this method directly, consider using `addSubParam` instead.
|
* Do not use this method directly, consider using `addSubParam` instead.
|
||||||
*/
|
*/
|
||||||
public addSubParamDigit(value: number): void {
|
public addSubParamDigit(value: number): void {
|
||||||
if (!this.subParamsLength || this._rejectDigits || this._rejectSubDigits) {
|
if (!this._subParamsLength || this._rejectDigits || this._rejectSubDigits) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (this.subParams[this.subParamsLength - 1] === -1) {
|
if (this._subParams[this._subParamsLength - 1] === -1) {
|
||||||
this.subParams[this.subParamsLength - 1] = value;
|
this._subParams[this._subParamsLength - 1] = value;
|
||||||
} else {
|
} else {
|
||||||
this.subParams[this.subParamsLength - 1] = this.subParams[this.subParamsLength - 1] * 10 + value;
|
this._subParams[this._subParamsLength - 1] = this._subParams[this._subParamsLength - 1] * 10 + value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Vendored
-4
@@ -25,10 +25,6 @@ export interface IParams {
|
|||||||
params: Int16Array;
|
params: Int16Array;
|
||||||
length: number;
|
length: number;
|
||||||
|
|
||||||
/** sub params and its length */
|
|
||||||
subParams: Int16Array;
|
|
||||||
subParamsLength: number;
|
|
||||||
|
|
||||||
/** methods */
|
/** methods */
|
||||||
clone(): IParams;
|
clone(): IParams;
|
||||||
toArray(): (number | number[])[];
|
toArray(): (number | number[])[];
|
||||||
|
|||||||
Vendored
+5
-12
@@ -928,23 +928,16 @@ declare module 'xterm' {
|
|||||||
|
|
||||||
interface IParams {
|
interface IParams {
|
||||||
/** from ctor */
|
/** from ctor */
|
||||||
maxLength: number;
|
readonly maxLength: number;
|
||||||
maxSubParamsLength: number;
|
readonly maxSubParamsLength: number;
|
||||||
|
|
||||||
/** param values and its length */
|
/** param values and its length */
|
||||||
params: Int16Array;
|
readonly params: Int16Array;
|
||||||
length: number;
|
readonly length: number;
|
||||||
|
|
||||||
/** sub params and its length */
|
/** exported methods */
|
||||||
subParams: Int16Array;
|
|
||||||
subParamsLength: number;
|
|
||||||
|
|
||||||
/** methods */
|
|
||||||
clone(): IParams;
|
clone(): IParams;
|
||||||
toArray(): (number | number[])[];
|
toArray(): (number | number[])[];
|
||||||
reset(): void;
|
|
||||||
addParam(value: number): void;
|
|
||||||
addSubParam(value: number): void;
|
|
||||||
hasSubParams(idx: number): boolean;
|
hasSubParams(idx: number): boolean;
|
||||||
getSubParams(idx: number): Int16Array | null;
|
getSubParams(idx: number): Int16Array | null;
|
||||||
getSubParamsAll(): {[idx: number]: Int16Array};
|
getSubParamsAll(): {[idx: number]: Int16Array};
|
||||||
|
|||||||
Reference in New Issue
Block a user