ansi

package module
v0.0.0-...-3bf9e29 Latest Latest
Warning

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

Go to latest
Published: May 17, 2018 License: MIT Imports: 3 Imported by: 451

README

go-ansi

Windows-portable ANSI escape sequence utility for Go language

What's this?

This library converts ANSI escape sequences to Windows API calls on Windows environment.
You can easily use this feature by replacing fmt with ansi.

Output redirection

Many coloring libraries for Go just use ANSI escape sequences, which don't work on Windows.

If you use go-ansi, you can use these libraries' nice APIs for Windows too. Not only coloring, many ANSI escape sequences are available.

color.Output = ansi.NewAnsiStdout()
color.Cyan("fatih/color")

colorstring.Fprintln(ansi.NewAnsiStdout(), "[green]mitchellh/colorstring")
Cursor

You can control cursor in your terminal. Of course it works on cmd.exe. In a following table, "Shell" shows a unix-like shortcut for the action. (It is not provided by this library and just for the explanation.)

API Escape Code Shell Description
ansi.CursorUp(n) CSI n A C-p Move the cursor n cells to up
ansi.CursorDown(n) CSI n B C-n Move the cursor n cells to down
ansi.CursorForward(n) CSI n C C-f Move the cursor n cells to right
ansi.CursorBack(n) CSI n D C-b Move the cursor n cells to left
ansi.CursorNextLine(n) CSI n E C-n C-a Move cursor to beginning of the line n lines down.
ansi.CursorPreviousLine(n) CSI n F C-p C-a Move cursor to beginning of the line n lines up.
ansi.CursorHorizontalAbsolute(x) CSI n G C-a,
C-e
Moves the cursor to column n.
Display

You can easily control your terminal display. You can easily provide unix-like shell functionarities for display, such as C-k or C-l.

API Escape Code Shell Description
ansi.EraseInLine(n) CSI n K C-k, C-u,
C-a C-k
0: clear to the end of the line.
1: clear to the beginning of the line.
2: clear entire line.

API document

https://godoc.org/github.com/k0kubun/go-ansi

Notes

This is just a cursor and display supported version of mattn/go-colorable. I used almost the same implementation as it for coloring. Many thanks for @mattn.

License

MIT License

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func CursorBack

func CursorBack(n int)

Move the cursor n cells to left.

func CursorDown

func CursorDown(n int)

Move the cursor n cells to down.

func CursorForward

func CursorForward(n int)

Move the cursor n cells to right.

func CursorHide

func CursorHide()

Hide the cursor.

func CursorHorizontalAbsolute

func CursorHorizontalAbsolute(x int)

Move cursor horizontally to x.

func CursorNextLine

func CursorNextLine(n int)

Move cursor to beginning of the line n lines down.

func CursorPreviousLine

func CursorPreviousLine(n int)

Move cursor to beginning of the line n lines up.

func CursorShow

func CursorShow()

Show the cursor.

func CursorUp

func CursorUp(n int)

Move the cursor n cells to up.

func EraseInLine

func EraseInLine(mode int)

func NewAnsiStderr

func NewAnsiStderr() io.Writer

Returns special stderr, which converts escape sequences to Windows API calls on Windows environment.

func NewAnsiStdout

func NewAnsiStdout() io.Writer

Returns special stdout, which converts escape sequences to Windows API calls on Windows environment.

func Print

func Print(a ...interface{}) (n int, err error)

Print prints given arguments with escape sequence conversion for windows.

func Printf

func Printf(format string, a ...interface{}) (n int, err error)

Printf prints a given format with escape sequence conversion for windows.

func Println

func Println(a ...interface{}) (n int, err error)

Println prints given arguments with newline and escape sequence conversion for windows.

Types

This section is empty.

Jump to

Keyboard shortcuts

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