From 13c771c84e6b86cebe6df14d0e92001f940581ba Mon Sep 17 00:00:00 2001 From: JP Appel Date: Tue, 8 Oct 2024 13:17:03 -0400 Subject: Move ansi stripper to util package --- api/docker.go | 33 --------------------------------- 1 file changed, 33 deletions(-) (limited to 'api/docker.go') diff --git a/api/docker.go b/api/docker.go index c79b76d..551c818 100644 --- a/api/docker.go +++ b/api/docker.go @@ -5,7 +5,6 @@ import ( "fmt" "io" "log/slog" - "regexp" "time" "github.com/docker/docker/api/types/container" @@ -14,38 +13,6 @@ import ( const vttContainerId string = "foundry-foundry-1" -// Strip ansi control characters from source -// -// The source reader is automatically closed when stripper reader is -type ansiStripper struct { - regex regexp.Regexp - source io.ReadCloser -} - -func NewAnsiStripper(source io.ReadCloser) *ansiStripper { - striper := new(ansiStripper) - striper.regex = *regexp.MustCompile(`\x1b[[0-9;]*m`) - striper.source = source - - return striper -} - -func (rc ansiStripper) Read(p []byte) (int, error) { - n, err := rc.source.Read(p) - if err != io.EOF && err != nil { - return n, err - } - - stripped := rc.regex.ReplaceAll(p[:n], []byte("")) - n = copy(p, stripped) - - return n, err -} - -func (rc ansiStripper) Close() error { - return rc.source.Close() -} - func stopVtt(ctx context.Context) error { apiClient, err := client.NewClientWithOpts(client.FromEnv, client.WithAPIVersionNegotiation()) if err != nil { -- cgit v1.2.3