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 ¶
- type Writer
- func (w *Writer) Blue()
- func (w *Writer) Bold() *Writer
- func (w Writer) Color() bool
- func (w *Writer) Cyan()
- func (w *Writer) Gray()
- func (w *Writer) Green()
- func (w *Writer) NoBold() *Writer
- func (w *Writer) NoColor()
- func (w *Writer) Off()
- func (w *Writer) Orange()
- func (w *Writer) Purple()
- func (w *Writer) Red()
Examples ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
This section is empty.
Types ¶
type Writer ¶
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 ¶
Wrap function create new Writer object by wrapping existing io.Writer interface and detect its ability to display color.