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

feat: replace newlines with crlf newlines when in a pty #185

Closed
wants to merge 4 commits into from

Conversation

caarlos0
Copy link
Contributor

Writing to the stdout of the session already handles replacing \n with \r\n, but the stderr didn't had the same treatment.

Created another io.Writer wrapper that can be used in both, and a "session.SafeStderr()` that returns it.

PS: pretty sure "safe writer" is not a good name, also considered "crlf writer", let me know if you like one better than the other, or maybe yet another name

session.go Outdated
// with the extended data type set to stderr. Stderr may
// safely be read and written from a different goroutine than
// Read and Write respectively.
Stderr() io.ReadWriter
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't this be a plain io.Writer? I'm fairly certain you can't read data from stderr.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

IMHO it could, but it comes as a readwriter from ssh.Channel: https://pkg.go.dev/golang.org/x/crypto/ssh#Channel

which we embed on our session here:

ssh/session.go

Line 23 in db09465

gossh.Channel

That said, if I try to change it to writer only, it won't compile... so unfortunately I think there's no other way (besides maybe a new stderr method with another name).

Signed-off-by: Carlos A Becker <caarlos0@users.noreply.github.com>

// NewPtyWriter creates a writer that handles when the session has a active
// PTY, replacing the \n with \r\n.
func NewPtyWriter(w io.Writer) io.Writer {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to export NewPtyWriter and NewPtyReadWriter?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good question... I don't think we need to export, but I think it would be nicer if we do... whatever @belak decides is fine by me though.

Add session.Stderr test

Fixes: 993008d ("refactor: keeping the same Stderr method")
@aymanbagabas
Copy link
Contributor

@belak Could you take a look at this?

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.

3 participants