github.com/lmorg/murex@v0.0.0-20240217211045-e081c89cd4ef/builtins/pipes/term/err.go (about) 1 //go:build !js 2 // +build !js 3 4 package term 5 6 import ( 7 "os" 8 9 "github.com/lmorg/murex/lang/stdio" 10 "github.com/lmorg/murex/utils" 11 ) 12 13 // Terminal: Standard Error 14 15 // Err is the Stderr interface for term 16 type Err struct { 17 term 18 } 19 20 func (t *Err) File() *os.File { 21 return os.Stderr 22 } 23 24 // SetDataType is a null method because the term interface is write-only 25 func (t *Err) SetDataType(string) {} 26 27 // Write is the io.Writer() interface for term 28 func (t *Err) Write(b []byte) (i int, err error) { 29 t.mutex.Lock() 30 t.bWritten += uint64(len(b)) 31 t.mutex.Unlock() 32 33 i, err = os.Stderr.Write(b) 34 if err != nil { 35 os.Stdout.WriteString(err.Error()) 36 } 37 38 return 39 } 40 41 // Writeln writes an OS-specific terminated line to the stderr 42 func (t *Err) Writeln(b []byte) (int, error) { 43 return t.Write(appendBytes(b, utils.NewLineByte...)) 44 } 45 46 // WriteArray performs data type specific buffered writes to an stdio.Io interface 47 func (t *Err) WriteArray(dataType string) (stdio.ArrayWriter, error) { 48 return stdio.WriteArray(t, dataType) 49 }