Documentation ¶
Overview ¶
Package stream provides NullStream
Packate stream defines input and output streams.
Index ¶
- Variables
- func IsNullWriter(writer io.Writer) bool
- type IOStream
- func (str IOStream) Die(err error) error
- func (str IOStream) EPrint(args ...interface{}) (n int, err error)
- func (str IOStream) EPrintf(format string, args ...interface{}) (n int, err error)
- func (str IOStream) EPrintln(args ...interface{}) (n int, err error)
- func (str IOStream) NonInteractive() IOStream
- func (str IOStream) Print(args ...interface{}) (n int, err error)
- func (str IOStream) Printf(format string, args ...interface{}) (n int, err error)
- func (str IOStream) Println(args ...interface{}) (n int, err error)
- func (str IOStream) ReadLine() (string, error)
- func (str IOStream) ReadPassword() (string, error)
- func (str IOStream) ReadPasswordStrict() (string, error)
- func (str IOStream) StderrIsATerminal() bool
- func (str IOStream) StderrWriteWrap(s string) (int, error)
- func (str IOStream) StdinIsATerminal() bool
- func (str IOStream) StdoutIsATerminal() bool
- func (str IOStream) StdoutWriteWrap(s string) (int, error)
- func (str IOStream) Streams(Stdout, Stderr io.Writer, Stdin io.Reader, wrap int) IOStream
Constants ¶
This section is empty.
Variables ¶
var Null io.ReadWriteCloser = nullStream{}
Null is an io.ReadWriteCloser.
Reads from it return 0 bytes and io.EOF. Writes and Closes succeed without doing anything.
See also io.Discard.
Functions ¶
func IsNullWriter ¶ added in v0.2.3
IsNullWriter checks if a writer is known to be a writer that discards any input
Types ¶
type IOStream ¶
type IOStream struct { Stdin io.Reader Stdout, Stderr io.Writer // contains filtered or unexported fields }
IOStream represents a set of input and output streams commonly associated to a process.
func FromEnv ¶
func FromEnv() IOStream
FromEnv creates a new IOStream using the environment.
The Stdin, Stdout and Stderr streams are used from the os package.
func FromNil ¶
func FromNil() IOStream
FromNil creates a new IOStream that silences all output and provides no input.
func NewIOStream ¶
NewIOStream creates a new IOStream with the provided readers and writers. If any of them are set to nil, they are set to Null. When wrap is set to 0, it is set to a reasonable default.
It furthermore wraps output as set by wrap.
func NonInteractive ¶ added in v0.2.1
NonInteractive creates a new non-interactive writer from a single output stream.
It is roughly equivalent to NewIOStream(Writer, Writer, nil, 0)
func (IOStream) Die ¶
Die prints a non-nil err to io.Stderr and returns an error of type Error or nil.
When error is non-nil, this function first turns err into type Error. Then if err.Message is not the empty string, it prints it to io.Stderr with wrapping.
If err is nil, it does nothing and returns nil.
func (IOStream) EPrintf ¶
EPrintf is like fmt.Printf but prints to io.Stderr.
func (IOStream) EPrintln ¶
EPrintln is like fmt.Println but prints to io.Stderr.
func (IOStream) NonInteractive ¶ added in v0.0.12
NonInteractive creates a new IOStream with Null as standard input.
func (IOStream) Printf ¶
Printf is like fmt.Printf but prints to str.Stdout.
func (IOStream) Println ¶
Println is like fmt.Println but prints to str.Stdout.
func (IOStream) ReadLine ¶ added in v0.0.8
ReadLine is like nobufio.ReadLine on the standard input
func (IOStream) ReadPassword ¶ added in v0.0.8
ReadPassword is like nobufio.ReadPassword on the standard input
func (IOStream) ReadPasswordStrict ¶ added in v0.0.8
ReadPasswordStrict is like nobufio.ReadPasswordStrict on the standard input
func (IOStream) StderrIsATerminal ¶ added in v0.0.16
StderrIsATerminal checks if standard error is a terminal
func (IOStream) StderrWriteWrap ¶
StderrWriteWrap is like
io.Stdout.Write([]byte(s + "\n"))
but wrapped at length Wrap.
func (IOStream) StdinIsATerminal ¶ added in v0.0.9
StdinIsATerminal checks if standard input is a terminal
func (IOStream) StdoutIsATerminal ¶ added in v0.0.16
StdoutIsATerminal checks if standard output is a terminal
func (IOStream) StdoutWriteWrap ¶
StdoutWriteWrap is like
io.Stdout.Write([]byte(s + "\n"))
but wrapped at a reasonable length