fix: adjust color paste on terminal

This commit is contained in:
Mauricio Siu
2025-01-26 14:55:22 -06:00
parent d7210e9d7b
commit b1beb7b71b
4 changed files with 188 additions and 159 deletions

View File

@@ -6,6 +6,7 @@ import "@xterm/xterm/css/xterm.css";
import { AttachAddon } from "@xterm/addon-attach"; import { AttachAddon } from "@xterm/addon-attach";
import { useTheme } from "next-themes"; import { useTheme } from "next-themes";
import { getLocalServerData } from "./local-server-config"; import { getLocalServerData } from "./local-server-config";
import { ClipboardAddon } from "@xterm/addon-clipboard";
interface Props { interface Props {
id: string; id: string;
@@ -32,15 +33,15 @@ export const Terminal: React.FC<Props> = ({ id, serverId }) => {
lineHeight: 1.4, lineHeight: 1.4,
convertEol: true, convertEol: true,
theme: { theme: {
cursor: resolvedTheme === "light" ? "#000000" : "#FFFFFF", cursor: resolvedTheme === "light" ? "#000000" : "transparent",
background: resolvedTheme === "light" ? "#FFFFFF" : "rgba(0, 0, 0, 0.9)", background: "rgba(0, 0, 0, 0)",
foreground: resolvedTheme === "light" ? "#000000" : "#FFFFFF", foreground: "currentColor",
selectionForeground: resolvedTheme === "light" ? "#000000" : "#FFFFFF",
}, },
allowTransparency: true, allowTransparency: true,
screenReaderMode: true, screenReaderMode: true,
scrollback: 1000, scrollback: 1000,
}); });
const addonFit = new FitAddon(); const addonFit = new FitAddon();
const protocol = window.location.protocol === "https:" ? "wss:" : "ws:"; const protocol = window.location.protocol === "https:" ? "wss:" : "ws:";
@@ -58,6 +59,8 @@ export const Terminal: React.FC<Props> = ({ id, serverId }) => {
const ws = new WebSocket(wsUrl); const ws = new WebSocket(wsUrl);
const addonAttach = new AttachAddon(ws); const addonAttach = new AttachAddon(ws);
const clipboardAddon = new ClipboardAddon();
term.loadAddon(clipboardAddon);
// @ts-ignore // @ts-ignore
term.open(termRef.current); term.open(termRef.current);

View File

@@ -75,6 +75,7 @@
"@uiw/react-codemirror": "^4.22.1", "@uiw/react-codemirror": "^4.22.1",
"@xterm/addon-attach": "0.10.0", "@xterm/addon-attach": "0.10.0",
"@xterm/xterm": "^5.4.0", "@xterm/xterm": "^5.4.0",
"@xterm/addon-clipboard": "0.1.0",
"adm-zip": "^0.5.14", "adm-zip": "^0.5.14",
"bcrypt": "5.1.1", "bcrypt": "5.1.1",
"bullmq": "5.4.2", "bullmq": "5.4.2",

View File

@@ -4,6 +4,7 @@
@layer base { @layer base {
:root { :root {
--terminal-paste: rgba(0, 0, 0, 0.2);
--background: 0 0% 100%; --background: 0 0% 100%;
--foreground: 240 10% 3.9%; --foreground: 240 10% 3.9%;
@@ -51,6 +52,7 @@
} }
.dark { .dark {
--terminal-paste: rgba(255, 255, 255, 0.2);
--background: 0 0% 0%; --background: 0 0% 0%;
--foreground: 0 0% 98%; --foreground: 0 0% 98%;
@@ -235,3 +237,8 @@
background-color: hsl(var(--muted-foreground) / 0.5); background-color: hsl(var(--muted-foreground) / 0.5);
} }
} }
.xterm-bg-257.xterm-fg-257 {
background-color: var(--terminal-paste) !important;
color: currentColor !important;
}

18
pnpm-lock.yaml generated
View File

@@ -217,6 +217,9 @@ importers:
'@xterm/addon-attach': '@xterm/addon-attach':
specifier: 0.10.0 specifier: 0.10.0
version: 0.10.0(@xterm/xterm@5.5.0) version: 0.10.0(@xterm/xterm@5.5.0)
'@xterm/addon-clipboard':
specifier: 0.1.0
version: 0.1.0(@xterm/xterm@5.5.0)
'@xterm/xterm': '@xterm/xterm':
specifier: ^5.4.0 specifier: ^5.4.0
version: 5.5.0 version: 5.5.0
@@ -3503,6 +3506,11 @@ packages:
peerDependencies: peerDependencies:
'@xterm/xterm': ^5.0.0 '@xterm/xterm': ^5.0.0
'@xterm/addon-clipboard@0.1.0':
resolution: {integrity: sha512-zdoM7p53T5sv/HbRTyp4hY0kKmEQ3MZvAvEtiXqNIHc/JdpqwByCtsTaQF5DX2n4hYdXRPO4P/eOS0QEhX1nPw==}
peerDependencies:
'@xterm/xterm': ^5.4.0
'@xterm/xterm@5.5.0': '@xterm/xterm@5.5.0':
resolution: {integrity: sha512-hqJHYaQb5OptNunnyAnkHyM8aCjZ1MEIDTQu1iIbbTD/xops91NB5yq1ZK/dC2JDbVWtF23zUtl9JE2NqwT87A==} resolution: {integrity: sha512-hqJHYaQb5OptNunnyAnkHyM8aCjZ1MEIDTQu1iIbbTD/xops91NB5yq1ZK/dC2JDbVWtF23zUtl9JE2NqwT87A==}
@@ -5011,6 +5019,9 @@ packages:
resolution: {integrity: sha512-34wB/Y7MW7bzjKRjUKTa46I2Z7eV62Rkhva+KkopW7Qvv/OSWBqvkSY7vusOPrNuZcUG3tApvdVgNB8POj3SPw==} resolution: {integrity: sha512-34wB/Y7MW7bzjKRjUKTa46I2Z7eV62Rkhva+KkopW7Qvv/OSWBqvkSY7vusOPrNuZcUG3tApvdVgNB8POj3SPw==}
engines: {node: '>=10'} engines: {node: '>=10'}
js-base64@3.7.7:
resolution: {integrity: sha512-7rCnleh0z2CkXhH67J8K1Ytz0b2Y+yxTPL+/KOJoa20hfnVQ/3/T6W/KflYI4bRHRagNeXeU2bkNGI3v1oS/lw==}
js-beautify@1.15.1: js-beautify@1.15.1:
resolution: {integrity: sha512-ESjNzSlt/sWE8sciZH8kBF8BPlwXPwhR6pWKAw8bw4Bwj+iZcnKW6ONWUutJ7eObuBZQpiIb8S7OYspWrKt7rA==} resolution: {integrity: sha512-ESjNzSlt/sWE8sciZH8kBF8BPlwXPwhR6pWKAw8bw4Bwj+iZcnKW6ONWUutJ7eObuBZQpiIb8S7OYspWrKt7rA==}
engines: {node: '>=14'} engines: {node: '>=14'}
@@ -9894,6 +9905,11 @@ snapshots:
dependencies: dependencies:
'@xterm/xterm': 5.5.0 '@xterm/xterm': 5.5.0
'@xterm/addon-clipboard@0.1.0(@xterm/xterm@5.5.0)':
dependencies:
'@xterm/xterm': 5.5.0
js-base64: 3.7.7
'@xterm/xterm@5.5.0': {} '@xterm/xterm@5.5.0': {}
'@xtuc/ieee754@1.2.0': {} '@xtuc/ieee754@1.2.0': {}
@@ -11410,6 +11426,8 @@ snapshots:
joycon@3.1.1: {} joycon@3.1.1: {}
js-base64@3.7.7: {}
js-beautify@1.15.1: js-beautify@1.15.1:
dependencies: dependencies:
config-chain: 1.1.13 config-chain: 1.1.13