github.com/drone/runner-go@v1.12.0/pipeline/streamer/console/pretty.go (about) 1 // Copyright 2019 Drone.IO Inc. All rights reserved. 2 // Use of this source code is governed by the Polyform License 3 // that can be found in the LICENSE file. 4 5 package console 6 7 import ( 8 "fmt" 9 "io" 10 ) 11 12 // pretty line format with line number and coloring. 13 const prettyf = "\033[%s[%s:%d]\033[0m %s\n" 14 15 // available terminal colors 16 var colors = []string{ 17 "32m", // green 18 "33m", // yellow 19 "34m", // blue 20 "35m", // magenta 21 "36m", // cyan 22 } 23 24 type pretty struct { 25 base io.Writer 26 color string 27 name string 28 seq *sequence 29 } 30 31 func (w *pretty) Write(b []byte) (int, error) { 32 for _, part := range split(b) { 33 fmt.Fprintf(w.base, prettyf, w.color, w.name, w.seq.next(), part) 34 } 35 return len(b), nil 36 } 37 38 func (w *pretty) Close() error { 39 return nil 40 }