Skip to content

Doesn't pass along mouse actions #101

Closed

Description

@kergoth

When using an xterm-compatible terminal, one can use the mouse in some applications (e.g. tmux, vim). Mosh does not pass this along, but ssh does. This is a blocking issue for me, and I won't be switching from pure ssh to mosh until/if this is resolved.

Activity

  1. keithw commented on Apr 9, 2012

    @keithw
    Member

    Thanks, we'll look at this.

  2. suan commented on Apr 10, 2012

    @suan

    Isn't this because mosh doesn't support X-forwarding?

  3. keithw commented on Apr 10, 2012

    @keithw
    Member

    Nah, it's a textual protocol that xterm uses to convey mouse clicks to a terminal app. We just don't support it yet.

  4. kmcallister commented on Apr 10, 2012

    @kmcallister
    Contributor

    Mosh advertises TERM=xterm so presumably we would support the Xterm mouse protocol on the server side.

    According to /usr/share/doc/xterm/ctlseqs.txt.gz Xterm supports "six mutually exclusive modes". They're enabled with the "Set Mode (SM)" command (CSI?numberh) and disabled with "Clear Mode (CM)" (CSI?numberl). For example, "normal tracking mode" is enabled with CSI?1000h. Once a mouse mode is enabled, Xterm sends control codes back to the application on mouse click and/or movement. (Wheel scrolling is interpreted as clicks on one of two additional buttons.)

    We would have to make the current mouse mode part of the synchronized terminal state, and interpret the mode-switching codes on the server. In the other direction, mouse reports can be part of the normal user input stream, and we might not even have to parse them client-side (but see below).

    There is an orthogonal mode bit for "extended mouse mode" (CSI?1005h). In extended mode, the mouse reports encode position as UTF-8 characters. Without extended mode, "positions outside (160,94) result in byte pairs which can be interpreted as a single UTF-8 character; applications which do treat their input as UTF-8 will almost certainly be confused". By this I think they mean that the position is a single byte per axis, but that byte might have bit 7 set.

    So regardless of what happens on the server, we want mosh-client to be in extended mouse mode. Unfortunately this was only recently added in Xterm, and isn't supported by my urxvt or gnome-terminal: these terminals send a single-byte position no matter what. And we'd still need to translate in the case where the remote application isn't expecting UTF-8 positions.

    There is also a problem of synchronization between terminal state and the user input stream. If the remote application has already disabled mouse mode, but the client doesn't know yet, will the remote app get a stream of unexpected mouse reports? For this reason we might have to parse mouse events client-side and send them as a type of input event separate from keypresses.

    So it's all a right mess, but definitely something users want.

  5. keithw commented on Apr 11, 2012

    @keithw
    Member

    Thanks for looking into all that. I think for the very last issue, what you propose (parsing the mouse events client-side) is definitely the right thing.

    The whole thing sounds pretty annoying though, especially if the clean approach only works in literal xterm.

  6. saurik commented on Apr 16, 2012

    @saurik
    Contributor

    I have probably simply misinterpreted this explanation, but to verify: the idea is not to have the client always be in mouse mode, correct? It is normally the case that using "set mouse=a" and "set mouse=" in vim can switch your local terminal between using local and remote mouse events. If the local console were always using remote mouse events then it would become impossible to highlight/copy text locally in many terminals (such as iTerm2) and in others it would be possible but would require a modifier key.

  7. kmcallister commented on Apr 16, 2012

    @kmcallister
    Contributor

    the idea is not to have the client always be in mouse mode, correct?

    Correct. The mouse mode would be part of the state synchronized between the server (authoritative) and the client.

    When I say "we want mosh-client to be in extended mouse mode", I'm referring to the independent bit that means "if we're in mouse mode, send positions as UTF-8 rather than single bytes". But I think this is not really usable because it's only supported by recent Xterm.

  8. HunterWare commented on May 3, 2012

    @HunterWare

    I'll just chime in that this is blocking my switching to mosh. Otherwise it's basically perfect for my needs and generally great.

  9. Mikaela commented on May 3, 2012

    @Mikaela

    I'll just chime in that this is blocking my switching to mosh.
    Otherwise it's basically perfect for my needs and generally great.

    Almost same for me.

    I use mosh with everything else than WeeChatting. I am missing mouse with WeeChat, because it makes channel list script, buffers.pl, more useful in my opinion and mouse is nice to have with htop too, but it's easy to use even without mouse.

  10. Synchro commented on Jun 22, 2012

    @Synchro

    @saurik you can use mouse events in iTerm2 - just press option to use local mouse control.

  11. kimtore commented on Jun 22, 2012

    @kimtore

    I would also very much like to see this feature implemented. Using vim, I often use the mouse to scroll up and down. Through mosh, this is impossible. But if the feature was implemented, I would switch over completely :)

  12. Synchro commented on Jun 22, 2012

    @Synchro

    To be fair, I think screen presents quite a few problems for passing on mouse events too.

  13. andersk commented on Jun 26, 2012

    @andersk
    Member

    The special case of scrolling up and down in applications like vim won’t actually need full mouse mode support. For that it’s enough to make sure that the client puts the real terminal in alternate screen mode (#2).

  14. grawity commented on Jun 29, 2012

    @grawity

    @andersk, I believe that depends on the terminal used. For example, GNOME Terminal (and other vte-based terms) will translate scroll events to Up/Down arrow keys while in alt screen mode, but other terminals (Xterm, PuTTY) will not, and full mouse support remains necessary.

  15. FiXato commented on Jan 16, 2013

    @FiXato

    A workaround to this issue is to enable utf8 mouse mode before starting mosh.
    For instance, running:
    perl -E ' print "\e[?1005h\e[?1002h" '
    before starting mosh allows me to use mouse support in my WeeChat client.

  16. 56 remaining items

  17. paulmiu commented on Mar 24, 2015

    @paulmiu

    tl;dr: The main problem was the local installation. Now there's another problem with mouse on tmux.

    Ok, I could solve the problem. The reason was, that I thought mosh on the client would automatically start the mosh-server which is given by which mosh-server on the server. But that's not true because .bashrc, .bash_profile (and all the other shell config files) aren't executed before starting the mosh-server, so the $PATH variable isn't set to the user specific paths and therefore the old mosh-server globally installed on the server is executed.
    So I have to mosh into my server with

    mosh --server="export LD_LIBRARY_PATH=/path/to/protobuf/installation/lib && /path/to/mosh/installation/mosh-server" -p 61234 [email protected]

    after install mosh locally with this guide: https://gist.github.com/mamiu/24066ed58c158787c72f.

    But now I have another problem: I can select text or panes only once, after that the mouse is disabled/locked. It behaves like the mouse outside tmux (or tmux with mouse mode disabled). This behavior doesn't occur when selecting windows at the bottom tmux bar (but after selecting text a second time I also can't switch windows with the mouse). Here's another person with the same problem: http://superuser.com/questions/882602/mouse-click-only-works-once-with-iterm2-tmux-mosh

    Thanks a lot for all your help!

  18. chrisjohnson commented on Mar 24, 2015

    @chrisjohnson

    Correct @niieani, I'm positively using the right installation. I blew away old installations first, which mosh-server verifies this. There's no other mosh-server on my filesystem. I'll try to give that demo a try over the next couple days. Thanks for the help

  19. mgd43b commented on Mar 28, 2015

    @mgd43b

    I've just compiled on the client and server from the git commit c6cd99b version.

    I'm also seeing the behavior that I'm only able to select panes once. I'm also using iTerm2 + mosh + tmux.

    thanks.

  20. randywallace commented on Mar 28, 2015

    @randywallace

    Actually, I just recently went thru this step (getting my client and server on the latest code) last night, via https://github.com/randywallace/mosh-portfile, and ran into this as well. On my gateway server, I'm running also on c6cd99b. I thought it may have had something to do with the fact that I'm running nested tmux servers on several remote hosts (even tho everything works fine over plain-ole ssh), but seeing as how this is replicable by @dickinsonmg without my complicated setup, I am less inclined to think that is the issue.

    I compiled and ran the demo over mosh to see what happened:

    $ ./demo -m -p 1002
    Mouse mode active
    <MousePress(4)> at line=47, col=130
    <MousePress(4)> at line=47, col=130
    <MousePress(5)> at line=47, col=130
    <MousePress(5)> at line=47, col=130
    <MousePress(4)> at line=47, col=130
    <MousePress(4)> at line=47, col=130
    <MousePress(5)> at line=47, col=130
    <MousePress(5)> at line=47, col=130
    <MousePress(4)> at line=51, col=236
    <C-c>
    Mouse mode deactivated
    

    It only works initially, or works for a little while, but it usually isn't long before I have to restart my mosh client->server connection to regain behavior. For example, if I start a new connection, open vim, set mouse=a, i can scroll all day long as long as I am in vim. Swap between insert/visual, visual select with the mouse, yank, paste, go back to visual mouse, no problem. If, though, I exit vim, then reopen vim, set mouse=a, and try again, it no longer works. Or sometimes it does.

    Check this out:

    ~/git/libtermkey-0.17$ ./demo -m -p 1005
    Mouse mode active
    <MousePress(5)> at line=32, col=204
    <MousePress(5)> at line=32, col=204
    <MousePress(4)> at line=32, col=204
    <MousePress(4)> at line=32, col=204
    <MousePress(5)> at line=32, col=204
    <MousePress(5)> at line=32, col=204
    <MousePress(4)> at line=32, col=204
    <MousePress(5)> at line=32, col=204
    <C-c>
    Mouse mode deactivated
    ~/git/libtermkey-0.17$ C`A`A`AaAaAaA`A`A`Aa
    

    Note that the terminal after running the demo with mode 1005 throws strange characters on the terminal when I scroll the mouse. One time, even thought the terminal was showing that, I could still open vim, set mouse=a, and scrolling still works fine. Tmux scrolling was not working though.

    BUT, in that case, I run the demo again afterward with 1002, I still get the libtermkey expected output. When I attempt to open vim afterward, though, and scroll, it won't work. Likewise, after running 1002, If I try 1005 again, that one won't work anymore either.

    Also, things occasionally get really whacky and this happens (the character between MousePress(es) changed every time I ran the demo):

    ~/git/libtermkey-0.17$ ./demo -m -p 1005
    Mouse mode active
    <MousePress(5)> at line=145, col=162
    P
    <MousePress(4)> at line=145, col=162
    P
    <MousePress(5)> at line=145, col=162
    P
    <C-c>
    Mouse mode deactivated
    

    Not sure what to make of all this, but I hope this helps :) In the meantime, I'll just keep resetting my mosh connection when I need mouse support and it isn't working (woot, tmux).

  21. chrisjohnson commented on Jul 11, 2015

    @chrisjohnson

    Just wanted to comment that miraculously, without ever touching either installation, the issue has gone away and mouse support works as of today. I just went to try libtermkey and it worked great, tested in vim, worked great, and as of yet I'm not even having any inconsistencies like @randywallace. I did nothing more than mosh my-host so perhaps a reboot on host or client cleared it up. Anyway thanks

  22. niieani commented on Jul 11, 2015

    @niieani
    Contributor

    @chrisjohnson thanks for the update. So it turns out it's like I said - the implementation is good, the problems were with the client/server installations...

  23. danielb2 commented on Jul 30, 2015

    @danielb2

    perl -E ' print "\e[?1005h\e[?1002h" ' no longer works with 1.2.5

  24. danielb2 commented on Jul 30, 2015

    @danielb2

    I made sure the mosh-server and client are both 1.2.5 but still no luck. Any idea what could be up with that?

  25. chrisjohnson commented on Jul 30, 2015

    @chrisjohnson

    The print trick should no longer be necessary. Make sure you build from source on both using the same commit. Then try manually specifying the full path to the binaries to be sure you call the built version

    On Jul 29, 2015, at 11:09 PM, Daniel Bretoi [email protected] wrote:

    perl -E ' print "\e[?1005h\e[?1002h" ' no longer works with 1.2.5

    So this didn't get fixed but was made worse?

    —
    Reply to this email directly or view it on GitHub.

  26. danielb2 commented on Jul 30, 2015

    @danielb2

    Well, you made me double-check the versions which was good because for some reason the server did not get upgraded and was still stuck on 1.2.4. Thanks a bundle :)

  27. sparr commented on Dec 18, 2015

    @sparr

    I'm encountering this issue with 1.2.5

    On Xubuntu, my mouse works fine in xterm+ssh and intermittently fails (scrolls the window buffer) with xterm+mosh.

    On OSX, my mouse behaves as arrow keys in Terminal+ssh and Terminal+mosh. my mouse works as expected in iTerm2+ssh and always fails with iTerm2+mosh

  28. cgull commented on Dec 19, 2015

    @cgull
    Member

    Reports on mosh-1.2.5's mouse functionality have generally been positive, and I use mosh, iTerm2, xterm, and weechat regularly and it all works.
    Are you sure you have mosh-1.2.5 installed on both clients and server? The mouse functionality is unlikely to work right if you have an older version of mosh installed at either end.
    What application are you running on the server?

  29. jamorales-bsft commented on Jul 7, 2016

    @jamorales-bsft

    on mac osx el capitan when I use the scroll wheel in a mosh terminal it goes through previous command as if I was pressing the up and down arrow keys. It does not actually scroll the terminal window at all.

  30. timotheecour commented on Aug 25, 2016

    @timotheecour

    @keithw , having the same issue:

    ssh+tmux+mouse works
    mosh+tmux+mouse doesn't work

    mosh version=1.2.6 on both client and server
    (ssh-ing from OSX to ubuntu, using iterm2)

  31. andersk commented on Aug 25, 2016

    @andersk
    Member

    @jamorales-bsft, @timotheecour: You are probably seeing #640 regarding iTerm2’s deep tmux integration (which, for reasons described there, only works over SSH), rather than this issue. You can get some level of mouse support in tmux without iTerm2’s deep integration by turning on tmux mouse mode (tmux < 2.1: set -g mode-mouse on, tmux ≥ 2.1: set -g mouse on).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions