handle buffers cut in the middle of a unicode char - fixes #3883, fixes #3882, fixes #3093, fixes #2043

This commit is contained in:
Eugene Pankov 2021-05-28 19:39:41 +02:00
parent ae7416792a
commit 1931b5ac7e
No known key found for this signature in database
GPG Key ID: 5896FCBBDD1CF4F4

View File

@ -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