add missing api docs and refactor serialize implementation by using list join instead and some code clean up

This commit is contained in:
javacs3
2019-07-12 23:23:06 +08:00
parent 57a8255654
commit 31f812cf94
2 changed files with 14 additions and 13 deletions
@@ -15,28 +15,21 @@ export class SerializeAddon implements ITerminalAddon {
}
public serialize(rows?: number): string {
// TODO: Add frontground/background color support later
if (!this._terminal) {
return '';
throw new Error('No terminal found!');
}
const buffer = this._terminal.buffer;
const length = Math.max(0, Math.min((rows === undefined ? buffer.length : rows), buffer.length));
let data = '';
const lines: string[] = new Array<string>(length);
for (let i = 0; i < length; i++) {
const line = buffer.getLine(i);
const last = i === length - 1;
if (line) {
data += line.translateToString();
}
if (!last) {
data += '\r\n';
}
lines[i] = line ? line.translateToString() : '';
}
return data;
return lines.join('\r\n');
}
public dispose(): void {
if (this._terminal !== undefined) { }
}
public dispose(): void { }
}