spiegel_podman/cmd/podman/common/term.go
Paul Holzinger 8ef234aedd
remove github.com/buger/goterm dependency
this is just a few bytes of escape codes, there is no need to depend on
a library for it. While it is not a big one it still seems better to
just write it ourselves.

Signed-off-by: Paul Holzinger <pholzing@redhat.com>
2025-03-31 19:17:55 +02:00

19 lines
543 B
Go

package common
import (
"os"
"golang.org/x/term"
)
// ClearScreen clears the screen and puts the cursor back to position 1,1
// Useful when printing output in an interval like podman stats.
// When the stdout is not a terminal this is a NOP.
func ClearScreen() {
// Only write escape sequences when the output is a terminal.
if term.IsTerminal(int(os.Stdout.Fd())) {
// terminal escape control sequence to clear screen ([2J)
// followed by putting the cursor to position 1,1 ([1;1H)
os.Stdout.WriteString("\033[2J\033[1;1H")
}
}