Exemplo n.º 1
0
func main() {
	output := doscolor.NewWrapper(os.Stdout)
	if err := output.Save(); err != nil {
		fmt.Println(err)
		return
	}
	fmt.Fprintln(output, "Here's some ordinary text.")
	if err := output.SetMask(doscolor.Red|doscolor.Bright, doscolor.Foreground); err != nil {
		fmt.Println(err)
		return
	}
	fmt.Fprintln(output, "Here's some (revolutionary) red text.")
	if err := output.Set(doscolor.White | doscolor.Bright | doscolor.BG(doscolor.Green)); err != nil {
		fmt.Println(err)
		return
	}
	fmt.Fprintln(output, "Esperanto colors.")
	if err := output.Restore(); err != nil {
		fmt.Println(err)
		return
	}
	fmt.Fprintln(output, "Now it should be back to normal.")
}
Exemplo n.º 2
0
// Return an error if the text wasn't printed;
// otherwise return nil
func text(f *os.File, s string, c []doscolor.Color) error {
	output := doscolor.NewWrapper(f)
	if err := output.Save(); err != nil {
		return err
	}
	if len(c) < 1 {
		fmt.Fprintln(output, s)
	}

	var cbits doscolor.Color = 0
	for _, color := range c {
		cbits |= color
	}

	if err := output.Set(cbits); err != nil {
		return err
	}
	fmt.Fprint(output, s)

	// Don't check for an error here,
	// because text has been printed
	output.Restore()
	return nil
}
Exemplo n.º 3
0
import (
	"github.com/anschelsc/doscolor"
	"log"
	"os"
	"strings"
	"sync"
)

type clogger struct {
	idx  int
	proc string
}

var mutex = new(sync.Mutex)
var cerr = doscolor.NewWrapper(os.Stderr)
var elog *log.Logger
var colors = []doscolor.Color{
	doscolor.Green | doscolor.Bright,
	doscolor.Cyan | doscolor.Bright,
	doscolor.Magenta | doscolor.Bright,
	doscolor.Yellow | doscolor.Bright,
	doscolor.Blue | doscolor.Bright,
	doscolor.Red | doscolor.Bright,
}
var ci int

// write handler of logger.
func (l *clogger) Write(p []byte) (n int, err error) {
	mutex.Lock()
	defer mutex.Unlock()