Documentation
¶
Index ¶
- func Base(w io.Writer) io.Writer
- func Parent(w io.Writer) io.Writer
- func Root(w io.Writer) io.Writer
- type PrefixWriter
- func (w *PrefixWriter) Base() io.Writer
- func (w *PrefixWriter) Buffered() []byte
- func (w *PrefixWriter) Flag(c int) bool
- func (w *PrefixWriter) Flush() error
- func (w *PrefixWriter) Precision() (int, bool)
- func (w *PrefixWriter) Width() (int, bool)
- func (w *PrefixWriter) Write(b []byte) (int, error)
- func (w *PrefixWriter) WriteString(s string) (int, error)
- type TreeWriter
- func (w *TreeWriter) Base() io.Writer
- func (w *TreeWriter) Close() (err error)
- func (w *TreeWriter) Flag(c int) bool
- func (w *TreeWriter) Parent() io.Writer
- func (w *TreeWriter) Precision() (int, bool)
- func (w *TreeWriter) Root() io.Writer
- func (w *TreeWriter) Width() (int, bool)
- func (w *TreeWriter) Write(b []byte) (int, error)
- func (w *TreeWriter) WriteByte(b byte) error
- func (w *TreeWriter) WriteRune(r rune) (int, error)
- func (w *TreeWriter) WriteString(s string) (int, error)
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
Types ¶
type PrefixWriter ¶
type PrefixWriter struct {
// contains filtered or unexported fields
}
PrefixWriter is an implementation of io.Writer which places a prefix before every line.
Instances of PrefixWriter are not safe to use concurrently from multiple goroutines.
func NewPrefixWriter ¶
func NewPrefixWriter(w io.Writer, s string) *PrefixWriter
NewPrefixWriter constructs a PrefixWriter which outputs to w and prefixes every line with s.
func (*PrefixWriter) Base ¶
func (w *PrefixWriter) Base() io.Writer
Base returns the underlying writer that w outputs to.
func (*PrefixWriter) Buffered ¶
func (w *PrefixWriter) Buffered() []byte
Buffered returns a byte slice of the data currently buffered in the writer.
func (*PrefixWriter) Flag ¶ added in v1.2.0
func (w *PrefixWriter) Flag(c int) bool
Flag satisfies the fmt.State interface.
func (*PrefixWriter) Flush ¶
func (w *PrefixWriter) Flush() error
Flush forces all buffered data to be flushed to the underlying writer.
func (*PrefixWriter) Precision ¶ added in v1.2.0
func (w *PrefixWriter) Precision() (int, bool)
Precision satisfies the fmt.State interface.
func (*PrefixWriter) Width ¶ added in v1.2.0
func (w *PrefixWriter) Width() (int, bool)
Width satisfies the fmt.State interface.
func (*PrefixWriter) Write ¶
func (w *PrefixWriter) Write(b []byte) (int, error)
Write writes b to w, satisfies the io.Writer interface.
func (*PrefixWriter) WriteString ¶
func (w *PrefixWriter) WriteString(s string) (int, error)
WriteString writes s to w.
type TreeWriter ¶
type TreeWriter struct {
// contains filtered or unexported fields
}
TreeWriter is an implementation of an io.Writer which prints a tree-like representation of the content.
Instances of TreeWriter are not safe to use concurrently from multiple goroutines.
func NewTreeWriter ¶
func NewTreeWriter(w io.Writer) *TreeWriter
NewTreeWriter constructs a new TreeWriter which outputs to w. If w is an instance of TreeWriter itself the new writer is added to the list of child nodes that will be renderend.
Example ¶
var ls func(io.Writer, string) ls = func(w io.Writer, path string) { tree := NewTreeWriter(w) tree.WriteString(filepath.Base(path)) defer tree.Close() files, _ := ioutil.ReadDir(path) for _, f := range files { if f.Mode().IsDir() { ls(tree, filepath.Join(path, f.Name())) } } for _, f := range files { if !f.Mode().IsDir() { io.WriteString(NewTreeWriter(tree), f.Name()) } } } ls(os.Stdout, "examples")
Output: examples ├── A │ ├── 1 │ └── 2 └── message
func (*TreeWriter) Close ¶
func (w *TreeWriter) Close() (err error)
Close closes w, causing all buffered content to be flushed to its underlying writer, and future write operations to error with io.ErrClosedPipe.
func (*TreeWriter) Flag ¶ added in v1.1.0
func (w *TreeWriter) Flag(c int) bool
Flag satisfies the fmt.State interface.
func (*TreeWriter) Parent ¶
func (w *TreeWriter) Parent() io.Writer
Parent returns the parent node of w, which its most direct base of type *TreeWriter.
func (*TreeWriter) Precision ¶ added in v1.1.0
func (w *TreeWriter) Precision() (int, bool)
Precision satisfies the fmt.State interface.
func (*TreeWriter) Root ¶
func (w *TreeWriter) Root() io.Writer
Root returns the root of w, which is the node on which calling Close will cause the tree to be rendered to the underlying writer.
func (*TreeWriter) Width ¶ added in v1.1.0
func (w *TreeWriter) Width() (int, bool)
Width satisfies the fmt.State interface.
func (*TreeWriter) Write ¶
func (w *TreeWriter) Write(b []byte) (int, error)
Write writes b to w, satisfies the io.Writer interface.
func (*TreeWriter) WriteByte ¶ added in v1.1.0
func (w *TreeWriter) WriteByte(b byte) error
WriteByte writes b to w.
func (*TreeWriter) WriteRune ¶ added in v1.1.0
func (w *TreeWriter) WriteRune(r rune) (int, error)
WriteRune writes r to w.
func (*TreeWriter) WriteString ¶
func (w *TreeWriter) WriteString(s string) (int, error)
WriteString writes s to w.