Skip to content

Display Error UTF-8 to ASCII #4481

Answered by jerch
Archie1978 asked this question in Q&A
Discussion options

You must be logged in to vote

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:

  • UTF-8 byte sequences given as Uint8Array, or
  • JS unicode string (interpreted as UTF-16)

(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:

// convert to byte sequence
const sdata = atob("w6k6IGNvbW1hbmQgbm90IGZvdW5k");
const bytes = new Uint8Array(sdata.length);
for (let i 

Replies: 2 comments

Comment options

You must be logged in to vote
0 replies
Answer selected by Tyriar
Comment options

You must be logged in to vote
0 replies
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants