1# go-term-text
2
3[](https://travis-ci.org/MichaelMure/go-term-text)
4[](https://godoc.org/github.com/MichaelMure/go-term-text)
5[](https://goreportcard.com/report/github.com/MichaelMure/go-term-text)
6[](https://codecov.io/gh/MichaelMure/go-term-text)
7[](https://github.com/MichaelMure/go-term-text/blob/master/LICENSE)
8[](https://gitter.im/the-git-bug/Lobby)
9
10`go-term-text` is a go package implementing a collection of algorithms to help format and manipulate text for the terminal.
11
12In particular, `go-term-text`:
13- support wide characters (chinese, japanese ...) and emoji
14- handle properly ANSI escape sequences
15
16Included algorithms cover:
17- wrapping with padding and indentation
18- padding
19- text length
20- trimming
21- alignment
22- escape sequence extraction and reapplication
23- truncation
24
25## Example
26
27```go
28package main
29
30import (
31 "fmt"
32 "strings"
33
34 text "github.com/MichaelMure/go-term-text"
35)
36
37func main() {
38 input := "The \x1b[1mLorem ipsum\x1b[0m text is typically composed of " +
39 "pseudo-Latin words. It is commonly used as \x1b[3mplaceholder\x1b[0m" +
40 " text to examine or demonstrate the \x1b[9mvisual effects\x1b[0m of " +
41 "various graphic design. 一只 A Quick \x1b[31m敏捷的狐 Fox " +
42 "狸跳过了\x1b[0mDog一只懒狗。"
43
44 output, n := text.WrapWithPadIndent(input, 60,
45 "\x1b[34m<-indent-> \x1b[0m", "\x1b[33m<-pad-> \x1b[0m")
46
47 fmt.Printf("output has %d lines\n\n", n)
48
49 fmt.Println("|" + strings.Repeat("-", 58) + "|")
50 fmt.Println(output)
51 fmt.Println("|" + strings.Repeat("-", 58) + "|")
52}
53```
54
55This will print:
56
57
58
59For more details, have a look at the [GoDoc](https://godoc.org/github.com/MichaelMure/go-term-text).
60
61## Origin
62
63This package has been extracted from the [git-bug](https://github.com/MichaelMure/git-bug) project. As such, its aim is to support this project and not to provide an all-in-one solution. Contributions as welcome though.
64
65## Contribute
66
67PRs accepted.
68
69## License
70
71MIT