From 6233903c57eec3fcb0105dfa6fd91ae4904213f1 Mon Sep 17 00:00:00 2001 From: Sebastiaan van Stijn Date: Fri, 4 Sep 2026 19:53:35 +0200 Subject: [PATCH] chore: remove github.com/buger/goterm dependency Replace goterm's terminal size detection with golang.org/x/term, which provides the same functionality and is already an indirect dependency. Use the existing github.com/morikuni/aec dependency for clearing the current terminal line. Signed-off-by: Sebastiaan van Stijn --- cmd/display/tty.go | 13 +++++-------- cmd/formatter/logs.go | 4 ++-- cmd/formatter/shortcut.go | 17 +++++++++++++---- go.mod | 3 +-- go.sum | 3 --- 5 files changed, 21 insertions(+), 19 deletions(-) diff --git a/cmd/display/tty.go b/cmd/display/tty.go index 9f379c13d42..32938d5e2eb 100644 --- a/cmd/display/tty.go +++ b/cmd/display/tty.go @@ -21,15 +21,16 @@ import ( "fmt" "io" "iter" + "os" "slices" "strings" "sync" "time" "unicode/utf8" - "github.com/buger/goterm" "github.com/docker/go-units" "github.com/morikuni/aec" + "golang.org/x/term" "github.com/docker/compose/v5/pkg/api" "github.com/docker/compose/v5/pkg/utils" @@ -321,13 +322,9 @@ type lineData struct { } func (w *ttyWriter) print() { - terminalWidth := goterm.Width() - terminalHeight := goterm.Height() - if terminalWidth <= 0 { - terminalWidth = 80 - } - if terminalHeight <= 0 { - terminalHeight = 24 + terminalWidth, terminalHeight, err := term.GetSize(int(os.Stdout.Fd())) + if err != nil || terminalWidth <= 0 || terminalHeight <= 0 { + terminalWidth, terminalHeight = 80, 24 } w.printWithDimensions(terminalWidth, terminalHeight) } diff --git a/cmd/formatter/logs.go b/cmd/formatter/logs.go index e0799a3fbde..d7834d09f02 100644 --- a/cmd/formatter/logs.go +++ b/cmd/formatter/logs.go @@ -25,8 +25,8 @@ import ( "sync" "time" - "github.com/buger/goterm" "github.com/moby/moby/client/pkg/jsonmessage" + "github.com/morikuni/aec" "github.com/docker/compose/v5/pkg/api" ) @@ -131,7 +131,7 @@ func (l *logConsumer) write(w io.Writer, container, message string) { func (l *logConsumer) Status(container, msg string) { p := l.getPresenter(container) - s := p.colors(fmt.Sprintf("%s%s %s\n", goterm.RESET_LINE, container, msg)) + s := p.colors(fmt.Sprintf("\r%s%s %s\n", aec.EraseLine(aec.EraseModes.Tail), container, msg)) l.stdout.Write([]byte(s)) //nolint:errcheck } diff --git a/cmd/formatter/shortcut.go b/cmd/formatter/shortcut.go index ffa083e2f84..def93dc2ab6 100644 --- a/cmd/formatter/shortcut.go +++ b/cmd/formatter/shortcut.go @@ -26,10 +26,10 @@ import ( "syscall" "time" - "github.com/buger/goterm" "github.com/compose-spec/compose-go/v2/types" "github.com/eiannone/keyboard" "github.com/skratchdot/open-golang/open" + "golang.org/x/term" "github.com/docker/compose/v5/internal/desktop" "github.com/docker/compose/v5/internal/tracing" @@ -149,12 +149,12 @@ func (lk *LogKeyboard) printNavigationMenu() { lk.createBuffer(offset) if lk.logLevel == INFO { - height := goterm.Height() menu := lk.navigationMenu() carriageReturn() saveCursor() + _, height := getTermSize() lk.kError.printError(height, menu) moveCursor(height-extraLines(menu), 0) @@ -191,11 +191,11 @@ func (lk *LogKeyboard) navigationMenu() string { } func (lk *LogKeyboard) clearNavigationMenu() { - height := goterm.Height() carriageReturn() saveCursor() // clearLine() + _, height := getTermSize() for range height { moveCursorDown(1) clearLine() @@ -376,7 +376,8 @@ func allocateSpace(lines int) { } func extraLines(s string) int { - return int(math.Floor(float64(lenAnsi(s)) / float64(goterm.Width()))) + width, _ := getTermSize() + return int(math.Floor(float64(lenAnsi(s)) / float64(width))) } func shortcutKeyColor(key string) string { @@ -390,3 +391,11 @@ func shortcutKeyColor(key string) string { func navColor(key string) string { return ansiColor(FAINT, key) } + +func getTermSize() (width, height int) { + width, height, err := term.GetSize(int(os.Stdout.Fd())) + if err != nil || width <= 0 || height <= 0 { + return 80, 24 + } + return width, height +} diff --git a/go.mod b/go.mod index c061e04d5c9..ff1a9998046 100644 --- a/go.mod +++ b/go.mod @@ -7,7 +7,6 @@ require ( github.com/DefangLabs/secret-detector v0.0.0-20250403165618-22662109213e github.com/Microsoft/go-winio v0.6.3-0.20251027160822-ad3df93bed29 github.com/acarl005/stripansi v0.0.0-20180116102854-5a71ef0e047d - github.com/buger/goterm v1.0.4 github.com/compose-spec/compose-go/v2 v2.15.0 github.com/containerd/console v1.0.5 github.com/containerd/containerd/v2 v2.3.4 @@ -54,6 +53,7 @@ require ( go.yaml.in/yaml/v4 v4.0.0-rc.6 golang.org/x/sync v0.22.0 golang.org/x/sys v0.47.0 + golang.org/x/term v0.45.0 google.golang.org/grpc v1.83.2 gotest.tools/v3 v3.5.2 tags.cncf.io/container-device-interface v1.1.0 @@ -127,7 +127,6 @@ require ( go.yaml.in/yaml/v3 v3.0.5 // indirect golang.org/x/crypto v0.56.0 // indirect golang.org/x/net v0.58.0 // indirect - golang.org/x/term v0.45.0 // indirect golang.org/x/text v0.41.0 // indirect golang.org/x/time v0.15.0 // indirect google.golang.org/genproto/googleapis/api v0.0.0-20260825221802-da73d73af1c5 // indirect diff --git a/go.sum b/go.sum index 92032c13677..c5b3da0fb2f 100644 --- a/go.sum +++ b/go.sum @@ -20,8 +20,6 @@ github.com/anchore/go-struct-converter v0.1.0 h1:2rDRssAl6mgKBSLNiVCMADgZRhoqtw9 github.com/anchore/go-struct-converter v0.1.0/go.mod h1:rYqSE9HbjzpHTI74vwPvae4ZVYZd1lue2ta6xHPdblA= github.com/beorn7/perks v1.0.1 h1:VlbKKnNfV8bJzeqoa4cOKqO6bYr3WgKZxO8Z16+hsOM= github.com/beorn7/perks v1.0.1/go.mod h1:G2ZrVWU2WbWT9wwq4/hrbKbnv/1ERSJQ0ibhJ6rlkpw= -github.com/buger/goterm v1.0.4 h1:Z9YvGmOih81P0FbVtEYTFF6YsSgxSUKEhf/f9bTMXbY= -github.com/buger/goterm v1.0.4/go.mod h1:HiFWV3xnkolgrBV3mY8m0X0Pumt4zg4QhbdOzQtB8tE= github.com/cenkalti/backoff/v5 v5.0.3 h1:ZN+IMa753KfX5hd8vVaMixjnqRZ3y8CuJKRKj1xcsSM= github.com/cenkalti/backoff/v5 v5.0.3/go.mod h1:rkhZdG3JZukswDf7f0cwqPNk4K0sa+F97BxZthm/crw= github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UFvs= @@ -344,7 +342,6 @@ golang.org/x/sync v0.22.0/go.mod h1:9xrNwdLfx4jkKbNva9FpL6vEN7evnE43NNNJQ2LF3+0= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190222072716-a9d3bda3a223/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= -golang.org/x/sys v0.0.0-20210331175145-43e1dd70ce54/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20210616094352-59db8d763f22/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220412211240-33da011f77ad/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=