Coder Social home page Coder Social logo

go-ansi's Introduction

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

go-ansi's People

Contributors

k0kubun avatar malashin avatar plusvic avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.