jline / jline3

JLine is a Java library for handling console input.
Other
1.49k stars 217 forks source link

problems with enabling MOUSE option #57

Open PerBothner opened 7 years ago

PerBothner commented 7 years ago

While enabling the new MOUSE option works pretty well, it has some annoying downsides: It interferes with mouse actions that aren't plain clicks. Specifically: selecting by dragging the mouse; middle-button-paste; right-button context menu; and scrolling using a wheel-mouse.

Most "xterm-compatible" terminal emulators allow you to get most of the default actions by using a shift-click (though mouse-scrolling doesn't work). However, this requires knowing (and remembering) to hit shift.

I'd like a mode such that:

Unfortunately, I don't believe there is any existing standard escape sequence to get this behavior. It should be easy enough to add for specific terminal emulators (I could do so for DomTerm), but it would be highly desirable to get at least Thomas Dickey (the xterm maintainer) to bless and document any new escape sequences.

(Architecturally, it would be better to move more of the editing into the terminal emulator, where we can integrate keyboard, mouse, selection, input methods, assistive technologies etc better. That is part of my vision for DomTerm. However, we should also improve the experience on more traditional terminal emulators.)

gnodet commented 7 years ago

I think in most situations, the terminal can handle all mouse inputs by sending cursor movement for moving the cursor, doing the selection, support copying the selection and pasting, etc... It may not always work if an application require a very deep integration, but I'm not sure I understand what you're looking for, as any JLine app can already do the 3 points above afaik.

PerBothner commented 7 years ago

I don't believe "any JLine app" can do the 3rd item in my list: Currently, if I enable the MOUSE option, then the following break, unless I remember to press shift: selection by dragging (and thus I can't copy from the terminal); middle-button-paste; and mouse-wheel scrolling (which doesn't work even when shifted). This is annoying - and confusing to most people.

Emacs-in-a-terminal does its own highlighting and selection when the mouse is dragged, but this is not integrated with the system selection or clipboard. I'm not sure JLine3 should attempt something similar. It would be better IMO to use the terminal's builtin highlighting and selection.

I think there should be one more item to the list:

Dufgui commented 2 weeks ago

Hello, I found this pretty old issue. I want to know if there is a way to permit selection on previous result on the console. And permit the copy by selecting with mouse and paste with 3rd button ? Maybe it's has been fixed or partially fixed. So I prefer to ask it here, instead of create a new issue.

If it's not exist, could you provide some input to propose a merge request on it.

Best regards

Dufgui commented 1 week ago

@gnodet Sorry to notify you but maybe my comment on an old issue has not be seen without it. It s maybe a bug and I can contribute to try to fix it. But I just need some entry point to investigate. Of maybe there is a way to do it. But I do not find it in any example. Thank you to all team to maintain this awesome project

gnodet commented 1 week ago

@gnodet Sorry to notify you but maybe my comment on an old issue has not be seen without it. It s maybe a bug and I can contribute to try to fix it. But I just need some entry point to investigate. Of maybe there is a way to do it. But I do not find it in any example. Thank you to all team to maintain this awesome project

There's no real standard for that afaik, so it really depends on which terminal emulator you use. The emulator may send escape sequences or support some configuration, or maybe just support copy/paste externally without any support from the application.

If you know your terminal emulator, you need to find which escape sequences related to mouse events it supports. I'd be happy to provide pointers or review a PR if you end up with something usable.

Dufgui commented 1 week ago

Hello, do you want a dedicated issue? I launch jline in a XTerm. JLine version is 3.21. My terminal is launch this way:

TerminalBuilder.builder().system(true).jansi(true).jna(true).nativeSignals(true)
                    .signalHandler(Terminal.SignalHandler.SIG_IGN).paused(true).build();

I don't know what you call terminal emulator and how to identify it. But we are on Linux Centos 7 or Rocky 8. As I can see Jansi works (I use the jar invocation to test it).

I test and I see the terminal.getType() on linux return xterm. I test on windows also, selection works on it. Terminal type is windows-vtp.

Is there any other test I can do to help? I can test a more recent version if you want.

gnodet commented 1 week ago

Hello, do you want a dedicated issue? I launch jline in a XTerm. JLine version is 3.21. My terminal is launch this way:

TerminalBuilder.builder().system(true).jansi(true).jna(true).nativeSignals(true)
                    .signalHandler(Terminal.SignalHandler.SIG_IGN).paused(true).build();

I don't know what you call terminal emulator and how to identify it. But we are on Linux Centos 7 or Rocky 8. As I can see Jansi works (I use the jar invocation to test it).

Terminal emulator is XTerm, Gnomę Terminal, Konsole ,etc... In xterm, you have copy/paste handled by the terminal afaik: https://askubuntu.com/questions/237942/how-does-copy-paste-work-with-xterm

I test and I see the terminal.getType() on linux return xterm. I test on windows also, selection works on it. Terminal type is windows-vtp.

Is there any other test I can do to help? I can test a more recent version if you want.

Dufgui commented 1 week ago

Indeed, copy paste works! the shift insert works. So copy paste works. I can also paste from external source.

But the mouse selection work before I launch my jar with jline. But when I launch my jar, the mouse selection no more works. I just can move the cursor inside the prompt with the mouse. But cannot select when I hold de the left mouse button

Dufgui commented 4 days ago

Hello,

I see some code about mouse in one example: https://github.com/jline/jline3/blob/master/builtins/src/test/java/org/jline/example/Example.java#L419

I see we can get mouse event. But I don't know how to not block them and let them continue to the terminal emulator.

Any inputs?

gnodet commented 4 days ago

The trackMouse call is the one triggering mouse support. If you don't call it, the emulator should not forward them to JLine. But it's one or the other, I don't think you can have both at the same time.

Dufgui commented 3 days ago

I do not want it on jline side in fact. I just want it forward to xtext. Is the mouse activated by default?

Dufgui commented 2 days ago

Finally I put .option(Option.MOUSE, false) and terminal.trackMouse(Terminal.MouseTracking.Off); I loose the third mouse button paste feature. XTerm do it but not inside jline. No idea why.

But the selection of text works this way

Thanks for your help @gnodet