Fix emoji rendering artifacts in terminal

- Activate Unicode 11 in XTerm to prevent double-width overlap
- Remove latin1 fallback that breaks multi-byte UTF-8
- Rely on SSH env configuration for proper locale handling

Fixes #266
This commit is contained in:
ZacharyZcR
2025-10-02 14:34:23 +08:00
parent a097b1e300
commit 02d1d8d1c0
3 changed files with 9 additions and 12 deletions
+1 -12
View File
@@ -427,18 +427,7 @@ wss.on("connection", async (ws: WebSocket, req) => {
sshStream = stream;
stream.on("data", (data: Buffer) => {
let decoded = data.toString("utf-8");
// Defensive fallback: if UTF-8 decode produces replacement characters
// and buffer contains high bytes, try latin1 (for legacy servers without UTF-8 locale)
if (
decoded.includes("\uFFFD") &&
data.some((byte) => byte >= 0x80 && byte <= 0xff)
) {
decoded = data.toString("latin1");
}
ws.send(JSON.stringify({ type: "data", data: decoded }));
ws.send(JSON.stringify({ type: "data", data: data.toString("utf-8") }));
});
stream.on("close", () => {
@@ -532,6 +532,10 @@ export const Terminal = forwardRef<any, SSHTerminalProps>(function SSHTerminal(
terminal.loadAddon(clipboardAddon);
terminal.loadAddon(unicode11Addon);
terminal.loadAddon(webLinksAddon);
// Activate Unicode 11 for proper emoji rendering (prevents double-width artifacts)
terminal.unicode.activeVersion = "11";
terminal.open(xtermRef.current);
const element = xtermRef.current;
+4
View File
@@ -233,6 +233,10 @@ export const Terminal = forwardRef<any, SSHTerminalProps>(function SSHTerminal(
terminal.loadAddon(clipboardAddon);
terminal.loadAddon(unicode11Addon);
terminal.loadAddon(webLinksAddon);
// Activate Unicode 11 for proper emoji rendering (prevents double-width artifacts)
terminal.unicode.activeVersion = "11";
terminal.open(xtermRef.current);
const textarea = xtermRef.current.querySelector(