tree: 32a63a02f655e5ab75cea927f7f36136776fa476 [path history] [tgz]
  1. ansicolor/
  2. .gitignore
  3. ansicolor.go
  4. ansicolor_ansi.go
  5. ansicolor_windows.go
  6. ansicolor_windows_test.go
  7. example_test.go
  8. export_test.go
  9. LICENSE
  10. README.google
  11. README.md
go/src/github.com/shiena/ansicolor/README.md

ansicolor

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

Features

Escape sequenceText attributes
\x1b[0mAll attributes off(color at startup)
\x1b[1mBold on(enable foreground intensity)
\x1b[4mUnderline on
\x1b[5mBlink on(enable background intensity)
\x1b[21mBold off(disable foreground intensity)
\x1b[24mUnderline off
\x1b[25mBlink off(disable background intensity)
Escape sequenceForeground colors
\x1b[30mBlack
\x1b[31mRed
\x1b[32mGreen
\x1b[33mYellow
\x1b[34mBlue
\x1b[35mMagenta
\x1b[36mCyan
\x1b[37mWhite
\x1b[39mDefault(foreground color at startup)
Escape sequenceBackground colors
\x1b[40mBlack
\x1b[41mRed
\x1b[42mGreen
\x1b[43mYellow
\x1b[44mBlue
\x1b[45mMagenta
\x1b[46mCyan
\x1b[47mWhite
\x1b[49mDefault(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