New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How do paste to xterm when I copy something from an oitside source? #1411
Comments
I think you can't. Browsers don't allow direct access to the clipboard for security reasons. xterm.js itself listens for the 'paste' event on its hidden textarea, so if something gets pasted while xterm is focused this event will be triggered and we are able to read the data that was pasted with that event and will write it to the terminal automatically. |
Thank you for the fast response. |
I don't quite understand your use-case. Copy & paste from and to xterm should just work fine without any extra code using CTRL+C and CTRL+V keyboard shortcuts. |
Sorry if I got you confused. My question was to how I can implement the paste when I copy from an outside source. |
What browser are you using? Could you try if it works in Chrome? (we had some troubles with pasting in Firefox a while ago, but that should also be fixed if I recall correctly) |
Try shift+insert to paste into the xterm. Or right-click and paste. @katrina-switch |
Hi sorry for the late reply. @justinjocewicz right click + paste doesn't work for me, it's still not implemented in my code. I finally was able to get to paste the string copied from another application. Thanks!
|
Details
Sorry, I am a bit new to javascript and xterm.
Just a summary, I have a web project where I intergrate xterm to show what's happening in a Linux gateway. I connect to it by sending a websocket message which contains my login credentials. A .net core service runs on the gateway that receives the websocket message and logs me in the SSH and SFTP service of the gateway. And sends back the result to my browser via websocket. Then I display the results using xterm.write(result);
In the web project I have an attachCustomKeyEventHandler that calls my Copy and Paste functions below..
function Copy() {
if (xterm.hasSelection()) {
var copySucceeded = document.execCommand('copy');
copiedText = "" + xterm.getSelection();
console.log('copy succeeded: ' + copiedText, copySucceeded);
}
else
console.log('no selection to copy!');
}
This works when I copy/paste from within the xterm. If I want to copy from an outside source like notepad, how do I implement this using Shift + Insert or Ctrl + Shift + V?
The text was updated successfully, but these errors were encountered: