From 1931b5ac7e602ec41751f893259870e42011cbed Mon Sep 17 00:00:00 2001 From: Eugene Pankov Date: Fri, 28 May 2021 19:39:41 +0200 Subject: [PATCH] handle buffers cut in the middle of a unicode char - fixes #3883, fixes #3882, fixes #3093, fixes #2043 --- app/lib/pty.ts | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/app/lib/pty.ts b/app/lib/pty.ts index 1917695a..2ca95548 100644 --- a/app/lib/pty.ts +++ b/app/lib/pty.ts @@ -1,4 +1,5 @@ import * as nodePTY from '@terminus-term/node-pty' +import { StringDecoder } from 'string_decoder' import { v4 as uuidv4 } from 'uuid' import { ipcMain } from 'electron' import { Application } from './app' @@ -9,6 +10,7 @@ class PTYDataQueue { private maxChunk = 1024 private maxDelta = 1024 * 50 private flowPaused = false + private decoder = new StringDecoder('utf8') constructor (private pty: nodePTY.IPty, private onData: (data: Buffer) => void) { } @@ -49,7 +51,7 @@ class PTYDataQueue { this.buffers.unshift(toSend.slice(this.maxChunk)) toSend = toSend.slice(0, this.maxChunk) } - this.onData(toSend) + this.emitData(toSend) this.delta += toSend.length if (this.buffers.length) { @@ -58,6 +60,10 @@ class PTYDataQueue { } } + private emitData (data: Buffer) { + this.onData(Buffer.from(this.decoder.write(data))) + } + private pause () { this.pty.pause() this.flowPaused = true