Documentation
¶
Index ¶
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) Flush ¶
func (w *PrefixWriter) Flush() error
Flush forces all buffered data to be flushed to the underlying writer.
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) Parent ¶
func (w *TreeWriter) Parent() io.Writer
Parent returns the parent node of w, which its most direct base of type *TreeWriter.
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) Write ¶
func (w *TreeWriter) Write(b []byte) (int, error)
Write writes b to w, satisfies the io.Writer interface.
func (*TreeWriter) WriteString ¶
func (w *TreeWriter) WriteString(s string) (int, error)
WriteString writes s to w.