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 terminal opcodes #210

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

aymanbagabas
Copy link
Contributor

All credit goes to @maisem and Tailscale tailscale/tailscale#4154

Fixes: #98
Fixes: #131

Updates tailscale/tailscale#4146

Signed-off-by: Maisem Ali <maisem@tailscale.com>
Co-Authored-By: Ayman Bagabas <ayman.bagabas@gmail.com>
@belak
Copy link
Collaborator

belak commented Jul 31, 2023

I want to make sure I understand this right before merging it in, so I might not get to this right away. @bradfitz might also be a good person to weigh in. Also @maisem who implemented this in tailscale's ssh fork.

Additionally, could we use this to replace the hard-coded \n to \r\n translation, using something like this block in the referenced PR?

@aymanbagabas
Copy link
Contributor Author

The emulation emulates Termios ONLCR mode which maps NL-CRNL (terminals 🙄).

This would only matter if the modes are used with PTY allocation. In that case, the emulation might corrupt the terminal and we would have to disable it to make the allocated PTY work correctly. A possible solution is to be able to disable the emulation. Something like 4f6e0b5. Otherwise, and if breaking the API is an option, users can opt-in using a PTYWriter interface #185.

@belak
Copy link
Collaborator

belak commented Aug 2, 2023

A breaking change would be completely reasonable for better PTY support. Realistically, for most people it wouldn't even matter because the existing behavior is less than ideal and is really just a hacky workaround.

@aymanbagabas
Copy link
Contributor Author

So more down the rabbit hole of SSH/PTY support. OpenSSH client sets the terminal into raw mode when the client requests a PTY session. 12 This sets the OPOST output flag which enables processing the output data using flags like ONLCR.

This means if you have this flag disabled before establishing an SSH session, the terminal wouldn't produce the right output because we always emulate the ONLCR flag. Instead, assuming we remove the emulation from the library, we should allocate a PTY and pass the SSH PTY request terminal modes to the allocated PTY to get the correct output (with ONLCR disabled).

Footnotes

  1. https://github.com/openssh/openssh-portable/blob/master/clientloop.c#L1350

  2. https://github.com/openssh/openssh-portable/blob/master/sshtty.c#L69

@belak
Copy link
Collaborator

belak commented Sep 26, 2023

Is working on better PTY support you'd be interested in, or not really? I realize that's a fairly big ask though, especially compared to what you're asking for in this PR.

@aymanbagabas
Copy link
Contributor Author

Is working on better PTY support you'd be interested in, or not really? I realize that's a fairly big ask though, especially compared to what you're asking for in this PR.

I've implemented PTY support here. This is based off #185 and #210. It uses go-pty.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Terminal modes
3 participants