Name | Date | Size | #Lines | LOC | ||
---|---|---|---|---|---|---|
.. | 03-May-2022 | - | ||||
README.md | H A D | 17-May-2018 | 2.5 KiB | |||
cursor.go | H A D | 17-May-2018 | 881 | |||
cursor_windows.go | H A D | 17-May-2018 | 1.7 KiB | |||
display.go | H A D | 17-May-2018 | 114 | |||
display_windows.go | H A D | 17-May-2018 | 564 | |||
output.go | H A D | 17-May-2018 | 379 | |||
output_windows.go | H A D | 17-May-2018 | 4.1 KiB | |||
print.go | H A D | 17-May-2018 | 618 | |||
syscall_windows.go | H A D | 17-May-2018 | 1,013 |
README.md
1# go-ansi 2 3Windows-portable ANSI escape sequence utility for Go language 4 5## What's this? 6 7This library converts ANSI escape sequences to Windows API calls on Windows environment. 8You can easily use this feature by replacing `fmt` with `ansi`. 9 10![](http://i.gyazo.com/12ecc4e1b4387f5c56d3e6ae319ab6c4.png) 11![](http://i.gyazo.com/c41072712ee05e28565ca92b416675e2.png) 12 13### Output redirection 14 15Many coloring libraries for Go just use ANSI escape sequences, which don't work on Windows. 16 17- [fatih/color](https://github.com/fatih/color) 18- [mitchellh/colorstring](https://github.com/mitchellh/colorstring) 19 20If you use go-ansi, you can use these libraries' nice APIs for Windows too. 21Not only coloring, many ANSI escape sequences are available. 22 23```go 24color.Output = ansi.NewAnsiStdout() 25color.Cyan("fatih/color") 26 27colorstring.Fprintln(ansi.NewAnsiStdout(), "[green]mitchellh/colorstring") 28``` 29 30### Cursor 31 32You can control cursor in your terminal. Of course it works on cmd.exe. 33In a following table, "Shell" shows a unix-like shortcut for the action. 34(It is not provided by this library and just for the explanation.) 35 36| API | Escape Code | Shell | Description | 37|:----|:----------------|:--|:------------| 38| ansi.CursorUp(n) | CSI `n` A | C-p | Move the cursor n cells to up | 39| ansi.CursorDown(n) | CSI `n` B | C-n | Move the cursor n cells to down | 40| ansi.CursorForward(n) | CSI `n` C | C-f | Move the cursor n cells to right | 41| ansi.CursorBack(n) | CSI `n` D | C-b | Move the cursor n cells to left | 42| ansi.CursorNextLine(n) | CSI `n` E | C-n C-a | Move cursor to beginning of the line n lines down. | 43| ansi.CursorPreviousLine(n) | CSI `n` F | C-p C-a | Move cursor to beginning of the line n lines up. | 44| ansi.CursorHorizontalAbsolute(x) | CSI `n` G | C-a,<br>C-e | Moves the cursor to column n. | 45 46### Display 47 48You can easily control your terminal display. You can easily provide unix-like 49shell functionarities for display, such as C-k or C-l. 50 51| API | Escape Code | Shell | Description | 52|:----|:----------------|:--|:------------| 53| ansi.EraseInLine(n) | CSI `n` K | C-k, C-u,<br>C-a C-k | 0: clear to the end of the line. <br> 1: clear to the beginning of the line. <br> 2: clear entire line. | 54 55## API document 56 57https://godoc.org/github.com/k0kubun/go-ansi 58 59## Notes 60 61This is just a cursor and display supported version of [mattn/go-colorable](https://github.com/mattn/go-colorable). 62I used almost the same implementation as it for coloring. Many thanks for [@mattn](https://github.com/mattn). 63 64## License 65 66MIT License 67