mirror of
https://github.com/copy/v86.git
synced 2025-12-31 04:23:15 +00:00
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:
parent
9735a0eed8
commit
667313401d
2 changed files with 11 additions and 11 deletions
|
|
@ -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");
|
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) {
|
const utf8_encoder = new TextEncoder();
|
||||||
for(let i = 0; i < data.length; i++)
|
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);
|
||||||
|
|
||||||
this.destroy = function() {
|
this.destroy = function() {
|
||||||
|
|
|
||||||
|
|
@ -289,16 +289,15 @@ V86.prototype.continue_init = async function(emulator, options)
|
||||||
settings.screen = this.screen_adapter;
|
settings.screen = this.screen_adapter;
|
||||||
settings.screen_options = screen_options;
|
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)
|
if(options.serial_container_xtermjs)
|
||||||
{
|
{
|
||||||
this.serial_adapter = new SerialAdapterXtermJS(options.serial_container_xtermjs, this.bus);
|
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)
|
if(!options.disable_speaker)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue