diff --git a/CHANGELOG.md b/CHANGELOG.md index b4c27bf..bfb494c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,7 @@ +## 0.5.0.2 + +- support copy and paste in terminal (#27) + ## 0.5.0.1 - Do not fail on unicode decode errors diff --git a/pyxtermjs/app.py b/pyxtermjs/app.py index 479cbb5..cdb4d3d 100644 --- a/pyxtermjs/app.py +++ b/pyxtermjs/app.py @@ -15,7 +15,7 @@ logging.getLogger("werkzeug").setLevel(logging.ERROR) -__version__ = "0.5.0.1" +__version__ = "0.5.0.2" app = Flask(__name__, template_folder=".", static_folder=".", static_url_path="") app.config["SECRET_KEY"] = "secret!" diff --git a/pyxtermjs/index.html b/pyxtermjs/index.html index 10e178e..d12e592 100644 --- a/pyxtermjs/index.html +++ b/pyxtermjs/index.html @@ -13,7 +13,9 @@ /> - pyxterm.js    + pyxterm.js    + status: connecting... { - console.log("key pressed in browser:", data); + console.log("browser terminal received new data:", data); socket.emit("pty-input", { input: data }); }); @@ -92,6 +99,38 @@ }; } + /** + * Handle copy and paste events + */ + function customKeyEventHandler(e) { + if (e.type !== "keydown") { + return true; + } + if (e.ctrlKey && e.shiftKey) { + const key = e.key.toLowerCase(); + if (key === "v") { + // ctrl+shift+v: paste whatever is in the clipboard + navigator.clipboard.readText().then((toPaste) => { + term.writeText(toPaste); + }); + return false; + } else if (key === "c" || key === "x") { + // ctrl+shift+x: copy whatever is highlighted to clipboard + + // 'x' is used as an alternate to 'c' because ctrl+c is taken + // by the terminal (SIGINT) and ctrl+shift+c is taken by the browser + // (open devtools). + // I'm not aware of ctrl+shift+x being used by anything in the terminal + // or browser + const toCopy = term.getSelection(); + navigator.clipboard.writeText(toCopy); + term.focus(); + return false; + } + } + return true; + } + const wait_ms = 50; window.onresize = debounce(fitToscreen, wait_ms);