34 lines
777 B
Go
34 lines
777 B
Go
package pretty
|
|
|
|
import "strings"
|
|
|
|
type PrettyBuilder struct {
|
|
lines []string
|
|
padding int
|
|
border bool
|
|
}
|
|
|
|
// NewBuilder creates and returns a new empty builder
|
|
func NewBuilder() *PrettyBuilder {
|
|
return &PrettyBuilder{
|
|
lines: []string{""},
|
|
}
|
|
}
|
|
|
|
// NewBuilderFromString creates and returns a new builder based on the string
|
|
func NewBuilderFromString(s string) *PrettyBuilder {
|
|
lines := strings.Split(strings.Trim(s, "\n"), "\n")
|
|
return &PrettyBuilder{
|
|
lines: lines,
|
|
}
|
|
}
|
|
|
|
// AppendString adds a string to the builder line buffer
|
|
func (pb *PrettyBuilder) AppendString(s string) *PrettyBuilder {
|
|
if strings.HasSuffix(s, "\n") {
|
|
pb.lines = append(pb.lines, strings.Trim(s, "\n"))
|
|
return pb
|
|
}
|
|
pb.lines[len(pb.lines)-1] = pb.lines[len(pb.lines)-1] + s
|
|
return pb
|
|
}
|