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 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
|
package cmd
import (
"fmt"
"io"
"github.com/muesli/termenv"
)
type Printer interface {
Print(w io.Writer)
}
// - - - - - - - //
type coloredBox struct {
prefix string
text string
}
func ColoredBox(prefix string, text string) Printer {
return &coloredBox{prefix, text}
}
func (p coloredBox) Print(w io.Writer) {
output := termenv.NewOutput(w)
prefix := output.String(p.prefix + ":").Background(termenv.ANSIRed).Foreground(termenv.ANSIBrightWhite).String()
message := output.String(p.text).Foreground(termenv.ANSIRed).String()
fmt.Fprintf(w, "%s %s\n", prefix, message)
}
// - - - - - - - //
type paragraph struct {
text string
}
func Paragraph(text string) Printer {
return ¶graph{text}
}
func (p paragraph) Print(w io.Writer) {
fmt.Fprintln(w, p.text)
}
// - - - - - - - //
type codeBlock struct {
code string
}
func CodeBlock(code string) Printer {
return &codeBlock{code}
}
func (cb codeBlock) Print(w io.Writer) {
// TODO: what about indenting multiline?
fmt.Fprintf(w, " %s\n", cb.code)
}
|