ansicolor

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Jun 8, 2015 License: MIT, BSD-3-Clause Imports: 1 Imported by: 0

README

ansicolor

Ansicolor library provides color console in Windows as ANSICON for Golang.

Features

Escape sequence Text attributes
\x1b[0m All attributes off(color at startup)
\x1b[1m Bold on(enable foreground intensity)
\x1b[4m Underline on
\x1b[5m Blink on(enable background intensity)
\x1b[21m Bold off(disable foreground intensity)
\x1b[24m Underline off
\x1b[25m Blink off(disable background intensity)
Escape sequence Foreground colors
\x1b[30m Black
\x1b[31m Red
\x1b[32m Green
\x1b[33m Yellow
\x1b[34m Blue
\x1b[35m Magenta
\x1b[36m Cyan
\x1b[37m White
\x1b[39m Default(foreground color at startup)
Escape sequence Background colors
\x1b[40m Black
\x1b[41m Red
\x1b[42m Green
\x1b[43m Yellow
\x1b[44m Blue
\x1b[45m Magenta
\x1b[46m Cyan
\x1b[47m White
\x1b[49m Default(background color at startup)

Example

package main

import (
	"fmt"
	"os"

	"github.com/shiena/ansicolor"
)

func main() {
	w := ansicolor.NewAnsiColorWriter(os.Stdout)
	text := "%sforeground %sbold%s %sbackground%s\n"
	fmt.Fprintf(w, text, "\x1b[31m", "\x1b[1m", "\x1b[21m", "\x1b[41;32m", "\x1b[0m")
	fmt.Fprintf(w, text, "\x1b[32m", "\x1b[1m", "\x1b[21m", "\x1b[42;31m", "\x1b[0m")
	fmt.Fprintf(w, text, "\x1b[33m", "\x1b[1m", "\x1b[21m", "\x1b[43;34m", "\x1b[0m")
	fmt.Fprintf(w, text, "\x1b[34m", "\x1b[1m", "\x1b[21m", "\x1b[44;33m", "\x1b[0m")
	fmt.Fprintf(w, text, "\x1b[35m", "\x1b[1m", "\x1b[21m", "\x1b[45;36m", "\x1b[0m")
	fmt.Fprintf(w, text, "\x1b[36m", "\x1b[1m", "\x1b[21m", "\x1b[46;35m", "\x1b[0m")
	fmt.Fprintf(w, text, "\x1b[37m", "\x1b[1m", "\x1b[21m", "\x1b[47;30m", "\x1b[0m")
}

screenshot

See also:

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

Documentation

Overview

Package ansicolor provides color console in Windows as ANSICON.

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

func NewAnsiColorWriter

func NewAnsiColorWriter(w io.Writer) io.Writer

NewAnsiColorWriter creates and initializes a new ansiColorWriter using io.Writer w as its initial contents. In the console of Windows, which change the foreground and background colors of the text by the escape sequence. In the console of other systems, which writes to w all text.

Example
package main

import (
	"fmt"
	"os"

	"github.com/shiena/ansicolor"
)

func main() {
	w := ansicolor.NewAnsiColorWriter(os.Stdout)
	text := "%sforeground %sbold%s %sbackground%s\n"
	fmt.Fprintf(w, text, "\x1b[31m", "\x1b[1m", "\x1b[21m", "\x1b[41;32m", "\x1b[0m")
	fmt.Fprintf(w, text, "\x1b[32m", "\x1b[1m", "\x1b[21m", "\x1b[42;31m", "\x1b[0m")
	fmt.Fprintf(w, text, "\x1b[33m", "\x1b[1m", "\x1b[21m", "\x1b[43;34m", "\x1b[0m")
	fmt.Fprintf(w, text, "\x1b[34m", "\x1b[1m", "\x1b[21m", "\x1b[44;33m", "\x1b[0m")
	fmt.Fprintf(w, text, "\x1b[35m", "\x1b[1m", "\x1b[21m", "\x1b[45;36m", "\x1b[0m")
	fmt.Fprintf(w, text, "\x1b[36m", "\x1b[1m", "\x1b[21m", "\x1b[46;35m", "\x1b[0m")
	fmt.Fprintf(w, text, "\x1b[37m", "\x1b[1m", "\x1b[21m", "\x1b[47;30m", "\x1b[0m")
}
Output:

Types

This section is empty.

Directories

Path Synopsis
The ansicolor command colors a console text by ANSI escape sequence like wac.
The ansicolor command colors a console text by ANSI escape sequence like wac.

Jump to

Keyboard shortcuts

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