• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..20-Jul-2021-

aec-1.0.0/H03-May-2022-1,061706

LICENSEH A D20-Jul-20211.1 KiB2217

README.mdH A D20-Jul-20212.7 KiB179135

aec.goH A D20-Jul-20212.4 KiB13891

ansi.goH A D20-Jul-2021978 6040

builder.goH A D20-Jul-20219.3 KiB389233

sgr.goH A D20-Jul-20213.9 KiB203133

README.md

1# aec
2
3[![GoDoc](https://godoc.org/github.com/morikuni/aec?status.svg)](https://godoc.org/github.com/morikuni/aec)
4
5Go wrapper for ANSI escape code.
6
7## Install
8
9```bash
10go get github.com/morikuni/aec
11```
12
13## Features
14
15ANSI escape codes depend on terminal environment.
16Some of these features may not work.
17Check supported Font-Style/Font-Color features with [checkansi](./checkansi).
18
19[Wikipedia](https://en.wikipedia.org/wiki/ANSI_escape_code) for more detail.
20
21### Cursor
22
23- `Up(n)`
24- `Down(n)`
25- `Right(n)`
26- `Left(n)`
27- `NextLine(n)`
28- `PreviousLine(n)`
29- `Column(col)`
30- `Position(row, col)`
31- `Save`
32- `Restore`
33- `Hide`
34- `Show`
35- `Report`
36
37### Erase
38
39- `EraseDisplay(mode)`
40- `EraseLine(mode)`
41
42### Scroll
43
44- `ScrollUp(n)`
45- `ScrollDown(n)`
46
47### Font Style
48
49- `Bold`
50- `Faint`
51- `Italic`
52- `Underline`
53- `BlinkSlow`
54- `BlinkRapid`
55- `Inverse`
56- `Conceal`
57- `CrossOut`
58- `Frame`
59- `Encircle`
60- `Overline`
61
62### Font Color
63
64Foreground color.
65
66- `DefaultF`
67- `BlackF`
68- `RedF`
69- `GreenF`
70- `YellowF`
71- `BlueF`
72- `MagentaF`
73- `CyanF`
74- `WhiteF`
75- `LightBlackF`
76- `LightRedF`
77- `LightGreenF`
78- `LightYellowF`
79- `LightBlueF`
80- `LightMagentaF`
81- `LightCyanF`
82- `LightWhiteF`
83- `Color3BitF(color)`
84- `Color8BitF(color)`
85- `FullColorF(r, g, b)`
86
87Background color.
88
89- `DefaultB`
90- `BlackB`
91- `RedB`
92- `GreenB`
93- `YellowB`
94- `BlueB`
95- `MagentaB`
96- `CyanB`
97- `WhiteB`
98- `LightBlackB`
99- `LightRedB`
100- `LightGreenB`
101- `LightYellowB`
102- `LightBlueB`
103- `LightMagentaB`
104- `LightCyanB`
105- `LightWhiteB`
106- `Color3BitB(color)`
107- `Color8BitB(color)`
108- `FullColorB(r, g, b)`
109
110### Color Converter
111
11224bit RGB color to ANSI color.
113
114- `NewRGB3Bit(r, g, b)`
115- `NewRGB8Bit(r, g, b)`
116
117### Builder
118
119To mix these features.
120
121```go
122custom := aec.EmptyBuilder.Right(2).RGB8BitF(128, 255, 64).RedB().ANSI
123custom.Apply("Hello World")
124```
125
126## Usage
127
1281. Create ANSI by `aec.XXX().With(aec.YYY())` or `aec.EmptyBuilder.XXX().YYY().ANSI`
1292. Print ANSI by `fmt.Print(ansi, "some string", aec.Reset)` or `fmt.Print(ansi.Apply("some string"))`
130
131`aec.Reset` should be added when using font style or font color features.
132
133## Example
134
135Simple progressbar.
136
137![sample](./sample.gif)
138
139```go
140package main
141
142import (
143	"fmt"
144	"strings"
145	"time"
146
147	"github.com/morikuni/aec"
148)
149
150func main() {
151	const n = 20
152	builder := aec.EmptyBuilder
153
154	up2 := aec.Up(2)
155	col := aec.Column(n + 2)
156	bar := aec.Color8BitF(aec.NewRGB8Bit(64, 255, 64))
157	label := builder.LightRedF().Underline().With(col).Right(1).ANSI
158
159	// for up2
160	fmt.Println()
161	fmt.Println()
162
163	for i := 0; i <= n; i++ {
164		fmt.Print(up2)
165		fmt.Println(label.Apply(fmt.Sprint(i, "/", n)))
166		fmt.Print("[")
167		fmt.Print(bar.Apply(strings.Repeat("=", i)))
168		fmt.Println(col.Apply("]"))
169		time.Sleep(100 * time.Millisecond)
170	}
171}
172```
173
174## License
175
176[MIT](./LICENSE)
177
178
179