From 443c2d7d4d92b634c40b677141ff4fd5fd1f4b16 Mon Sep 17 00:00:00 2001 From: Dustin Brett Date: Sat, 7 Dec 2024 18:33:30 -0800 Subject: [PATCH] Remove terminal bg for lolcat --- components/apps/Terminal/functions.ts | 3 +++ components/apps/Terminal/loadWapm.ts | 8 ++++++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/components/apps/Terminal/functions.ts b/components/apps/Terminal/functions.ts index de29f878b3..af5af1ab6f 100644 --- a/components/apps/Terminal/functions.ts +++ b/components/apps/Terminal/functions.ts @@ -290,6 +290,9 @@ export const printColor = ( )}` }\u001B[0m`; +export const clearAnsiBackground = (text: string): string => + text.replace(/;48;2;/g, ";48;0;").replace(/;48;5;/g, ";48;0;"); + export const readClipboardToTerminal = (localEcho: LocalEcho): void => { try { navigator.clipboard diff --git a/components/apps/Terminal/loadWapm.ts b/components/apps/Terminal/loadWapm.ts index 9e4aa72939..1ad4942107 100644 --- a/components/apps/Terminal/loadWapm.ts +++ b/components/apps/Terminal/loadWapm.ts @@ -5,7 +5,10 @@ import { WAPM_STD_IN_EXCLUDE_ARGS, config, } from "components/apps/Terminal/config"; -import { parseCommand } from "components/apps/Terminal/functions"; +import { + clearAnsiBackground, + parseCommand, +} from "components/apps/Terminal/functions"; import { getExtension } from "utils/functions"; type WASIError = Error & { @@ -225,7 +228,8 @@ const loadWapm = async ( sendStderr: (buffer: Uint8Array) => print(buffer.toString()), sendStdout: (buffer: Uint8Array) => { if (stdIn) exitStdIn = true; - print(buffer.toString()); + const output = buffer.toString(); + print(stdIn ? clearAnsiBackground(output) : output); }, }); const instance = await WebAssembly.instantiate(