diff --git a/apps/terminal/components/Terminal/index.tsx b/apps/terminal/components/Terminal/index.tsx index a710007..83ba6cc 100644 --- a/apps/terminal/components/Terminal/index.tsx +++ b/apps/terminal/components/Terminal/index.tsx @@ -100,9 +100,28 @@ const Terminal = ({ active, shellName }: { active: boolean; shellName: string }) }; xtermDiv.addEventListener('focus', focusListener); + const mouseUpListener = () => { + if (config.copyOnSelect && xterm.hasSelection()) { + const selectedText = xterm.getSelection(); + navigator.clipboard.writeText(selectedText); + } + }; + xtermDiv.addEventListener('mouseup', mouseUpListener); + + const contextMenuListener = () => { + navigator.clipboard.readText().then((text) => { + if (text) { + xterm.paste(text); + } + }); + }; + xtermDiv.addEventListener('contextmenu', contextMenuListener); + return () => { window.removeEventListener('resize', resizeListener); xtermDiv.removeEventListener('focus', focusListener); + xtermDiv.removeEventListener('mouseup', mouseUpListener); + xtermDiv.removeEventListener('contextmenu', contextMenuListener); window.TerminalOne?.terminal?.killTerminal(terminalId); xterm.dispose(); diff --git a/package.json b/package.json index 42a1268..2ea5512 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "@terminalone/monorepo", "productName": "Terminal One", - "version": "0.4.0", + "version": "0.5.0", "description": "A fast, elegant and intelligent cross-platform terminal.", "author": "Kun Chen", "license": "MIT", diff --git a/packages/types/config.ts b/packages/types/config.ts index 39c73ff..47a0955 100644 --- a/packages/types/config.ts +++ b/packages/types/config.ts @@ -60,6 +60,7 @@ const ConfigTypeContent = { }), cursorWidth: t.number, scrollback: t.number, + copyOnSelect: t.boolean, fontSize: t.number, fontFamily: t.string, fontWeight: t.number, diff --git a/packages/types/defaultConfig.ts b/packages/types/defaultConfig.ts index 1dd176c..f1a86b6 100644 --- a/packages/types/defaultConfig.ts +++ b/packages/types/defaultConfig.ts @@ -7,6 +7,9 @@ export const DEFAULT_CONFIG: ResolvedConfig = { // Number of lines to keep in the scrollback buffer. scrollback: 10000, + // Whether to copy text to the clipboard on selection. + copyOnSelect: true, + // Whether to blink the cursor. cursorBlink: true,