Fix UTF-8 encoding in SerialAdapterXtermJS (#1439)

* avoid possibly creating unused SerialAdapter instance

* use UTF-8 encoding when exchanging strings between XTerm and serial port

Use TextEncoder.encode() instead of String.charCodeAt() in Terminal.onData(data_str) to encode user input strings (keyboard or paste).
This commit is contained in:
Christian Schnell 2025-10-30 18:35:05 +01:00 committed by GitHub
parent 9735a0eed8
commit 667313401d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 11 additions and 11 deletions

View file

@ -234,16 +234,17 @@ export function SerialAdapterXtermJS(element, bus)
});
term.write("This is the serial console. Whatever you type or paste here will be sent to COM1");
const on_data_disposable = term["onData"](function(data) {
for(let i = 0; i < data.length; i++)
const utf8_encoder = new TextEncoder();
const on_data_disposable = term["onData"](function(data_str) {
for(const utf8_byte of utf8_encoder.encode(data_str))
{
bus.send("serial0-input", data.charCodeAt(i));
bus.send("serial0-input", utf8_byte);
}
});
bus.register("serial0-output-byte", function(byte)
bus.register("serial0-output-byte", function(utf8_byte)
{
term.write(Uint8Array.of(byte));
term.write(Uint8Array.of(utf8_byte));
}, this);
this.destroy = function() {

View file

@ -289,16 +289,15 @@ V86.prototype.continue_init = async function(emulator, options)
settings.screen = this.screen_adapter;
settings.screen_options = screen_options;
if(options.serial_container)
{
this.serial_adapter = new SerialAdapter(options.serial_container, this.bus);
//this.recording_adapter = new SerialRecordingAdapter(this.bus);
}
if(options.serial_container_xtermjs)
{
this.serial_adapter = new SerialAdapterXtermJS(options.serial_container_xtermjs, this.bus);
}
else if(options.serial_container)
{
this.serial_adapter = new SerialAdapter(options.serial_container, this.bus);
//this.recording_adapter = new SerialRecordingAdapter(this.bus);
}
if(!options.disable_speaker)
{