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

Add support for Headless Terminal Multiplexer (htm) #2988

Closed
wants to merge 3 commits into from

Conversation

MisterTea
Copy link
Contributor

@MisterTea MisterTea commented May 8, 2018

As discussed in #2406 and #2978 , a terminal multiplexer that integrates with the terminal emulator would be a great addition to Hyper.js. I initially looked into integrating the existing solution, tmux control center, but tmux -CC has no defined spec and is difficult to reverse engineer. As a result, I wrote my own headless terminal multiplexer called HTM. HTM will be packaged with the next version of Eternal Terminal ( https://mistertea.github.io/EternalTerminal/ ).

The core idea is that htm runs inside of ssh/et and sends commands to Hyper.js (or any other terminal emulator). Hyper.js gets a special ANSI escape sequence which puts hyper in HTM mode, and then the current state of the tabs/panes. As users make tabs, delete tabs, or type in panes, all of this is funneled through htm. If someone exits hyper.js and comes back, running htm restores the state when the person exited. To see a demo of how this works, check out https://www.youtube.com/watch?v=Ea6Y08tP-RI&feature=youtu.be

This PR is a WIP because I assume it's a big enough change that it will require more iterations before it's ready to merge. It's 100% functional and can be tried by following these instructions:

  • First, check out the htm branch of eternal terminal and build the source (see https://github.com/MisterTea/EternalTerminal#building-from-source ).
  • Then, ensure that htm and htmd are in your path by copying to /usr/local/bin or modifying your .bashrc/.zshrc
  • Then, build & run yarn with this PR.
  • Inside hyper (can be in an ssh session or not), run htm
  • Do some work
  • Close hyper.js
  • re-open and re-run htm
  • your state is preserved.

@ppot
Copy link
Contributor

ppot commented May 8, 2018

Can you create a new one with only your changes by pulling the latest version? 90k line of addition if very difficult to track. @chabou What's your take on this?

@MisterTea MisterTea changed the base branch from canary to master May 8, 2018 16:47
@MisterTea
Copy link
Contributor Author

@ppot Sorry about that: it was using the canary as the base instead of master.

@albinekb
Copy link
Contributor

albinekb commented May 9, 2018

Really cool! However I think this is better suited as a plugin, since it's not a thing that will be used by even 1% of hyper users, I think most of the stuff you're doing is already possible from a plugin, and if we need to expose more API for you to be able to pull it off I think that's a better way to do it than to integrate this deeply into hyper itself.

Thoughts?

@MisterTea
Copy link
Contributor Author

@albinekb Sure, I'm fine with making it a plugin, but we will need to make some core changes either way. I'll see how much I can move over.

@albinekb
Copy link
Contributor

albinekb commented May 9, 2018

@chabou what do you think?

@MisterTea
Copy link
Contributor Author

@albinekb So I started looking into it. Most of the logic can go into a plugin. The hardest part is the code in window.js. I have a new type of Session class that doesn't open a pty but instead forwards all the keystrokes to the session that's running htm. I may change that from Session/HtmSession to PtySession/DummySession and make the DummySession go through RPC to send/receive data.

@albinekb
Copy link
Contributor

albinekb commented May 10, 2018

Awesome to hear, yes, that sounds like a plan that could support more other interesting plugins too! 👍 see my comment here as to why we want as much as possible in a plugin 🙏

@MisterTea
Copy link
Contributor Author

MisterTea commented May 12, 2018

@albinekb Alright, I've moved as much as I can out to a plugin: https://github.com/MisterTea/hyper-htm

Overall, the core changes remaining can be described as follows:

  • Actions to create a term group / session now optionally take a termGroupUid and sessionUid so the HTM uid and Hyper uid remain in sync
  • Split actions now take a sessionUid and also a sourceUid instead of splitting from the active session. These are also optional and revert to the current behavior when empty
  • A new class, FollowerSession, that does not contain a PTY but instead forwards all input & resize requests to the window
  • Functions in window.js were modified to make it easier to override them in a plugin

I'm leaving the WIP tag on because I still need to test more edge cases and also replace iTerm with this on my own machines and use it for a few days. In the meantime it would be great to get feedback.

@MisterTea
Copy link
Contributor Author

I changed the logic so initSession is now a function inside the window class, and this way the plugin can override it. With this change, the FollowerSession logic can move entirely into the plugin and the overall change to hyper.js becomes pretty small.

@albinekb albinekb requested review from leo and chabou May 13, 2018 23:49
@MisterTea MisterTea changed the title [WIP] Add support for Headless Terminal Multiplexer (htm) Add support for Headless Terminal Multiplexer (htm) May 14, 2018
@Stanzilla Stanzilla added the 🎨 Type: Enhancement Issue or PR is an enhancement request/proposal for Hyper label May 16, 2018
@MisterTea
Copy link
Contributor Author

@albinekb I just realized that active development is happening on the canary branch, not the master branch. I have a branch in my fork called "htmcanary" that is the same changes rebased on the canary branch. Should I open a new PR with that branch?

@albinekb
Copy link
Contributor

Yes please 🙏 Sorry for not noticing 🙈 @MisterTea

@MisterTea
Copy link
Contributor Author

Moved to #3026

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🎨 Type: Enhancement Issue or PR is an enhancement request/proposal for Hyper
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants