package lineprefix
import "github.com/abiosoft/lineprefix"
Package lineprefix provides a `io.Writer` wrapper with line prefix and color customizations.
Static Prefix
prefix := lineprefix.Prefix("app |") writer := lineprefix.New(prefix) fmt.Fprintln(writer, "hello world")
Dynamic Prefix
now := func() string { return time.Now().UTC().Format("2006-01-02 15:04:05") } prefix := lineprefix.PrefixFunc(now) writer := lineprefix.New(prefix) for i := 0; i<3; i++ { fmt.Fprintln(writer, "hello world") time.Sleep(time.Second) }
Colors can be added with github.com/faith/color
A prefix with blue text on white background
blue := color.New(color.FgBlue, color.BgWhite).SprintFunc() prefix := lineprefix.Prefix(blue("app")) writer := lineprefix.New(prefix) fmt.Fprintln(writer, "this outputs blue on white prefix text")
A blue colored output
blue := color.New(color.FgBlue) option := lineprefix.Color(blue) writer := lineprefix.New(option) fmt.Fprintln(writer, "this outputs blue color text")
Index ¶
Functions ¶
func New ¶
func New(options ...Option) io.WriteCloser
New creates a new lineprefix writer with options.
Types ¶
type Option ¶
type Option interface {
// contains filtered or unexported methods
}
Option is the configuration option for a new instance of lineprefix writer.
func Color ¶
Color sets the colour for the line outputs, excluding the prefix.
func Prefix ¶
Prefix sets the prefix to use. Can be called multiple times to set multiple prefixes.
func PrefixFunc ¶
PrefixFunc is like prefix but with the ability to make it dynamic. Can be called multiple times to set multiple prefixes.
func RenderEscaped ¶
RenderEscaped (if true) enables the rendering of escaped whitespace characters. e.g. `\\t` appears as tab instead of `\t`, `\\n` appears as newline instead of `\n` e.t.c.
func Writer ¶
Writer sets the writer to use. The default writer is os.Stdout.
Source Files ¶
Directories ¶
Path | Synopsis |
---|---|
example |
- Version
- v0.1.4 (latest)
- Published
- Jun 3, 2021
- Platform
- linux/amd64
- Imports
- 6 packages
- Last checked
- 19 hours ago –
Tools for package owners.