gnome-terminator / terminator

multiple GNOME terminals in one window
https://gnome-terminator.org
GNU General Public License v2.0
2.09k stars 252 forks source link

add or merge Tmux control mode support #79

Open yosefrow opened 4 years ago

yosefrow commented 4 years ago

(Feature request)

Tmux control mode would allow users to connect terminator to a tmux session and represent the tmux session with the Terminator GUI.

As I understand this feature has already implemented at https://github.com/manno/terminator .

I added an issue to that repo as well. So maybe the author will respond and look into merging his code into this main repo.

But if for some reason he is not able to do so, I want to at least raise awareness that the feature seems to exist for those who are interested.

mattrose commented 4 years ago

This looks really good. Hopefully the user who owns the fork will craft a proper pull request against this repo. If not, we'll still look at it, but I personally don't use tmux that much, so any guidance you could give would help. What are people looking for from tmux integration?

mattrose commented 4 years ago

Looking further. Wow, that's a lot of work they've done. Hopefully they'd be willing to work with us, as that terminator code is probably missing all the python3 fixes.

yosefrow commented 4 years ago

@mattrose

TLDR:

I'm sure there are more features that a more advanced user might know about. But personally, I'm looking for the following:

As an intermediate level tmux user, I think I can best provide an insight by describing my use of tmux.

Because I administrate multiple systems remotely, I find myself more often than not logging into the remote server and then running tmux inside terminator, because otherwise I'd have to ssh many times (every time I opened a tab). Opening tmux inside the remote server, saves me time and headache associated with constantly connecting. But it also allows me to save my sessions remotely and reconnect to them the next day, or between laptop reboots.

Sometimes, even though I have no work to do on the remote server, I actually open a tmux session on the remote server, just because I want to continue where I left off the next day. I know that there are some plugins that allow you to save terminator sessions. But so far I haven't found one that accurately saves the buffer of all active windows/tabs and the window/tab configurations.

Additionally, I appreciate the fact that the tmux status bar allows you to dynamically and contextually display any text you want. It is the closest I've seen to a "task bar" that you typically find on desktop systems and it adds just enough extra benefit, that I can permanently live in my terminal in full screen. For example, you can place small scripts that will add a kubernetes or git context indicator for your current folder, hostname, cpu info, memory usage, clock etc (instead of shoving it on to the end of my already overloaded bash prompt!).

Lastly, even when my entire desktop crashes, my tmux session may survive. So my shell work flow can exist independent of my gui. e.g. If my desktop crashes then just move to a Linux tty and attach to the tmux session I was using in terminator!

mattrose commented 4 years ago

Thanks. This was very instructive and it really does sound like something good to have, and according to https://unix.stackexchange.com/questions/189805/what-terminal-emulators-support-tmux-control-mode it's not widely available. I hope the authors of that fork get in touch, because that would be much quicker than me trying to integrate their code.

yosefrow commented 4 years ago

@mattrose

I hope so as well. As I mentioned, I opened an issue in the author's repo. So I hope they will be in touch soon :)

Also, I forgot to mention one of the most interesting features in tmux, which is the ability to share sessions between multiple clients. This means that one user can start a session and multiple people can connect to it remotely (through ssh) or locally and optionally control the session (in the same window, or even a separate window). Basically desktop-sharing for terminals!

I'd love to see this feature supported in Terminator as well through the Tmux control mode :)

iamjackg commented 3 years ago

I contacted the original author of the fork via email, and he said he's going to try and rebase his changes on the new codebase :)

mattrose commented 3 years ago

Oh good. I definitely want more/better tmux integration, but I don't use it enough to know what is important or give it a thorough test.

manno commented 3 years ago

I had to squash all the commits from Dan and Andrea, who did most of the tmux work back in 2016. Sadly I just wasn't able to preserve the commit history when merging.

I created https://github.com/gnome-terminator/terminator/pull/378, but it is not working. However all the code is there and it only hangs when started in tmux mode. Maybe someone with more knowledge of terminator (and/or tmux control mode) can fix this easily? Otherwise I'm not giving up on this, might just take a while :)

theotheroracle commented 3 years ago

oh gods yes i'm so hyped for this, might take a look at the code in a bit and see if i can get it working

iamjackg commented 3 years ago

I've been working on an MR for this, but the original code might be a bit too outdated to get working properly.

https://github.com/gnome-terminator/terminator/pull/408

I started a rewrite of the implementation, but haven't had much time to work on it recently.

theotheroracle commented 3 years ago

oh great ! thanks

theotheroracle commented 3 years ago

is your rewrite of the implementation posted anywhere ? i'm not sure what would be best for me to work on atm

iamjackg commented 3 years ago

My first attempt to merge it is here, but it's currently broken: #408

