brush

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

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

Go to latest
Published: Apr 21, 2017 License: MIT Imports: 4 Imported by: 0

README

Brush, Colorful Writer Interface Wrapper

Package brush wraps io.Writer interface and supercharge them with high-level color and formatting API on supported terminal.

This package is similar to Bash's tput command, but also works in Windows system. It will look good on supported terminal but does not do anything on anything else.

Usage

Get the package from your favorite terminal by running

go get -u github.com/Mandala/brush

Then, include it in your package and wrap your writer with brush.Wrap().

import (
    "fmt"
    "os"

    "github.com/Mandala/brush"
)

func main() {
    // Wrap stdout with brush wrapper
    color := brush.Wrap(os.Stdout)
    // Switch to red color on supported terminal
    color.Red()
    // Print actual message to user
    fmt.Fprintf(color, "Works with standard fmt.Fprintf function")
    // Don't forget to turn off formatting after writes
    color.Off()
}

API Documentation

Brush API documentation is available on Godoc.org at https://godoc.org/github.com/Mandala/brush.

Bugs and Feature Requests

Please report bugs and feature requests on https://github.com/Mandala/brush/issues.

License

Copyright (c) 2017 Fadhli Dzil Ikram. All rights reserved.

Source code is governed under MIT license, see LICENSE for more information.

Documentation

Overview

Package brush wraps io.Writer interface and supercharge them with high-level color and formatting API on supported terminal.

This package is similar to Bash's tput command, but also works in Windows system. It will look good on supported terminal but does not do anything on anything else.

Usage

Get the package from your favorite terminal by running

go get -u github.com/Mandala/brush

Then, include it in your package and wrap your writer with brush.Wrap(). See example section on how to use the brush wrapper with os.Stdout writer.

Bugs and Feature Requests

Please report them on https://github.com/Mandala/brush/issues.

License

Copyright (c) 2017 Fadhli Dzil Ikram. All rights reserved.

Source code is governed under MIT license, see LICENSE for more information.

Example

Wrap os.Stdout writer and print a message with red color.

package main

import (
	"fmt"
	"os"

	"github.com/mandala/brush"
)

func main() {
	// Wrap stdout with brush wrapper
	color := brush.Wrap(os.Stdout)
	// Switch to red color on supported terminal
	color.Red()
	// Print actual message to user
	fmt.Fprintf(color, "Works with standard fmt.Fprintf function")
	// Don't forget to turn off formatting after writes
	color.Off()
}
Output:

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Writer

type Writer struct {
	io.Writer
	// contains filtered or unexported fields
}

Writer function wraps io.Writer and store related formatting state. User should use Wrap function to create new Writer struct instead of manual instantiation.

func Wrap

func Wrap(w io.Writer) *Writer

Wrap function create new Writer object by wrapping existing io.Writer interface and detect its ability to display color.

func (*Writer) Blue

func (w *Writer) Blue()

Blue method set to blue color.

func (*Writer) Bold

func (w *Writer) Bold() *Writer

Bold method set bold formatting (should be followed by a color command).

func (Writer) Color

func (w Writer) Color() bool

Color function get underlying writer color support status.

func (*Writer) Cyan

func (w *Writer) Cyan()

Cyan method set to cyan color.

func (*Writer) Gray

func (w *Writer) Gray()

Gray method set to gray color.

func (*Writer) Green

func (w *Writer) Green()

Green method set to green color.

func (*Writer) NoBold

func (w *Writer) NoBold() *Writer

NoBold method unset bold formatting (should be followed by a color command).

func (*Writer) NoColor

func (w *Writer) NoColor()

NoColor method unset all color.

func (*Writer) Off

func (w *Writer) Off()

Off method unset all formatting.

func (*Writer) Orange

func (w *Writer) Orange()

Orange method set to orange color.

func (*Writer) Purple

func (w *Writer) Purple()

Purple method set to purple color.

func (*Writer) Red

func (w *Writer) Red()

Red method set to red color.

Jump to

Keyboard shortcuts

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