Documentation
¶
Overview ¶
Package line is an easy to use package for stylizing terminal output. The API focuses on usability via chaining and, consequently, is quite flexible.
Use the color methods to print in a wide selection of colors:
line.Red().Print("Hello").Green("World").Blue().Println("!!!")
Output with a prefix and a suffix:
line.Prefix("--> ").Suffix(" <---").Println("Nice to meet you!")
Prefix all output:
out := line.Prefix("--> ")
out.Println("One").Println("Two").Println("Three")
Example ¶
package main
import (
"github.com/dollarshaveclub/line"
)
func main() {
line.Red().Print("Hello").Green("World").Blue().Println("!!!")
line.Prefix("--> ").Suffix(" <---").Println("Nice to meet you!")
out := line.Prefix("--> ")
out.Println("One").Prefix(" --> ").Print("A\nB\nC")
out.Println("Two").Prefix(" --> ").Green().Println("D")
line.Info("An info statement")
line.Error("An error statement")
}
Output:
Index ¶
- Variables
- type Color
- type Formatter
- type Interface
- type Line
- func (l *Line) Black(a ...interface{}) *Output
- func (l *Line) Blue(a ...interface{}) *Output
- func (l *Line) Cyan(a ...interface{}) *Output
- func (l *Line) Error(a ...interface{}) *Output
- func (l *Line) Format(f Formatter) *Output
- func (l *Line) Green(a ...interface{}) *Output
- func (l *Line) Info(a ...interface{}) *Output
- func (l *Line) Magenta(a ...interface{}) *Output
- func (l *Line) Prefix(prefix string) *Output
- func (l *Line) Print(a ...interface{}) *Output
- func (l *Line) Printf(format string, a ...interface{}) *Output
- func (l *Line) Println(a ...interface{}) *Output
- func (l *Line) Progress(a ...interface{}) *Output
- func (l *Line) Red(a ...interface{}) *Output
- func (l *Line) Suffix(suffix string) *Output
- func (l *Line) White(a ...interface{}) *Output
- func (l *Line) Yellow(a ...interface{}) *Output
- type Output
- func Black(a ...interface{}) *Output
- func Blue(a ...interface{}) *Output
- func Cyan(a ...interface{}) *Output
- func Error(a ...interface{}) *Output
- func Format(f Formatter) *Output
- func Green(a ...interface{}) *Output
- func Info(a ...interface{}) *Output
- func Magenta(a ...interface{}) *Output
- func NewOutput(l *Line, prefix, suffix string, formatter Formatter) *Output
- func Prefix(prefix string) *Output
- func Print(a ...interface{}) *Output
- func Printf(format string, a ...interface{}) *Output
- func Println(a ...interface{}) *Output
- func Progress(a ...interface{}) *Output
- func Red(a ...interface{}) *Output
- func Suffix(suffix string) *Output
- func White(a ...interface{}) *Output
- func Yellow(a ...interface{}) *Output
- func (o *Output) Black(a ...interface{}) *Output
- func (o *Output) Blue(a ...interface{}) *Output
- func (o *Output) Cyan(a ...interface{}) *Output
- func (o *Output) Err() error
- func (o *Output) Error(a ...interface{}) *Output
- func (o *Output) Format(f Formatter) *Output
- func (o *Output) Green(a ...interface{}) *Output
- func (o *Output) Info(a ...interface{}) *Output
- func (o *Output) Magenta(a ...interface{}) *Output
- func (o *Output) N() int
- func (o *Output) Prefix(prefix string) *Output
- func (o *Output) Print(a ...interface{}) *Output
- func (o *Output) Printf(format string, a ...interface{}) *Output
- func (o *Output) Println(a ...interface{}) *Output
- func (o *Output) Progress(a ...interface{}) *Output
- func (o *Output) Red(a ...interface{}) *Output
- func (o *Output) Suffix(suffix string) *Output
- func (o *Output) White(a ...interface{}) *Output
- func (o *Output) Yellow(a ...interface{}) *Output
Examples ¶
Constants ¶
This section is empty.
Variables ¶
View Source
var ( // BlackColor is a Formatter for black BlackColor = Color{Code: black} // RedColor is a Formatter for red RedColor = Color{Code: red} // GreenColor is a Formatter for green GreenColor = Color{Code: green} // YellowColor is a Formatter for yellow YellowColor = Color{Code: yellow} // BlueColor is a Formatter for blue BlueColor = Color{Code: blue} // MagentaColor is a Formatter for magenta MagentaColor = Color{Code: magenta} // CyanColor is a Formatter for cyan CyanColor = Color{Code: cyan} // WhiteColor is a Formatter for white WhiteColor = Color{Code: white} )
View Source
var ( // Std is a os.Stdout backed Line Std = New(os.Stdout, "", "", nil) )
Functions ¶
This section is empty.
Types ¶
type Formatter ¶
type Formatter interface {
Sprint(a ...interface{}) string
}
Formatter formats arguments to be suitable for printing
type Interface ¶
type Interface interface {
// Prefix sets the prefix for the returned Output
Prefix(prefix string) *Output
// Suffix sets the suffix for the returned Output
Suffix(suffix string) *Output
// Format sets the Format for the returned Output
Format(f Formatter) *Output
// Print prints and returns an Output allowing for chaining
Print(a ...interface{}) *Output
// Println prints the arguments with a new line
Println(a ...interface{}) *Output
// Printf prints and returns an Output allowing for chaining
Printf(format string, a ...interface{}) *Output
// Info prints using formatting suitable for an info message
Info(a ...interface{}) *Output
// Progress prints with an "-->" prefix
Progress(a ...interface{}) *Output
// Error prints using formatting suitable for an error message
Error(a ...interface{}) *Output
// Black prints black text
Black(a ...interface{}) *Output
// Red prints red text
Red(a ...interface{}) *Output
// Green prints green text
Green(a ...interface{}) *Output
// Yellow prints yellow text
Yellow(a ...interface{}) *Output
// Blue prints blue text
Blue(a ...interface{}) *Output
// Magenta prints magenta text
Magenta(a ...interface{}) *Output
// Cyan prints cyan text
Cyan(a ...interface{}) *Output
// White prints white text
White(a ...interface{}) *Output
}
Interface is Line's interface
type Line ¶
type Line struct {
// contains filtered or unexported fields
}
Line is an easy way to stylize terminal output
type Output ¶
type Output struct {
// contains filtered or unexported fields
}
Output represents an output
func Error ¶
func Error(a ...interface{}) *Output
Error prints using formatting suitable for an error message
func Info ¶
func Info(a ...interface{}) *Output
Info prints using formatting suitable for an info message
func Print ¶
func Print(a ...interface{}) *Output
Print prints and returns an Output allowing for chaining
Click to show internal directories.
Click to hide internal directories.


