proof of concept: allow spawning remote shell
This allows something like
iex> {:ok, tty} = ExTTY.start_link(handler: self(), node: :"mynode@myhost")
There is a problem though (therefore only as draft and no tests yet): IEx autocomplete doesn't work because it tries to run autocompletion on the wrong node (https://github.com/elixir-lang/elixir/blob/70391199a481c7d3ccb2756c99452ee7dc8ad12f/lib/iex/lib/iex/server.ex#L328-L335). Not sure how to fix this. Maybe someone else has an idea how to do this "properly".
@SteffenDE This is pretty cool. I have never tried this myself and don't have any ideas to suggest sadly.
Neat! I'm curious what the motivation is here? I can't seem to think of a case I'd want to use this over calling :rpc programmatically to execute remote code which is isolated from the current process by design?
Neat! I'm curious what the motivation is here? I can't seem to think of a case I'd want to use this over calling
:rpcprogrammatically to execute remote code which is isolated from the current process by design?
In our management interface at work we have a special section for developers with some tools. My idea was to add an integrated iex shell as well for the (rare) cases where we currently directly connect with the node. This works just fine for accessing the current node, but as we are clustered I wanted to add a node selection like in the phoenix live dashboard, that's where this PR comes from. This could probably also be integrated as a custom page into the live dashboard itself.
aahhh! Interesting. So really having the whole TTY-like experience at the client rather than have to implement more on the remote to handle transporting the IO back and forth 🤔
For the expand, I am unsure. I might be able to help think through ideas this weekend. My first thought is to try to manually call ExTTY.send_text(tty, ":io.setopts(expand_fun: IEx.Autocomplete.remsh(node))") and see if that works first? (or I might have the problem backwards)
Good idea! The problem is that IEx resets the expand fun in its loop. So that won't work.
or I might have the problem backwards
It would be :io.setopts(expand_fun: &IEx.Autocomplete.expand/1), because (I think) we want the remote node to expand the code itself.
I just noticed that this works fine when the node hosting the terminal is not running in IEx itself. So maybe this solution is fine after all. I'll try to see what happens when deploying this in a release.
https://gist.github.com/SteffenDE/f4ca9af33bbc3a0cd06109ea486efd07
Autocomplete works in a release. Not sure what would be the best way to test this. I'll add some documentation soon.
There is one annoying problem when using this together with something like xterm.js from a LiveView page: the terminal width seems to be hardcoded here: https://github.com/jjcarstens/extty/blob/15938dbc2461fa8153e1dfbc06a1837157e046bd/src/tty_pty.hrl#L31-L34
and there's no way to override it or react to a window resize. That's a separate issue though.
Thanks!
You should be able to use window_change to alter the height and width for that remote console case
https://github.com/jjcarstens/extty/blob/15938dbc2461fa8153e1dfbc06a1837157e046bd/lib/extty.ex#L27
Ah well, I should have looked into the docs first. Works perfectly, thank you!