Skip to content

Commit 1a1da3b

Browse files
committed
fix: consume resize events on pty
1 parent 7ffdd48 commit 1a1da3b

File tree

1 file changed

+11
-23
lines changed

1 file changed

+11
-23
lines changed

session.go

Lines changed: 11 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,8 @@ import (
44
"errors"
55
"fmt"
66
"io"
7+
"log"
78
"net"
8-
"runtime"
99
"sync"
1010

1111
"github.com/anmitsu/go-shlex"
@@ -366,11 +366,14 @@ func (sess *session) handleRequests(reqs <-chan *gossh.Request) {
366366
defer closer() // nolint: errcheck
367367

368368
if !sess.EmulatedPty() {
369-
if err := resizePty(sess, ptyReq.Window); err != nil {
370-
// TODO: handle error
371-
req.Reply(false, nil)
372-
continue
373-
}
369+
go func() {
370+
for win := range sess.winch {
371+
if err := resizePty(sess, win); err != nil {
372+
// TODO: handle error
373+
continue
374+
}
375+
}
376+
}()
374377
}
375378
}
376379

@@ -380,21 +383,16 @@ func (sess *session) handleRequests(reqs <-chan *gossh.Request) {
380383
}()
381384
req.Reply(ok, nil)
382385
case "window-change":
386+
log.Printf("window resize event")
383387
if sess.pty == nil {
384388
req.Reply(false, nil)
385389
continue
386390
}
387391
win, _, ok := parseWindow(req.Payload)
388392
if ok {
393+
log.Printf("window resize %dx%d", win.Width, win.Height)
389394
sess.pty.Window = win
390395
sess.winch <- win
391-
if !sess.EmulatedPty() {
392-
if err := resizePty(sess, win); err != nil {
393-
// TODO: handle error
394-
req.Reply(false, nil)
395-
continue
396-
}
397-
}
398396
}
399397
req.Reply(ok, nil)
400398
case agentRequestType:
@@ -418,11 +416,6 @@ func (sess *session) handleRequests(reqs <-chan *gossh.Request) {
418416
}
419417

420418
func (s *session) ptyAllocate(term string, win Window, modes gossh.TerminalModes) (func() error, error) {
421-
if runtime.GOOS == "windows" {
422-
// TODO: handle ConPty
423-
return nil, nil
424-
}
425-
426419
p, err := newPty(s.ctx, term, win, modes)
427420
if err != nil {
428421
return nil, err
@@ -439,11 +432,6 @@ func (s *session) ptyAllocate(term string, win Window, modes gossh.TerminalModes
439432
}
440433

441434
func resizePty(sess *session, win Window) error {
442-
if runtime.GOOS == "windows" {
443-
// TODO: handle ConPty
444-
return nil
445-
}
446-
447435
if sess.pty == nil {
448436
return nil
449437
}

0 commit comments

Comments
 (0)