Skip to content

Commit 8ad6a1c

Browse files
authored
feat(terminal): support clipboard for terminal input/output (#515)
1 parent 5875379 commit 8ad6a1c

File tree

3 files changed

+21
-4
lines changed

3 files changed

+21
-4
lines changed

docker-compose-dev.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ services:
105105
timeout: 5s
106106
retries: 20
107107

108-
supertokens:
108+
nixopus-supertokens:
109109
image: registry.supertokens.io/supertokens/supertokens-postgresql:latest
110110
container_name: supertokens
111111

view/app/terminal/utils/stopExecution.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ export const StopExecution = () => {
44
const [isStopped, setIsStopped] = useState(false);
55
useEffect(() => {
66
const handleKeyDown = (e: KeyboardEvent) => {
7-
if (e.key === 'c' && (e.metaKey || e.ctrlKey)) {
7+
if (e.key === 'c' && (e.metaKey || e.ctrlKey) && e.shiftKey) {
88
e.preventDefault();
99
console.log('Stopped execution');
1010
setIsStopped(true);

view/app/terminal/utils/useTerminal.ts

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,12 +157,29 @@ export const useTerminal = (
157157

158158
if (allowInput) {
159159
term.attachCustomKeyEventHandler((event: KeyboardEvent) => {
160-
if ((event.ctrlKey || event.metaKey) && event.key.toLowerCase() === 'j') {
160+
const key = event.key.toLowerCase();
161+
if (key === 'j' && (event.ctrlKey || event.metaKey)) {
162+
return false;
163+
}
164+
else if (key === 'c' && (event.ctrlKey || event.metaKey) && !event.shiftKey) {
165+
if (event.type === 'keydown' ) {
166+
try {
167+
const selection = term.getSelection();
168+
if (selection) {
169+
navigator.clipboard.writeText(selection)
170+
.then(() => {
171+
term.clearSelection(); // Clear selection after successful copy
172+
})
173+
return false;
174+
}
175+
} catch (error) {
176+
console.error('Error in Ctrl+C handler:', error);
177+
}
178+
}
161179
return false;
162180
}
163181
return true;
164182
});
165-
166183
term.onData((data) => {
167184
sendJsonMessage({
168185
action: 'terminal',

0 commit comments

Comments
 (0)