Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement tmux control mode (-CC) #5612

Closed
browell opened this issue Apr 28, 2020 · 3 comments
Closed

Implement tmux control mode (-CC) #5612

browell opened this issue Apr 28, 2020 · 3 comments
Labels
Issue-Feature Complex enough to require an in depth planning process and actual budgeted, scheduled work. Resolution-Duplicate There's another issue on the tracker that's pretty much the same thing.

Comments

@browell
Copy link

browell commented Apr 28, 2020

Description

Tmux/Screen has long been considered an essential tool when working in terminals on Linux, and a huge portion of all WSL users are likely using tmux.

With the introduction of panes in the latest release, it is now reasonable to consider integrating with tmux's control mode (tmux -CC). This is a textual interface provided by tmux specifically for the purpose of integrating with terminal emulators. The most prominent example of such integration is iTerm2.

This would build on the existing pane implementation to allow terminal windows displaying a tmux session to essentially function as a renderer of tmux's state in the following ways:

  • Panes created/destroyed in tmux would create/destroy corresponding panes in windows terminal, and vice versa.

  • Changes in size to panes in either tmux or windows terminal would be mirrored respectively.

  • Text selections within windows terminal would therefore be limited by the presence of native panes, and prevented from spanning multiple panes.

  • Window names would be updated based on the name for the active pane within a tmux session.

  • It may or may not be helpful to pass through raw keystrokes to tmux to allow them to be interpreted, and the output reinterpreted by the terminal emulator so that users can make use of existing tmux key bindings.

Doing this would allow for native-feeling experiences even for terminals over SSH; reduce configuration for tmux users; and gloss over some of the awkwardness of overlapping functionality. For example, a terminal emulator can't provide tmux's persistence functionality and therefore will never replace it, but the presence of panes within panes within panes (vim within tmux within a terminal emulator that has panes...) can get quite awkward and difficult to manage. It also reduces the experience of latency when working with tmux.

Implementation details

To spy on an tmux session's control codes, open a tmux session in one terminal window, and in another, attach to the same session with tmux -CC attach. You will now see the outputted control codes for every action within tmux in the original window, including the raw text output for each pane.

From the man pages:
`
CONTROL MODE

 tmux offers a textual interface called control mode.  This allows
 applications to communicate with tmux using a simple text-only proto‐
 col.

 In control mode, a client sends tmux commands or command sequences ter‐
 minated by newlines on standard input.  Each command will produce one
 block of output on standard output.  An output block consists of a
 %begin line followed by the output (which may be empty).  The output
 block ends with a %end or %error.  %begin and matching %end or %error
 have two arguments: an integer time (as seconds from epoch) and command
 number.  For example:

       %begin 1363006971 2
       0: ksh* (1 panes) [80x24] [layout b25f,80x24,0,0,2] @2 (active)
       %end 1363006971 2

 The refresh-client -C command may be used to set the size of a client
 in control mode.

 In control mode, tmux outputs notifications.  A notification will never
 occur inside an output block.

 The following notifications are defined:

 %client-session-changed client session-id name
         The client is now attached to the session with ID session-id,
         which is named name.

 %exit [reason]
         The tmux client is exiting immediately, either because it is
         not attached to any session or an error occurred.  If present,
         reason describes why the client exited.

 %layout-change window-id window-layout window-visible-layout
         window-flags
         The layout of a window with ID window-id changed.  The new lay‐
         out is window-layout.  The window's visible layout is
         window-visible-layout and the window flags are window-flags.

 %output pane-id value
         A window pane produced output.  value escapes non-printable
         characters and backslash as octal \xxx.

 %pane-mode-changed pane-id
         The pane with ID pane-id has changed mode.

 %session-changed session-id name
         The client is now attached to the session with ID session-id,
         which is named name.

 %session-renamed name
         The current session was renamed to name.

 %session-window-changed session-id window-id
         The session with ID session-id changed its active window to the
         window with ID window-id.

 %sessions-changed
         A session was created or destroyed.

 %unlinked-window-add window-id
         The window with ID window-id was created but is not linked to
         the current session.

 %window-add window-id
         The window with ID window-id was linked to the current session.

 %window-close window-id
         The window with ID window-id closed.

 %window-pane-changed window-id pane-id
         The active pane in the window with ID window-id changed to the
         pane with ID pane-id.

 %window-renamed window-id name
         The window with ID window-id was renamed to name.

`

In Summary

Windows Terminal should detect when tmux is launched in control mode (tmux -CC), and should start rendering the parsed output described above using native GUI panes. It would be reasonable to prevent non-tmux panes from being created in this mode, or otherwise create placeholder panes within the tmux session displaying some simple but useful representation of what is in the pane.

When the window is closed, session is detached. Tmux is left running. This would also facilitate persistent layouts without the need to implement it natively.

The ability to create profiles which automatically attach to a tmux session would enhance the usefulness of this feature.

@browell browell added the Issue-Feature Complex enough to require an in depth planning process and actual budgeted, scheduled work. label Apr 28, 2020
@ghost ghost added Needs-Triage It's a new issue that the core contributor team needs to triage at the next triage meeting Needs-Tag-Fix Doesn't match tag requirements labels Apr 28, 2020
@j4james
Copy link
Collaborator

j4james commented Apr 28, 2020

This looks like a duplicate of #3656.

@zadjii-msft
Copy link
Member

Thanks for the triage @j4james, and the great writeup @browell. We'll make sure to reference this as we're implementing control mode (in the future).

/dup #3656

@ghost
Copy link

ghost commented Apr 28, 2020

Hi! We've identified this issue as a duplicate of another one that already exists on this Issue Tracker. This specific instance is being closed in favor of tracking the concern over on the referenced thread. Thanks for your report!

@ghost ghost closed this as completed Apr 28, 2020
@ghost ghost added Resolution-Duplicate There's another issue on the tracker that's pretty much the same thing. and removed Needs-Triage It's a new issue that the core contributor team needs to triage at the next triage meeting Needs-Tag-Fix Doesn't match tag requirements labels Apr 28, 2020
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Issue-Feature Complex enough to require an in depth planning process and actual budgeted, scheduled work. Resolution-Duplicate There's another issue on the tracker that's pretty much the same thing.
Projects
None yet
Development

No branches or pull requests

3 participants