Skip to content

Commit 13ad1c2

Browse files
committed
fix: UTF-8 in serial port data is mangled in wokwi-cli stdout #32
close #32
1 parent a85a7e1 commit 13ad1c2

File tree

1 file changed

+2
-3
lines changed

1 file changed

+2
-3
lines changed

src/main.ts

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -324,12 +324,11 @@ async function main() {
324324

325325
await client.serialMonitorListen();
326326

327+
const utf8Decoder = new TextDecoder('utf-8');
327328
client.listen('serial-monitor:data', (event: APIEvent<SerialMonitorDataPayload>) => {
328329
let { bytes } = event.payload;
329330
bytes = scenario?.processSerialBytes(bytes) ?? bytes;
330-
for (const byte of bytes) {
331-
process.stdout.write(String.fromCharCode(byte));
332-
}
331+
process.stdout.write(utf8Decoder.decode(Buffer.from(bytes)));
333332

334333
serialLogStream?.write(Buffer.from(bytes));
335334
expectEngine.feed(bytes);

0 commit comments

Comments
 (0)