Skip to content

Commit 7ff3cf6

Browse files
nicochebchatelard
authored andcommitted
Exec: disable term resizes on windows
SIGWINCH does not exist, it breaks the build
1 parent 088beb1 commit 7ff3cf6

File tree

3 files changed

+66
-38
lines changed

3 files changed

+66
-38
lines changed

pkg/koyeb/instances_exec.go

Lines changed: 0 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -54,32 +54,6 @@ func (h *InstanceHandler) exec(cmd *cobra.Command, args []string) (int, error) {
5454
return e.Run(ctx)
5555
}
5656

57-
func watchTermSize(ctx context.Context, s *StdStreams) <-chan *TerminalSize {
58-
out := make(chan *TerminalSize)
59-
go func() {
60-
defer close(out)
61-
sigCh := make(chan os.Signal, 1)
62-
signal.Notify(sigCh, syscall.SIGWINCH)
63-
for {
64-
select {
65-
case <-ctx.Done():
66-
return
67-
case <-sigCh:
68-
termSize, err := GetTermSize(s.Stdout)
69-
if err != nil {
70-
continue
71-
}
72-
select {
73-
case <-ctx.Done():
74-
return
75-
case out <- termSize:
76-
}
77-
}
78-
}
79-
}()
80-
return out
81-
}
82-
8357
// Disclaimer: parts of this file are either taken or largey inspired from Nomad's CLI
8458
// implementation (command/alloc_exec.go) or API implementation (api/allocations_exec.go)
8559

@@ -445,15 +419,3 @@ func GetStdStreams() (*StdStreams, func() error, error) {
445419
}
446420
return stdStreams, resetTermState, nil
447421
}
448-
449-
func GetTermSize(t io.Writer) (*TerminalSize, error) {
450-
fd, isTerm := term.GetFdInfo(t)
451-
if !isTerm {
452-
return nil, errors.New("not a terminal")
453-
}
454-
ws, err := term.GetWinsize(fd)
455-
if err != nil {
456-
return nil, errors.Wrap(err, "cannot get winsize")
457-
}
458-
return &TerminalSize{Height: int32(ws.Height), Width: int32(ws.Width)}, nil
459-
}

pkg/koyeb/instances_exec_unix.go

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
//go:build !windows
2+
// +build !windows
3+
4+
package koyeb
5+
6+
import (
7+
"context"
8+
"io"
9+
"os"
10+
"os/signal"
11+
"syscall"
12+
13+
"github.com/moby/term"
14+
15+
"github.com/pkg/errors"
16+
)
17+
18+
func watchTermSize(ctx context.Context, s *StdStreams) <-chan *TerminalSize {
19+
out := make(chan *TerminalSize)
20+
go func() {
21+
defer close(out)
22+
sigCh := make(chan os.Signal, 1)
23+
signal.Notify(sigCh, syscall.SIGWINCH)
24+
for {
25+
select {
26+
case <-ctx.Done():
27+
return
28+
case <-sigCh:
29+
termSize, err := getTermSize(s.Stdout)
30+
if err != nil {
31+
continue
32+
}
33+
select {
34+
case <-ctx.Done():
35+
return
36+
case out <- termSize:
37+
}
38+
}
39+
}
40+
}()
41+
return out
42+
}
43+
44+
func getTermSize(t io.Writer) (*TerminalSize, error) {
45+
fd, isTerm := term.GetFdInfo(t)
46+
if !isTerm {
47+
return nil, errors.New("not a terminal")
48+
}
49+
ws, err := term.GetWinsize(fd)
50+
if err != nil {
51+
return nil, errors.Wrap(err, "cannot get winsize")
52+
}
53+
return &TerminalSize{Height: int32(ws.Height), Width: int32(ws.Width)}, nil
54+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
//go:build windows
2+
// +build windows
3+
4+
package koyeb
5+
6+
import (
7+
"context"
8+
)
9+
10+
func watchTermSize(ctx context.Context, s *StdStreams) <-chan *TerminalSize {
11+
return nil
12+
}

0 commit comments

Comments
 (0)