github.com/drone/runner-go@v1.12.0/pipeline/streamer/console/plain.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 "strings" 11 ) 12 13 // plain text line format with line number. 14 const plainf = "[%s:%d] %s\n" 15 16 type plain struct { 17 base io.Writer 18 name string 19 seq *sequence 20 } 21 22 func (w *plain) Write(b []byte) (int, error) { 23 for _, part := range split(b) { 24 fmt.Fprintf(w.base, plainf, w.name, w.seq.next(), part) 25 } 26 return len(b), nil 27 } 28 29 func (w *plain) Close() error { 30 return nil 31 } 32 33 func split(b []byte) []string { 34 s := string(b) 35 s = strings.TrimSuffix(s, "\n") 36 return strings.Split(s, "\n") 37 }