From 747b94f1034907688af17e852862ce064d37dbeb Mon Sep 17 00:00:00 2001 From: b1ek Date: Fri, 17 Mar 2023 16:08:13 +1000 Subject: [PATCH] clipboard support --- react/resume/src/emulator/pastebuffer.js | 37 ++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 react/resume/src/emulator/pastebuffer.js diff --git a/react/resume/src/emulator/pastebuffer.js b/react/resume/src/emulator/pastebuffer.js new file mode 100644 index 0000000..bb4d033 --- /dev/null +++ b/react/resume/src/emulator/pastebuffer.js @@ -0,0 +1,37 @@ +import { Terminal } from "xterm" +import copy from 'copy-to-clipboard'; + +/** @type { Terminal } */ +let terminal; +const zsh = require('./zsh'); + +/** + * + * @param {{ key: string, domEvent: KeyboardEvent }} e + */ +async function keyHandler(e) { + const dom = e.domEvent; + + if (!dom.altKey) + return; + + if (dom.key.length != 1) + return; + + switch (dom.key.toLowerCase()) { + case 'c': + if (!terminal.hasSelection()) break; + + copy(terminal.getSelection()) + break; + case 'v': + zsh.pr_char(prompt("Paste your text:"), {key: 'a'}) + + } +} + +module.exports = (t, d) => { + terminal = t; + terminal.onKey(keyHandler); + +} \ No newline at end of file