From 02d1d8d1c09af22002b0fac4afbd45753cd595a5 Mon Sep 17 00:00:00 2001 From: ZacharyZcR Date: Thu, 2 Oct 2025 14:34:23 +0800 Subject: [PATCH] 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 --- src/backend/ssh/terminal.ts | 13 +------------ src/ui/Desktop/Apps/Terminal/Terminal.tsx | 4 ++++ src/ui/Mobile/Apps/Terminal/Terminal.tsx | 4 ++++ 3 files changed, 9 insertions(+), 12 deletions(-) diff --git a/src/backend/ssh/terminal.ts b/src/backend/ssh/terminal.ts index 0f0b7a0b..7706fe13 100644 --- a/src/backend/ssh/terminal.ts +++ b/src/backend/ssh/terminal.ts @@ -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", () => { diff --git a/src/ui/Desktop/Apps/Terminal/Terminal.tsx b/src/ui/Desktop/Apps/Terminal/Terminal.tsx index 5a686ec5..17a7edeb 100644 --- a/src/ui/Desktop/Apps/Terminal/Terminal.tsx +++ b/src/ui/Desktop/Apps/Terminal/Terminal.tsx @@ -532,6 +532,10 @@ export const Terminal = forwardRef(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; diff --git a/src/ui/Mobile/Apps/Terminal/Terminal.tsx b/src/ui/Mobile/Apps/Terminal/Terminal.tsx index c2470658..7428e628 100644 --- a/src/ui/Mobile/Apps/Terminal/Terminal.tsx +++ b/src/ui/Mobile/Apps/Terminal/Terminal.tsx @@ -233,6 +233,10 @@ export const Terminal = forwardRef(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(