github.com/buildpacks/pack@v0.33.3-0.20240516162812-884dd1837311/internal/termui/fakes/docker_stdwriter.go (about) 1 package fakes 2 3 import ( 4 "io" 5 "time" 6 7 "github.com/docker/docker/pkg/stdcopy" 8 ) 9 10 type DockerStdWriter struct { 11 wOut io.Writer 12 wErr io.Writer 13 } 14 15 func NewDockerStdWriter(w io.Writer) *DockerStdWriter { 16 return &DockerStdWriter{ 17 wOut: stdcopy.NewStdWriter(w, stdcopy.Stdout), 18 wErr: stdcopy.NewStdWriter(w, stdcopy.Stderr), 19 } 20 } 21 22 func (w *DockerStdWriter) WriteStdoutln(contents string) { 23 w.write(contents+"\n", stdcopy.Stdout) 24 } 25 26 func (w *DockerStdWriter) WriteStderrln(contents string) { 27 w.write(contents+"\n", stdcopy.Stderr) 28 } 29 30 func (w *DockerStdWriter) write(contents string, t stdcopy.StdType) { 31 switch t { 32 case stdcopy.Stdout: 33 w.wOut.Write([]byte(contents)) 34 case stdcopy.Stderr: 35 w.wErr.Write([]byte(contents)) 36 } 37 38 // guard against race conditions 39 time.Sleep(time.Millisecond) 40 }