github.com/echohead/hub@v2.2.1+incompatible/ui/ui.go (about)

     1  package ui
     2  
     3  import (
     4  	"fmt"
     5  	"io"
     6  	"os"
     7  )
     8  
     9  type UI interface {
    10  	Printf(format string, a ...interface{}) (n int, err error)
    11  	Println(a ...interface{}) (n int, err error)
    12  	Errorf(format string, a ...interface{}) (n int, err error)
    13  	Errorln(a ...interface{}) (n int, err error)
    14  }
    15  
    16  var Default UI = Console{Stdout: os.Stdout, Stderr: os.Stderr}
    17  
    18  func Printf(format string, a ...interface{}) (n int, err error) {
    19  	return Default.Printf(format, a...)
    20  }
    21  
    22  func Println(a ...interface{}) (n int, err error) {
    23  	return Default.Println(a...)
    24  }
    25  
    26  func Errorf(format string, a ...interface{}) (n int, err error) {
    27  	return Default.Errorf(format, a...)
    28  }
    29  
    30  func Errorln(a ...interface{}) (n int, err error) {
    31  	return Default.Errorln(a...)
    32  }
    33  
    34  type Console struct {
    35  	Stdout io.Writer
    36  	Stderr io.Writer
    37  }
    38  
    39  func (c Console) Printf(format string, a ...interface{}) (n int, err error) {
    40  	return fmt.Fprintf(c.Stdout, format, a...)
    41  }
    42  
    43  func (c Console) Println(a ...interface{}) (n int, err error) {
    44  	return fmt.Fprintln(c.Stdout, a...)
    45  }
    46  
    47  func (c Console) Errorf(format string, a ...interface{}) (n int, err error) {
    48  	return fmt.Fprintf(c.Stderr, format, a...)
    49  }
    50  
    51  func (c Console) Errorln(a ...interface{}) (n int, err error) {
    52  	return fmt.Fprintln(c.Stderr, a...)
    53  }