Collection of ANSI escapes for Go
MIT License
ansi-scapes is a minimal Go library for ANSI escape sequences. It handles the small differences in the Apple's Terminal app, as well as enable and disable escape sequences on Windows 10 v1511 and later.
🚧 ansi-escapes is still under development, and is subject to change 🚧
With the Go Programming Language,
$ go get -u github.com/snugfox/ansi-escapes
Go's import mechanism does not allow package names to contain hyphens, so import
the package as escapes
.
import escapes "github.com/snugfox/ansi-escapes"
package main
import (
"bytes"
"fmt"
"os"
escapes "github.com/snugfox/ansi-escapes"
)
func main() {
// Enable support on Windows for this application. It is safe to include on
// OSes other than Windows, as the functions will only return nil; thus
// compiled out.
escapes.EnableVirtualTerminal(escapes.Stdout)
defer escapes.DisableVirtualTerminal(escapes.Stdout)
// Erase the screen. Remember that fmt.Println would print the newline *after*
// the escape sequence.
fmt.Print(escapes.EraseScreen)
// Move the cursor one column to the right
fmt.Print(escapes.CursorForward)
// Move the cursor to (1, 1)
fmt.Print(escapes.CursorPos(1, 1))
// Display a super secret image
var buf bytes.Buffer
file, _ := os.Open("meow.jpg")
buf.ReadFrom(file)
fmt.Print(escapes.Image(buf.Bytes()))
}
MIT (c) Snug_Fox