line

package module
v0.0.0-...-fc7a351 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Dec 19, 2017 License: MIT Imports: 6 Imported by: 7

README

line  

GoDoc CircleCI Go Report Card

line is an easy to use package for stylizing terminal output. line focuses on usability via chaining and, consequently, is quite flexible. line also boasts compatibility with the popular Color package.

Install

go get github.com/dollarshaveclub/line

Usage

Simple
package main

import "github.com/dollarshaveclub/line"

func main() {
    line.Red().Print("Hello ").Green("World").Blue().Println("!!!")
}

Simple Usage

Prefix / Suffix
package main

import "github.com/dollarshaveclub/line"

func main() {
	line.Prefix("--> ").Suffix(" <---").Println("Nice to meet you!").Println("And you too!")
}

Prefix / Suffix Usage

Complex
package main

import (
	"os"

	"github.com/dollarshaveclub/line"
	"github.com/fatih/color"
)

func main() {
	output := line.New(os.Stdout, "", "", line.WhiteColor)
	output.Println("Welcome! Here is a list:")

	li := output.Prefix("--> ").Red()
	li.Println("one").Println("two").Println("sub")

	subli := li.Prefix("  --> ").Green()
	subli.Println("a").Println("b")

	output.Println()

	boldgreen := color.New(color.Bold, color.FgMagenta)
	output.Format(boldgreen).Println("Have a nice day!")
}

Complex Usage

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

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 Color

type Color struct {
	Code int
}

Color formats with a given color

func (Color) Sprint

func (c Color) Sprint(a ...interface{}) string

Sprint wraps fmt.Sprint with ANSI control codes for a color

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

func New

func New(out io.Writer, prefix string, suffix string, formatter Formatter) *Line

New creates a new instance of Line

func (*Line) Black

func (l *Line) Black(a ...interface{}) *Output

Black prints black text

func (*Line) Blue

func (l *Line) Blue(a ...interface{}) *Output

Blue prints blue text

func (*Line) Cyan

func (l *Line) Cyan(a ...interface{}) *Output

Cyan prints cyan text

func (*Line) Error

func (l *Line) Error(a ...interface{}) *Output

Error prints using formatting suitable for an error message

func (*Line) Format

func (l *Line) Format(f Formatter) *Output

Format sets the Format for the returned Output

func (*Line) Green

func (l *Line) Green(a ...interface{}) *Output

Green prints green text

func (*Line) Info

func (l *Line) Info(a ...interface{}) *Output

Info prints using formatting suitable for an info message

func (*Line) Magenta

func (l *Line) Magenta(a ...interface{}) *Output

Magenta prints magenta text

func (*Line) Prefix

func (l *Line) Prefix(prefix string) *Output

Prefix sets the prefix for the returned Output

func (*Line) Print

func (l *Line) Print(a ...interface{}) *Output

Print prints and returns an Output allowing for chaining

func (*Line) Printf

func (l *Line) Printf(format string, a ...interface{}) *Output

Printf prints and returns an Output allowing for chaining

func (*Line) Println

func (l *Line) Println(a ...interface{}) *Output

Println prints the arguments with a new line

func (*Line) Progress

func (l *Line) Progress(a ...interface{}) *Output

Progress prints with an "-->" prefix

func (*Line) Red

func (l *Line) Red(a ...interface{}) *Output

Red prints red text

func (*Line) Suffix

func (l *Line) Suffix(suffix string) *Output

Suffix sets the suffix for the returned Output

func (*Line) White

func (l *Line) White(a ...interface{}) *Output

White prints white text

func (*Line) Yellow

func (l *Line) Yellow(a ...interface{}) *Output

Yellow prints yellow text

type Output

type Output struct {
	// contains filtered or unexported fields
}

Output represents an output

func Black

func Black(a ...interface{}) *Output

Black prints black text

func Blue

func Blue(a ...interface{}) *Output

Blue prints blue text

func Cyan

func Cyan(a ...interface{}) *Output

Cyan prints cyan text

func Error

func Error(a ...interface{}) *Output

Error prints using formatting suitable for an error message

func Format

func Format(f Formatter) *Output

Format sets the Format for the returned Output

func Green

func Green(a ...interface{}) *Output

Green prints green text

func Info

func Info(a ...interface{}) *Output

Info prints using formatting suitable for an info message

func Magenta

func Magenta(a ...interface{}) *Output

Magenta prints magenta text

func NewOutput

func NewOutput(l *Line, prefix, suffix string, formatter Formatter) *Output

NewOutput creates a new output

func Prefix

func Prefix(prefix string) *Output

Prefix sets the prefix for the returned Output

func Print

func Print(a ...interface{}) *Output

Print prints and returns an Output allowing for chaining

func Printf

func Printf(format string, a ...interface{}) *Output

Printf prints and returns an Output allowing for chaining

func Println

func Println(a ...interface{}) *Output

Println prints the arguments with a new line

func Progress

func Progress(a ...interface{}) *Output

Progress prints with an "-->" prefix

func Red

func Red(a ...interface{}) *Output

Red prints red text

func Suffix

func Suffix(suffix string) *Output

Suffix sets the suffix for the returned Output

func White

func White(a ...interface{}) *Output

White prints white text

func Yellow

func Yellow(a ...interface{}) *Output

Yellow prints yellow text

func (*Output) Black

func (o *Output) Black(a ...interface{}) *Output

Black prints black text

func (*Output) Blue

func (o *Output) Blue(a ...interface{}) *Output

Blue prints blue text

func (*Output) Cyan

func (o *Output) Cyan(a ...interface{}) *Output

Cyan prints cyan text

func (*Output) Err

func (o *Output) Err() error

Err is the error that occurred in the Print call that produced this output

func (*Output) Error

func (o *Output) Error(a ...interface{}) *Output

Error prints using formatting suitable for an error message

func (*Output) Format

func (o *Output) Format(f Formatter) *Output

Format sets the Format for the returned Output

func (*Output) Green

func (o *Output) Green(a ...interface{}) *Output

Green prints green text

func (*Output) Info

func (o *Output) Info(a ...interface{}) *Output

Info prints using formatting suitable for an info message

func (*Output) Magenta

func (o *Output) Magenta(a ...interface{}) *Output

Magenta prints magenta text

func (*Output) N

func (o *Output) N() int

N number of bytes written on the Print call that produced this output

func (*Output) Prefix

func (o *Output) Prefix(prefix string) *Output

Prefix sets the prefix for the returned Output

func (*Output) Print

func (o *Output) Print(a ...interface{}) *Output

Print prints and returns an Output allowing for chaining

func (*Output) Printf

func (o *Output) Printf(format string, a ...interface{}) *Output

Printf prints and returns an Output allowing for chaining

func (*Output) Println

func (o *Output) Println(a ...interface{}) *Output

Println prints the arguments with a new line

func (*Output) Progress

func (o *Output) Progress(a ...interface{}) *Output

Progress prints with an "-->" prefix

func (*Output) Red

func (o *Output) Red(a ...interface{}) *Output

Red prints red text

func (*Output) Suffix

func (o *Output) Suffix(suffix string) *Output

Suffix sets the suffix for the returned Output

func (*Output) White

func (o *Output) White(a ...interface{}) *Output

White prints white text

func (*Output) Yellow

func (o *Output) Yellow(a ...interface{}) *Output

Yellow prints yellow text

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL