Jupyter lab Terminal can't copy and paste!

133 views
Skip to first unread message

铁龙国

unread,
Sep 18, 2018, 6:11:16 AM9/18/18
to Project Jupyter
Jupyter lab Terminal can't copy and paste!

Tyler Erickson

unread,
Sep 19, 2018, 6:33:03 PM9/19/18
to Project Jupyter
The copy and paste keyboard strokes are different depending on your operating system.

What operating system / browser are you using?

William Stein

unread,
Sep 20, 2018, 4:18:52 PM9/20/18
to jup...@googlegroups.com
Hi,

Jupyter (and Jupyter Lab) uses xterm.js to implement their terminal:
https://github.com/xtermjs/xterm.js
I've been looking into xterm.js a lot this week since I'm currently
rewriting CoCalc to xterm.js instead of term.js.

(NOTE term.js -- see https://github.com/chjj/term.js -- is Fabrice
Bellard's terminal in Javascript so he could use his emscriptem linux
in a browser, and xterm.js is a fork of term.js with all the code
refactored and rewritten in Typescript, and with an additional Canvas
renderer, a plugin system, etc., etc. I hadn't looked at xterm.js much
and have been developing term.js a little over the last 5 years in
parallel.)

As far as I can tell, xterm.js is pretty amazing. However, I just
searched through the xterm.js source code
for a while, and it looks to me like "the copy/paste via the keyboard
terminal problem" is not really fully solved in xterm.js itself.
There's also no issue in the xterm.js issue tracker about implementing
copy so maybe I'm missing something. There's discussion claiming this
is not a problem at all: "Copy & paste from and to xterm should just
work fine without any extra code using CTRL+C and CTRL+V keyboard
shortcuts."
(see https://github.com/xtermjs/xterm.js/issues/1411#issuecomment-383916953)

This is the sort of thing you would think if you don't do cross
platform testing... e.g., you only use a mac, but is a big problem
for people using Linux (me) or maybe Windows. Anyway, it looks to me
like the only way copy can happen is via the code here:

https://github.com/xtermjs/xterm.js/blob/master/src/Terminal.ts#L546

This binds to the copy event I think of the hidden textarea. So copy
(and paste) via *right click and a menu* work fine in Windows and
Linux with xterm.js. However, copy via "Control+C" doesn't seem to
trigger copy on the terminal, since that gets interpreted elsewhere,
and results in an interrupt signal in bash.

It's an interesting UX problem how to deal with this, and most
terminals on Windows/Linux have their own solution. For example, the
browser-based one in ChromeOS uses Control+Shift+C (and
Control+Shift+V) for copy/paste, and also I think *just* highlighting
causes the copy to happen in ChromeOS, even if you don't hit keys. I
think this control+shift+v choice is pretty common in Linux. VSCode
also integrates xterm.js, and they
have solved this problem as explained here:

https://code.visualstudio.com/docs/editor/integrated-terminal#_copy-paste

where they have control+shift+c on linux, control+c on Windows, and
Cmd+c on OS X. I didn't look into the vscode/xterm.js integration
code to see how they did this (in electron/chromium).

In CoCalc, with term.js, I took a different approach. I made it so
Control+C behaves as usual (sending an interrupt, say) if no text is
selected. If you select text and then hit Control+C then it does
copy. I've been using this for years, and I think it makes a ton of
sense. On the other hand, it's just a UX solution I completely made
up, and I've never seen it anywhere else. Our users don't complain
about it -- they expect control+c to copy after all when they are
doing a copy, and they expect it to interrupt when they are trying to
stop something, and just never think about it. Either I implement
this same thing somehow for xterm.js, or I have to just stick with old
term.js (which I really don't want to do).

-- William
> --
> You received this message because you are subscribed to the Google Groups
> "Project Jupyter" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to jupyter+u...@googlegroups.com.
> To post to this group, send email to jup...@googlegroups.com.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/jupyter/493eb17e-ec01-4e7b-b03d-325e036be092%40googlegroups.com.
>
> For more options, visit https://groups.google.com/d/optout.



--
William (http://wstein.org)

Jason Grout

unread,
Sep 20, 2018, 4:40:38 PM9/20/18
to jup...@googlegroups.com

铁龙国

unread,
Sep 21, 2018, 2:05:04 AM9/21/18
to jup...@googlegroups.com
My operating system is  windows and my browse is firfox . 



'Tyler Erickson' via Project Jupyter <jup...@googlegroups.com> 于2018年9月20日周四 上午6:33写道:
--

Tyler Erickson

unread,
Sep 21, 2018, 10:32:07 PM9/21/18
to Project Jupyter
I don't have a windows machine to test this, but try clicking on the terminal and then use the following to open up a context menu for copy/pasting:

Shift+F10


- Tyler

Jason Grout

unread,
Sep 22, 2018, 12:16:18 AM9/22/18
to Project Jupyter
You can also try using the keyboard shortcuts documented at https://github.com/jupyterlab/jupyterlab/issues/1146#issuecomment-394686488 (which I think are similar to the ones documented for Visual Studio Code at https://code.visualstudio.com/docs/editor/integrated-terminal#_copy-paste). Apparently it depends (currently) on the platform you are running the jupyter lab application on.

Jason


铁龙国

unread,
Sep 23, 2018, 11:28:24 AM9/23/18
to jup...@googlegroups.com
Thanks ,when I using microsoft edge it works.(Shift + right click.).

'Tyler Erickson' via Project Jupyter <jup...@googlegroups.com> 于2018年9月22日周六 上午10:32写道:
Reply all
Reply to author
Forward
0 new messages