Terminal: [Terminal] VT Mouse Support

Created on 8 May 2019  路  38Comments  路  Source: microsoft/terminal

  • Your Windows build number: (Type ver at a Windows Command Prompt)

10.0.18890.1000

  • What you're doing and what's happening: (Copy & paste specific commands and their output, or include screen shots)

I routinely use mouse mode in tmux with WSL for window selection, pane resizing, and scrollback, enabled in tmux.conf thus:

  # -- mouse support ---------------------------------------------------------                                                                                                                                                                                        
  # Enable mouse control (clickable windows, panes, resizable panes)                                                                
  set -g mouse on

While this works perfectly in conhost, it does not work at all in Terminal; nothing happens, as if the mouse events were never reaching tmux.

  • What's wrong / what should be happening instead:

tmux mouse support (and presumably other mouse-supporting applications) should work as they do in conhost.

Area-Input Area-VT Issue-Feature Product-Terminal Resolution-Fix-Committed

Most helpful comment

I'm eagerly awaiting this to show up in a future release - I keep clicking on tmux panes in hopes the mouse will work :)

All 38 comments

Yea, this is a known issue at the moment. We need to add support for mouse in two places: both in the terminal, to be able to synthesize mouse sequences, and in conpty to be able to read mouse sequences.

This issue is tracking the first bit, the Terminal functionality.

For the second bit, the conpty part, see #376.

Sadly this does not work, having the mouse events with TMUX would defer the need to have multiple panes.
I hope this feature get implemented before the panes, is much needed and will solve most of issues

I would like to point out that the mouse support is also not supported in tmux within Docker (through Powershell). I know this is because the functionality simply isn't there in Terminal so of course it won't work in WSL or Docker, but thought I'd go ahead and mention it.

the mouse does work with TMUX in WSL

Mouse works with wsltty: https://github.com/mintty/wsltty

@guibirow Maybe it's an issue with Docker from within Terminal then.

No. It's not an issue with Docker. It's an issue with conpty (this repo). Try wsltty if you want mouse support.

Are there plans to enable full mouse support in tmux for Docker in the future through Terminal?

I don't know about Docker specifically, but i don't see why it should be any different than a normal terminal. This issue is about that, so keep an eye out!

So I just checked tmux through WSL 1 in Terminal and the mouse isn't supported there either. So my guess is that tmux itself just doesn't work in Terminal at this point and that it's not a Docker issue. Not sure what @guibirow was seeing on his end.

You have to run a command to enable it, isn't enabled by default.
I don't have it right now, but it is simple like this set mouse on
I will have to confirm next week when I get my laptop

It only works on wsl terminal though, not in the new windows terminal

Oh I gotcha. Yeah it works fine in the plain WSL window. It only fails to work when embedded within the new Windows Terminal.

If you implement mouse support, please make sure to implement the SGR (1006) extension as well.

The legacy, byte-based protocol only allows row and column numbers up to 223, because 32 is added to this number and this is sent as a single byte. The column limit is not uncommon to be too small. (By the way, beginning at column 95 the generated data is not 7-bit clean and not valid UTF-8 which is a problem for encoding conversion layers such as luit.)

The SGR 1006 extension fixes these problems by encoding the numbers as decimal digits, and is supported by plenty of applications.

If this extension is not requested, please don't generate any event if the row or column exceeds 223. Otherwise an overflow could have nasty consequences. E.g. clicking on column 227 could generate the byte 32+227 = 259 = 3 = Ctrl+C which is typically the interrupt character sending a SIGINT to the running process.

So! Conhost actually does support DECSET 1006! Since we have this intervening layer (the pseudoconsole, which needs to talk to conhost), we get to choose what sort of mouse mode the pseudoconsole requests and supports. I see no reason that that shouldn't just be 1006 :smile: Thanks for the info!

To clarify, because we have conhost in the middle, that would look like this:

                                      |                 |
                 DECSET 1002, 1005    | Windows conhost |
+-------------+                       |  (in PTY mode)  |
|             +----------------------->                 |
| Application |                       |                 |
|             <-----------------------+                 |
+-------------+                       |                 |
                 mouse information    |                 |
                 1002 in 1005 format  |                 |
                                      |                 |
                                      +---+---------^---+
                                          |         |
                                          |         | mouse information in
                         DECSET 1002,1006 |         | SGR Extended Format
                                          |         | (1002+1006)
                                          |         |
                                      +---v---------+---+
                                      |                 |
                                      | Windows         |
                                      |  Terminal       |
                                      |                 |
                                      |                 |
                                      |                 |
                                      |                 |
                                      +-----------------+

