mirror of
https://github.com/wavetermdev/xterm.js.git
synced 2026-08-05 13:43:48 -07:00
remove toArray; interface type for iterator result
This commit is contained in:
+10
-10
@@ -357,7 +357,7 @@ describe('Buffer', () => {
|
||||
it('multiline ascii', () => {
|
||||
const input = 'This is ASCII text spanning multiple lines.';
|
||||
terminal.writeSync(input);
|
||||
const s = terminal.buffer.contents(true).toArray()[0];
|
||||
const s = terminal.buffer.contents(true).next().content;
|
||||
assert.equal(input, s);
|
||||
for (let i = 0; i < input.length; ++i) {
|
||||
const bufferIndex = terminal.buffer.stringIndexToBufferIndex(0, i);
|
||||
@@ -368,7 +368,7 @@ describe('Buffer', () => {
|
||||
it('combining e\u0301 in a sentence', () => {
|
||||
const input = 'Sitting in the cafe\u0301 drinking coffee.';
|
||||
terminal.writeSync(input);
|
||||
const s = terminal.buffer.contents(true).toArray()[0];
|
||||
const s = terminal.buffer.contents(true).next().content;
|
||||
assert.equal(input, s);
|
||||
for (let i = 0; i < 19; ++i) {
|
||||
const bufferIndex = terminal.buffer.stringIndexToBufferIndex(0, i);
|
||||
@@ -388,7 +388,7 @@ describe('Buffer', () => {
|
||||
it('multiline combining e\u0301', () => {
|
||||
const input = 'e\u0301e\u0301e\u0301e\u0301e\u0301e\u0301e\u0301e\u0301e\u0301e\u0301e\u0301e\u0301e\u0301e\u0301e\u0301';
|
||||
terminal.writeSync(input);
|
||||
const s = terminal.buffer.contents(true).toArray()[0];
|
||||
const s = terminal.buffer.contents(true).next().content;
|
||||
assert.equal(input, s);
|
||||
// every buffer cell index contains 2 string indices
|
||||
for (let i = 0; i < input.length; ++i) {
|
||||
@@ -400,7 +400,7 @@ describe('Buffer', () => {
|
||||
it('surrogate char in a sentence', () => {
|
||||
const input = 'The 𝄞 is a clef widely used in modern notation.';
|
||||
terminal.writeSync(input);
|
||||
const s = terminal.buffer.contents(true).toArray()[0];
|
||||
const s = terminal.buffer.contents(true).next().content;
|
||||
assert.equal(input, s);
|
||||
for (let i = 0; i < 5; ++i) {
|
||||
const bufferIndex = terminal.buffer.stringIndexToBufferIndex(0, i);
|
||||
@@ -420,7 +420,7 @@ describe('Buffer', () => {
|
||||
it('multiline surrogate char', () => {
|
||||
const input = '𝄞𝄞𝄞𝄞𝄞𝄞𝄞𝄞𝄞𝄞𝄞𝄞𝄞𝄞𝄞𝄞𝄞𝄞𝄞𝄞𝄞𝄞𝄞𝄞𝄞𝄞𝄞';
|
||||
terminal.writeSync(input);
|
||||
const s = terminal.buffer.contents(true).toArray()[0];
|
||||
const s = terminal.buffer.contents(true).next().content;
|
||||
assert.equal(input, s);
|
||||
// every buffer cell index contains 2 string indices
|
||||
for (let i = 0; i < input.length; ++i) {
|
||||
@@ -433,7 +433,7 @@ describe('Buffer', () => {
|
||||
// eye of Ra with acute accent - string length of 3
|
||||
const input = '𓂀\u0301 - the eye hiroglyph with an acute accent.';
|
||||
terminal.writeSync(input);
|
||||
const s = terminal.buffer.contents(true).toArray()[0];
|
||||
const s = terminal.buffer.contents(true).next().content;
|
||||
assert.equal(input, s);
|
||||
// index 0..2 should map to 0
|
||||
assert.deepEqual([0, 0], terminal.buffer.stringIndexToBufferIndex(0, 1));
|
||||
@@ -447,7 +447,7 @@ describe('Buffer', () => {
|
||||
it('multiline surrogate with combining', () => {
|
||||
const input = '𓂀\u0301𓂀\u0301𓂀\u0301𓂀\u0301𓂀\u0301𓂀\u0301𓂀\u0301𓂀\u0301𓂀\u0301𓂀\u0301𓂀\u0301𓂀\u0301𓂀\u0301𓂀\u0301';
|
||||
terminal.writeSync(input);
|
||||
const s = terminal.buffer.contents(true).toArray()[0];
|
||||
const s = terminal.buffer.contents(true).next().content;
|
||||
assert.equal(input, s);
|
||||
// every buffer cell index contains 3 string indices
|
||||
for (let i = 0; i < input.length; ++i) {
|
||||
@@ -459,7 +459,7 @@ describe('Buffer', () => {
|
||||
it('fullwidth chars', () => {
|
||||
const input = 'These 123 are some fat numbers.';
|
||||
terminal.writeSync(input);
|
||||
const s = terminal.buffer.contents(true).toArray()[0];
|
||||
const s = terminal.buffer.contents(true).next().content;
|
||||
assert.equal(input, s);
|
||||
for (let i = 0; i < 6; ++i) {
|
||||
const bufferIndex = terminal.buffer.stringIndexToBufferIndex(0, i);
|
||||
@@ -478,7 +478,7 @@ describe('Buffer', () => {
|
||||
it('multiline fullwidth chars', () => {
|
||||
const input = '12345678901234567890';
|
||||
terminal.writeSync(input);
|
||||
const s = terminal.buffer.contents(true).toArray()[0];
|
||||
const s = terminal.buffer.contents(true).next().content;
|
||||
assert.equal(input, s);
|
||||
for (let i = 9; i < input.length; ++i) {
|
||||
const bufferIndex = terminal.buffer.stringIndexToBufferIndex(0, i);
|
||||
@@ -489,7 +489,7 @@ describe('Buffer', () => {
|
||||
it('fullwidth combining with emoji - match emoji cell', () => {
|
||||
const input = 'Lots of ¥\u0301 make me 😃.';
|
||||
terminal.writeSync(input);
|
||||
const s = terminal.buffer.contents(true).toArray()[0];
|
||||
const s = terminal.buffer.contents(true).next().content;
|
||||
assert.equal(input, s);
|
||||
const stringIndex = s.match(/😃/).index;
|
||||
const bufferIndex = terminal.buffer.stringIndexToBufferIndex(0, stringIndex);
|
||||
|
||||
+3
-11
@@ -4,7 +4,7 @@
|
||||
*/
|
||||
|
||||
import { CircularList } from './common/CircularList';
|
||||
import { CharData, ITerminal, IBuffer, IBufferLine, BufferIndex, IBufferStringIterator } from './Types';
|
||||
import { CharData, ITerminal, IBuffer, IBufferLine, BufferIndex, IBufferStringIterator, IBufferStringIteratorResult } from './Types';
|
||||
import { EventEmitter } from './common/EventEmitter';
|
||||
import { IMarker } from 'xterm';
|
||||
import { BufferLine } from './BufferLine';
|
||||
@@ -419,7 +419,7 @@ export class BufferStringIterator implements IBufferStringIterator {
|
||||
return this._current < this._end;
|
||||
}
|
||||
|
||||
public next(withRanges: boolean = false): string | [{first: number, last: number}, string] {
|
||||
public next(): IBufferStringIteratorResult {
|
||||
const range = this._buffer.getWrappedRangeForLine(this._current);
|
||||
let result = '';
|
||||
for (let i = range.first; i <= range.last; ++i) {
|
||||
@@ -427,14 +427,6 @@ export class BufferStringIterator implements IBufferStringIterator {
|
||||
result += this._buffer.translateBufferLineToString(i, (this._trimRight) ? i === range.last : false);
|
||||
}
|
||||
this._current = range.last + 1;
|
||||
return (withRanges) ? [range, result] : result;
|
||||
}
|
||||
|
||||
public toArray(): string[] {
|
||||
const result = [];
|
||||
while (this.hasNext()) {
|
||||
result.push(this.next() as string);
|
||||
}
|
||||
return result;
|
||||
return {range: range, content: result};
|
||||
}
|
||||
}
|
||||
|
||||
+3
-3
@@ -4,7 +4,7 @@
|
||||
*/
|
||||
|
||||
import { IMouseZoneManager } from './ui/Types';
|
||||
import { ILinkHoverEvent, ILinkMatcher, LinkMatcherHandler, LinkHoverEventTypes, ILinkMatcherOptions, ILinkifier, ITerminal } from './Types';
|
||||
import { ILinkHoverEvent, ILinkMatcher, LinkMatcherHandler, LinkHoverEventTypes, ILinkMatcherOptions, ILinkifier, ITerminal, IBufferStringIteratorResult } from './Types';
|
||||
import { MouseZone } from './ui/MouseZoneManager';
|
||||
import { EventEmitter } from './common/EventEmitter';
|
||||
import { CHAR_DATA_ATTR_INDEX } from './Buffer';
|
||||
@@ -93,9 +93,9 @@ export class Linkifier extends EventEmitter implements ILinkifier {
|
||||
// we skip those later in _doLinkifyRow
|
||||
const linesIterator = this._terminal.buffer.contents(false, absoluteRowIndexStart, this._terminal.buffer.ydisp + this._rowsToLinkify.end + 1);
|
||||
while (linesIterator.hasNext()) {
|
||||
const lineData: any = linesIterator.next(true);
|
||||
const lineData: IBufferStringIteratorResult = linesIterator.next();
|
||||
for (let i = 0; i < this._linkMatchers.length; i++) {
|
||||
this._doLinkifyRow(lineData[0].first, lineData[1], this._linkMatchers[i]);
|
||||
this._doLinkifyRow(lineData.range.first, lineData.content, this._linkMatchers[i]);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
+6
-2
@@ -268,10 +268,14 @@ export interface ITerminalOptions extends IPublicTerminalOptions {
|
||||
useFlowControl?: boolean;
|
||||
}
|
||||
|
||||
export interface IBufferStringIteratorResult {
|
||||
range: {first: number, last: number};
|
||||
content: string;
|
||||
}
|
||||
|
||||
export interface IBufferStringIterator {
|
||||
hasNext(): boolean;
|
||||
next(withRanges: boolean): string | [{first: number, last: number}, string];
|
||||
toArray(): string[];
|
||||
next(): IBufferStringIteratorResult;
|
||||
}
|
||||
|
||||
export interface IBuffer {
|
||||
|
||||
Reference in New Issue
Block a user