github.com/lmorg/murex@v0.0.0-20240217211045-e081c89cd4ef/builtins/types/hcl/array.go (about) 1 package hcl 2 3 import ( 4 "github.com/lmorg/murex/lang/stdio" 5 "github.com/lmorg/murex/utils/json" 6 ) 7 8 type arrayWriter struct { 9 array []string 10 writer stdio.Io 11 } 12 13 func newArrayWriter(writer stdio.Io) (stdio.ArrayWriter, error) { 14 w := &arrayWriter{writer: writer} 15 return w, nil 16 } 17 18 func (w *arrayWriter) Write(b []byte) error { 19 w.array = append(w.array, string(b)) 20 return nil 21 } 22 23 func (w *arrayWriter) WriteString(s string) error { 24 w.array = append(w.array, s) 25 return nil 26 } 27 28 func (w *arrayWriter) Close() error { 29 b, err := json.Marshal(w.array, w.writer.IsTTY()) 30 if err != nil { 31 return err 32 } 33 34 _, err = w.writer.Write(b) 35 return err 36 }