rivo / tview

Terminal UI library with rich, interactive widgets — written in Golang
MIT License
11.13k stars 575 forks source link

Question: problems with copy/paste in TextArea and system menu on right-click #992

Closed name212 closed 6 months ago

name212 commented 6 months ago

Hello everyone!

I am creating a console utility that install Deckhouse Kubernetes Platfom through a series of steps. In one of the steps I output a public key that needs to be copied to a remote machine to continue the installation. But unfortunately I can highlight the public key but cannot copy the public key as CTRL+Insert because it is handled by tview. Also I can't call the terminal context menu to copy or paste, as tview handle all mouse clicks, which is extremely inconvenient from a user experience point of view. But I've given up on that for now. Next, I found the https://pkg.go.dev/github.com/rivo/tview#TextArea.SetClipboard method and together with the https://github.com/F1bonacc1/glippy library implemented copy/paste support. Everything works fine in my linux terminal, but when I started to run in production build (in docker container) glippy stops with panic. It's clear that the docker container doesn't have X11 (or what implements the clipboard) and buffer functions are not available. Now my application logic is broken, as the terminal context menu is not available and the clipboard is not available either.

Is there any way to not handle the right mouse click and allow the terminal context menu to appear? And what about CTRL+Insert, perhaps the processing of this combination can also be left to the terminal? And why in some cases Shift+Insert works correctly and in some cases it doesn't?

Thanks

rivo commented 6 months ago

Regarding mouse handling, this is something that needs to be turned on explicitly in every application: https://pkg.go.dev/github.com/rivo/tview#Application.EnableMouse

If you don't call this command, your application should not capture any mouse events and right-clicking should work. (I'm saying "should" because every terminal is different and I'm not familiar with yours — in fact, you didn't even mention which terminal you're using.) So overall, I would suggest that you don't call EnableMouse().

Regarding copy&paste keyaboard shortcuts, which key combination will be forwarded to the application and which one won't is entirely up to your terminal. And every terminal is different. For example, I'm using iTerm2 on macOS and I can always paste text using Cmd+V. As far as I know, this cannot be controlled by the application. If you want your terminal to process the Ctrl+Ins key, you need to find a way to configure your terminal accordingly. (For example, WSL on Windows can be set to use Ctrl+Shift+V for the "paste" command so it doesn't overlap with an application's handling of Ctrl+V.)

But from what you're writing, it seems that your users' terminal settings are beyond your control. So, again, the only thing I can suggest is turning off mouse handling.

name212 commented 6 months ago

Thank you for your response.

Using your advice for the public key screen, I disabled mouse capture with app.EnableMouse and return mouse capture after this screen. It's a bit crutchy but I can't think of anything else.

Issue can be closed. Thanks