~emersion/drmdb

ref: a85c27af65ce9e831bcaf14da813dc24b495d376 drmdb/treefmt/text.go -rw-r--r-- 502 bytes
a85c27afSimon Ser Filter capabilities by driver name 4 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
package treefmt

import (
	"fmt"
	"io"
	"strings"
)

type textFormatter struct {
	w      io.Writer
	indent int
}

// NewTextFormatter pretty-prints a tree in a text format to w.
func NewTextFormatter(w io.Writer) Formatter {
	return &textFormatter{w: w}
}

func (tp *textFormatter) NewChild() Formatter {
	return &textFormatter{w: tp.w, indent: tp.indent + 1}
}

func (tp *textFormatter) Printf(format string, v ...interface{}) {
	fmt.Fprintf(tp.w, strings.Repeat("  ", tp.indent)+format+"\n", v...)
}