Display Error UTF-8 to ASCII #4481
-
Hello, var terminal=new Terminal({
terminal.write(atob("w6k6IGNvbW1hbmQgbm90IGZvdW5k")); Display: é command not foun From my terminal: Can you help me ? Browser: Frefox linux 112.0 (64 bit) |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
(See https://xtermjs.org/docs/guides/encoding/ for encoding details.) Now putting this together - you gonna need to convert the bytestring into an // convert to byte sequence
const sdata = atob("w6k6IGNvbW1hbmQgbm90IGZvdW5k");
const bytes = new Uint8Array(sdata.length);
for (let i = 0; i < bytes.length; ++i) {
bytes[i] = sdata.charCodeAt(i);
}
// write bytes to terminal
term.write(bytes);
// write string to terminal
const td = new TextDecoder();
const s = td.decode(bytes); // s is a normal JS string now
term.write(s); |
Beta Was this translation helpful? Give feedback.
-
ah, yes I have a little trouble with its binary in javascript. Thanks you |
Beta Was this translation helpful? Give feedback.
atob
creates a "bytestring", where every byte maps to a character in [0..255], thus multibyte chars of the original UTF-8 string are not fused into higher codepoints yet.term.write
supports as input:Uint8Array
, or(See https://xtermjs.org/docs/guides/encoding/ for encoding details.)
Now putting this together - you gonna need to convert the bytestring into an
Uint8Array
instance first, then either write that directly to the terminal or create a proper JS unicode string before writing: