diff --git a/app/backend/internal/cli/commands/exec.go b/app/backend/internal/cli/commands/exec.go index c63a099..ef0c03d 100644 --- a/app/backend/internal/cli/commands/exec.go +++ b/app/backend/internal/cli/commands/exec.go @@ -4,9 +4,7 @@ import ( "fmt" "net/http" "os" - "os/signal" "strings" - "syscall" "time" "github.com/gorilla/websocket" @@ -44,20 +42,13 @@ var ShellCmd = &cobra.Command{ if err == nil { defer term.Restore(fd, oldState) } - if w, h, err := term.GetSize(fd); err == nil { - _ = conn.WriteJSON(map[string]interface{}{"type": "resize", "cols": w, "rows": h}) - } - // Forward SIGWINCH resizes. - sigCh := make(chan os.Signal, 1) - signal.Notify(sigCh, syscall.SIGWINCH) - defer signal.Stop(sigCh) - go func() { - for range sigCh { - if w, h, err := term.GetSize(fd); err == nil { - _ = conn.WriteJSON(map[string]interface{}{"type": "resize", "cols": w, "rows": h}) - } + sendSize := func() { + if w, h, err := term.GetSize(fd); err == nil { + _ = conn.WriteJSON(map[string]interface{}{"type": "resize", "cols": w, "rows": h}) } - }() + } + sendSize() + defer watchResize(sendSize)() } done := make(chan struct{}) diff --git a/app/backend/internal/cli/commands/exec_resize_unix.go b/app/backend/internal/cli/commands/exec_resize_unix.go new file mode 100644 index 0000000..e9506d5 --- /dev/null +++ b/app/backend/internal/cli/commands/exec_resize_unix.go @@ -0,0 +1,30 @@ +//go:build !windows + +package commands + +import ( + "os" + "os/signal" + "syscall" +) + +// watchResize forwards SIGWINCH events to send. Returns a stop func. +func watchResize(send func()) func() { + sigCh := make(chan os.Signal, 1) + signal.Notify(sigCh, syscall.SIGWINCH) + done := make(chan struct{}) + go func() { + for { + select { + case <-sigCh: + send() + case <-done: + return + } + } + }() + return func() { + signal.Stop(sigCh) + close(done) + } +} diff --git a/app/backend/internal/cli/commands/exec_resize_windows.go b/app/backend/internal/cli/commands/exec_resize_windows.go new file mode 100644 index 0000000..5daa897 --- /dev/null +++ b/app/backend/internal/cli/commands/exec_resize_windows.go @@ -0,0 +1,8 @@ +//go:build windows + +package commands + +// watchResize is a no-op on Windows — console resize events don't map to a +// signal. The initial size is still sent, and Windows Terminal resize is rare +// enough to accept stale dimensions for now. +func watchResize(send func()) func() { return func() {} }