I've been working on a new version, but I have to say I'm very disheartened by it all. In an ideal world the feature should be bidirectional, i.e. any changes made within tmux should be reflected in real time in Terminator and vice versa, but it's turning out to be really difficult to do. You can really tell that Terminator wasn't built with something like this in mind.

As an example, when a new pane (a Terminal in terminator speak) is created in tmux by splitting an existing pane, all we get is a layout-change notification: we don't know exactly what changed. It's simple enough to figure out what changed by comparing the two layout definitions, but we run into another problem: tmux considers a vertical split with 3 terminals as a single vertical split with 3 children, whereas in Terminator this is accomplished with a second vertical pane within the first vertical pane. No problem! The original implementation of this feature came with a neat tmux-to-Terminator layout translator, so it's easy to figure out what's different. But now we need to actually apply that change, and that's really difficult (read: would require a lot of work) given the way Terminator is implemented.

One option is to translate all the possible changes to an actual operation: if we recognize that a tmux pane was split, for example, we can run a split command on the corresponding Terminator pane. That's also not trivial: there's no real way to traverse the tree of translated layout children and tie them to actual widgets, so we'd have to populate a global mapping as the layout is being created. Then the new terminal would need to know that it's a tmux terminal, but the only current way to pass that information is through the layout and the create_layout function.

Another option could be to destroy and recreate the window with the new layout?

Long story short: this is a big, big mess and it would take a huge amount of work to get it working, a lot more than I originally expected. The original implementation got away with a bunch of stuff because it never accounted for changes made on the tmux side of things, but I feel like having that is kind of a must? Or rather, the actual limitation is that you would only be able to either run the session via tmux or via Terminator, but never both at the same time.

Let me know your thoughts. As it is, I'm probably gonna drop it since I don't really have enough time to invest in this :disappointed:

iamjackg commented 3 years ago

(This is still doable, at least in a limited way, if we decide to completely drop the bidirectional sync and have Terminator drive most of the logic -- it just means that things might get messed up if people use tmux in the background to modify the shared session while Terminator is running)

iamjackg commented 3 years ago

In classic programmer fashion, I think I had an epiphany overnight :laughing: I'm testing a couple things and it might actually be doable -- if not I can always fall back on the one at a time approach.

mattrose commented 3 years ago

Thanks again for all your work on this. I wish I could do more than offer encouragement and support, but I've never used tmux or even screen really, so I have no idea what's necessary. If you have any questions or need anything from me, please don't hesitate to ask. I'm usually around on https://gitter.im/gnome-terminator/community

iamjackg commented 3 years ago

No worries! I was a bit frustrated because I really wanted to get bidirectional sync working, and I think I finally nailed it. Slowly adding the rest of the functionality in. Here's a sneak peek :)

https://user-images.githubusercontent.com/19474350/124389751-9791b780-dcb6-11eb-9230-019a2db4157c.mp4

iamjackg commented 3 years ago

Just FYI I didn't die -- life got in the way and my free time suddenly went to almost zero. I'm hoping to pick this up again soon!

mattrose commented 3 years ago

No problem, I figured it was something like that, and wasn't worried. Thanks again and I appreciate everything you've done so far.

freeqaz commented 3 years ago

@iamjackg If you're willing to throw your code up (even in WIP state) it'd be helpful. If I have some time in the near future to work on this, this is definitely high up on my priority list. Every time I try to copy-paste in tmux I am reminded of why I want this so badly!

And for anybody looking at this in the future, this terminal emulator also seems to support tmux CC mode. I haven't used it yet though, so I can't say if it's actually good or not: https://eternalterminal.dev/

iamjackg commented 3 years ago

Yeah, it looks like I won't be able to spend much time on this for a while. Sorry :(

I pushed all my changes here: https://github.com/iamjackg/terminator/tree/tmux-v2

It's very much in a WIP state, i.e. a huge mess. To get started with it, I suggest you diff it with the current main branch and start following the flow from here: https://github.com/iamjackg/terminator/blob/tmux-v2/terminator#L133

Good luck! If you have any questions post them here, and I'll try to answer when I have a moment :)

rrnewton commented 2 years ago

I wanted to chime in as someone who uses tmux constantly but only in a very basic way (for the tabs+scrollback history). @iamjackg, based on your assessment above, would it be far easier to get something basic working with:

?

yurenchen000 commented 1 year ago

@freeqaz: And for anybody looking at this in the future, this terminal emulator also seems to support tmux CC mode. I haven't used it yet though, so I can't say if it's actually good or not: https://eternalterminal.dev/

eternalterminal site not a terminal anymore. it's a ssh (server,client) replacement (with connection keeper) nowdays.

I also have one tool: works with open-ssh (as a proxyCommand), so can't survive after ssh client gone https://github.com/yurenchen000/ssh-keep

yurenchen000 commented 1 year ago

@rrnewton

  • no support for panes, just separate tabs
  • no bidirectional sync (and thus probably no session sharing with others)

I think it's fine (and greatly simplifies the problem):