Skip to content

Commit 4f6e0b5

Browse files
Maisem Alimaisem
Maisem Ali
authored andcommitted
document behavior of NL to CRNL translation in Write and add a way to disable it.
Updates tailscale/tailscale#4146 Signed-off-by: Maisem Ali <[email protected]>
1 parent 851f95c commit 4f6e0b5

File tree

1 file changed

+29
-17
lines changed

1 file changed

+29
-17
lines changed

session.go

Lines changed: 29 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,13 @@ type Session interface {
8383
// the request handling loop. Registering nil will unregister the channel.
8484
// During the time that no channel is registered, breaks are ignored.
8585
Break(c chan<- bool)
86+
87+
// DisablePTYEmulation disables the session's default minimal PTY emulation.
88+
// If you're setting the pty's termios settings from the Pty request, use
89+
// this method to avoid corruption.
90+
// Currently (2022-03-12) the only emulation implemented is NL-to-CRNL translation (`\n`=>`\r\n`).
91+
// A call of DisablePTYEmulation must precede any call to Write.
92+
DisablePTYEmulation()
8693
}
8794

8895
// maxSigBufSize is how many signals will be buffered
@@ -110,26 +117,31 @@ func DefaultSessionHandler(srv *Server, conn *gossh.ServerConn, newChan gossh.Ne
110117
type session struct {
111118
sync.Mutex
112119
gossh.Channel
113-
conn *gossh.ServerConn
114-
handler Handler
115-
subsystemHandlers map[string]SubsystemHandler
116-
handled bool
117-
exited bool
118-
pty *Pty
119-
winch chan Window
120-
env []string
121-
ptyCb PtyCallback
122-
sessReqCb SessionRequestCallback
123-
rawCmd string
124-
subsystem string
125-
ctx Context
126-
sigCh chan<- Signal
127-
sigBuf []Signal
128-
breakCh chan<- bool
120+
conn *gossh.ServerConn
121+
handler Handler
122+
subsystemHandlers map[string]SubsystemHandler
123+
handled bool
124+
exited bool
125+
pty *Pty
126+
winch chan Window
127+
env []string
128+
ptyCb PtyCallback
129+
sessReqCb SessionRequestCallback
130+
rawCmd string
131+
subsystem string
132+
ctx Context
133+
sigCh chan<- Signal
134+
sigBuf []Signal
135+
breakCh chan<- bool
136+
disablePtyEmulation bool
137+
}
138+
139+
func (sess *session) DisablePTYEmulation() {
140+
sess.disablePtyEmulation = true
129141
}
130142

131143
func (sess *session) Write(p []byte) (n int, err error) {
132-
if sess.pty != nil {
144+
if sess.pty != nil && !sess.disablePtyEmulation {
133145
m := len(p)
134146
// normalize \n to \r\n when pty is accepted.
135147
// this is a hardcoded shortcut since we don't support terminal modes.

0 commit comments

Comments
 (0)