Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 5 additions & 8 deletions cmd/display/tty.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
}
Expand Down
4 changes: 2 additions & 2 deletions cmd/formatter/logs.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)
Expand Down Expand Up @@ -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
}

Expand Down
17 changes: 13 additions & 4 deletions cmd/formatter/shortcut.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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 {
Expand All @@ -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
}
3 changes: 1 addition & 2 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
3 changes: 0 additions & 3 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -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=
Expand Down Expand Up @@ -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=
Expand Down
Loading