github.com/lmorg/murex@v0.0.0-20240217211045-e081c89cd4ef/builtins/pipes/term/red_js.go (about)

     1  //go:build js
     2  // +build js
     3  
     4  package term
     5  
     6  import (
     7  	"github.com/lmorg/murex/lang/stdio"
     8  	"github.com/lmorg/murex/utils"
     9  	"github.com/lmorg/murex/utils/ansi/codes"
    10  )
    11  
    12  // Terminal: Standard Error - Coloured Red
    13  
    14  // ErrRed is the Stderr interface for term - with output coloured red
    15  type ErrRed struct {
    16  	term
    17  }
    18  
    19  // SetDataType is a null method because the term interface is write-only
    20  func (t *ErrRed) SetDataType(string) {}
    21  
    22  // Write is the io.Writer() interface for term
    23  func (t *ErrRed) Write(b []byte) (int, error) {
    24  	t.mutex.Lock()
    25  	t.bWritten += uint64(len(b))
    26  	t.mutex.Unlock()
    27  
    28  	new := codes.FgRed + string(b) + codes.Reset
    29  
    30  	vtermWrite([]rune(new))
    31  
    32  	return len(b), nil
    33  }
    34  
    35  // Writeln writes an OS-specific terminated line to the stderr
    36  func (t *ErrRed) Writeln(b []byte) (int, error) {
    37  	return t.Write(appendBytes(b, utils.NewLineByte...))
    38  }
    39  
    40  // WriteArray performs data type specific buffered writes to an stdio.Io interface
    41  func (t *ErrRed) WriteArray(dataType string) (stdio.ArrayWriter, error) {
    42  	return stdio.WriteArray(t, dataType)
    43  }