From f0d758445e194194ac17991b4fd34929fd1b0daa Mon Sep 17 00:00:00 2001 From: Ayman Bagabas Date: Thu, 21 Sep 2023 15:20:28 -0400 Subject: [PATCH] feat: disable pty emulation This adds the ability to disable the session's PTY emulation from translating NL to CRLN. This is needed when allocating PTYs and applying their terminal modes from the session PTY request. --- session.go | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/session.go b/session.go index aaa7b75..0df5401 100644 --- a/session.go +++ b/session.go @@ -82,6 +82,13 @@ type Session interface { // the request handling loop. Registering nil will unregister the channel. // During the time that no channel is registered, breaks are ignored. Break(c chan<- bool) + + // DisablePtyEmulation disables the session from emulating a pty when a pty + // is requested. If you're allocating a pty for the session, you should + // call this method to disable the pty emulation before any call to Write. + // This affects the behavior of Stderr() and Write and stops them from + // translating NL -> CRNL (`\n` -> `\r\n`). + DisablePtyEmulation() } // maxSigBufSize is how many signals will be buffered @@ -125,17 +132,22 @@ type session struct { sigCh chan<- Signal sigBuf []Signal breakCh chan<- bool + disablePtyEmu bool +} + +func (sess *session) DisablePtyEmulation() { + sess.disablePtyEmu = true } func (sess *session) Stderr() io.ReadWriter { - if sess.pty != nil { + if sess.pty != nil && !sess.disablePtyEmu { return NewPtyReadWriter(sess.Channel.Stderr()) } return sess.Channel.Stderr() } func (sess *session) Write(p []byte) (int, error) { - if sess.pty != nil { + if sess.pty != nil && !sess.disablePtyEmu { return NewPtyWriter(sess.Channel).Write(p) } return sess.Channel.Write(p)