如何使用 nodejs 在终端中呈现扩展的 ASCII 字符

How to render extended ASCII characters in terminal using nodejs

根据this site,ASCII扩展字符码176、177、178分别对应三个长方形深浅不同的字符:

此处更详细,字符 178:

现在,根据 https://mathiasbynens.be/notes/javascript-escapes,我应该能够转义任何代码低于 256 的 ASCII 字符,例如,它的十六进制转义序列。因此,176 将是十六进制的 \xB0。但是我没有得到如上所述的预期字符,而是得到 "degree symbol" '°'。度数符号是 ASCII 248,而不是 176,所以....我做错了什么?

JavaScript 使用 Unicode, rather than extended ASCII. You can find the Unicode equivalent of the ASCII symbols by using String.prototype.charCodeAt(), and then output them with String.prototype.fromCharCode():

console.log("░".charCodeAt(0)); // 9617
console.log("▒".charCodeAt(0)); // 9618
console.log("▓".charCodeAt(0)); // 9619

console.log(String.fromCharCode(9617)); // ░
console.log(String.fromCharCode(9618)); // ▒
console.log(String.fromCharCode(9619)); // ▓

希望对您有所帮助! :)

JavaScript 使用 Unicode,而不是扩展 ASCII。

U+00B0 is the degree symbol

Block elements hold positions 2580 to 259F

console.log("\u2592");