Did you mean 1005 between the application and conhost, or is that a typo in this picture? Mouse extensions 1005 and 1015 also exist but they are hardly used (if at all) due to their flaws, it's not something that applications are interested in.

1005 (xterm's two-byte UTF-8), 1015 (urxvt) and 1006 (xterm SGR), in this chronological order, are three mutually exclusive extensions to address the limitation of the column number. See e.g. Midnight Commander issues 2662 and 2956 for technical description about the flaws of the first two. Note that this story is now 6-8 years old. I'm not aware of any application that supports the problematic 1005 and/or 1015 but not the okay 1006. As such, I don't see any point in implementing support for the first two (although it should be very easy to implement them).

That very well could be a typo, right now, conhost actually supports a bunch of different mouse modes, including, but not limited to 1005 and 1006.

It鈥檚 not a typo. Sorry, this was intended to illustrate how the pseudoconsole system could support a bunch of mouse modes on the client end (an application requests 1005, 1015, legacy VT220, etc.) but present a unified mouse mode interface (1006) to the pty pipe holder.

That diagram admittedly fits better in #376, which is the infrastructural part of this bug.

@DHowett-MSFT Awesome, thanks for the clarification!

I'm eagerly awaiting this to show up in a future release - I keep clicking on tmux panes in hopes the mouse will work :)

Any progress on this?

@sandric Not particularly - when there's something of note to share, we'll make sure to post in this thread 馃槣

@carlos-zamora is starting this work this month (as you can see from the "assigned to" and "milestone" fields to the right). He's got a PR (#3963) out starting on work for #376, one of the prerequisites for this feature.

@zadjii-msft The PR you linked says it was merged Is that correct now?

Based on the comment in the release notes:

The pseudoconsole will now process mouse escapes, but it won't do much useful with them yet (#3963)

It seems not (yet). I'm staying tuned!

@fpqc yep, that's correct, that one PR was merged. From that discussion, there's still a bunch of work needed before this will work fully in the Terminal:

  • [ ] Conpty emits a [sequence] on entering any mouse mode to tell terminals that they should synthesize VT Mouse Mode input as SGR sequences (with hover, scroll, etc)
  • [ ] Conhost translates Mouse input into VT from both conpty and the HWND the same way
  • [ ] Terminal can consume [sequence] to synthesize VT mouse mode input

And then of course, this issue:

  • [ ] Terminal synthesizes mouse input sequences

How do we copy the text when VT Mouse is enabled? I couldn't do it on Vim or Tmux.

Hold down shift to interact with the terminal itself instead of the application inside it.

This is so great! When will we see a preview of this in the Store?

Stay tuned

Downloaded from the shop! The mouse is working great in VIM, htop and Tmux. Finally, time to move from all other WSL Terminal to the microsoft one ! Good job guys and thanks a lot !

PS: shift is working great too !

Just came here looking for why mouse wasn't working ... read the most recent comment from @yveslange and then updated the app ... and now mouse works perfect.

Thanks guys!

@DHowett-MSFT : Mouse still doesn't work for me with Micro (https://github.com/zyedidia/micro), whereas both mouse and scrollwheel work flawlessly in the default powershell or cmd.exe terminal. Is mouse support only working in WSL for now ?

@nicolus indeed, mouse input only works for WSL applications currently. If you're using the Win32 version of micro, I'd bet that it won't work quite yet. You could probably work around this by running the WSL version for now. #376 is the issue we're using for the Windows mouse input

@zadjii-msft
Mouse events don't work for me with a custom profile with "commandline": "ssh [...]". Is this also expected until #376 is resolved? Is there a good workaround?

Edit: Or is that just a result of PowerShell/Win32-OpenSSH#1310 and would work otherwise?

This is a result of https://github.com/PowerShell/Win32-OpenSSH/issues/1310, which is (mercifully) fixed in the 8.x series.

@DHowett-MSFT Thanks for the quick reply. In that case, is there a sane way to manually upgrade to a version with the fix right now or is it better to just wait?

Sure, just download the latest release from their Releases page!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

NickITGuy picture NickITGuy  路  3Comments

dev-logan picture dev-logan  路  3Comments

mrmlnc picture mrmlnc  路  3Comments

warpdesign picture warpdesign  路  3Comments

ghvanderweg picture ghvanderweg  路  3Comments