pico

created pr with ps-210 on 2026-02-26T03:15:38Z · by c8ef7d19
changed status to accepted on 2026-02-26T19:32:17Z · by c8ef7d19
cmds
checkout latest patchset:
ssh pr.pico.sh print pr-118 | git am -3
checkout any patchset in a patch request:
ssh pr.pico.sh print ps-X | git am -3
add changes to patch request:
git format-patch main --stdout | ssh pr.pico.sh pr add 118
set PR to open (enables RSS notifications):
ssh pr.pico.sh pr open 118
set PR to draft (stops RSS notifications):
ssh pr.pico.sh pr draft 118

Patchset ps-210 on 2026-02-26T03:15:38Z · commit b10aef1

+27 -0 pkg/pssh/server.go #
@@ -1,6 +1,7 @@
 package pssh
 
 import (
+	"bytes"
 	"context"
 	"crypto/ed25519"
 	"crypto/rand"
@@ -185,6 +186,32 @@ func (s *SSHServerConnSession) Pty() (*Pty, <-chan Window, bool) {
 	return s.pty, s.winch, true
 }
 
+// Write overrides the embedded Channel's Write to normalize line endings when PTY is allocated.
+func (s *SSHServerConnSession) Write(p []byte) (n int, err error) {
+	s.mu.Lock()
+	hasPty := s.pty != nil
+	s.mu.Unlock()
+
+	if !hasPty {
+		// No PTY, write as-is
+		return s.Channel.Write(p)
+	}
+
+	// When PTY is active, normalize line endings like a real terminal would.
+	// Replace \n with \r\n, but avoid double \r\n.
+	normalized := bytes.ReplaceAll(p, []byte{'\n'}, []byte{'\r', '\n'})
+	normalized = bytes.ReplaceAll(normalized, []byte{'\r', '\r', '\n'}, []byte{'\r', '\n'})
+
+	// Write the normalized data
+	written, err := s.Channel.Write(normalized)
+
+	// Return the count based on original data length, not normalized
+	if written > len(p) {
+		written = len(p)
+	}
+	return written, err
+}
+
 var _ context.Context = &SSHServerConnSession{}
 
 func (sc *SSHServerConn) Handle(chans <-chan ssh.NewChannel, reqs <-chan *ssh.Request) error {
Back to top