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- escape sequence snapshot and simplification
24- truncation
25
26## Example
27
28```go
29package main
30
31import (
32 "fmt"
33 "strings"
34
35 "github.com/MichaelMure/go-term-text"
36)
37
38func main() {
39 input := "The \x1b[1mLorem ipsum\x1b[0m text is typically composed of " +
40 "pseudo-Latin words. It is commonly used as \x1b[3mplaceholder\x1b[0m" +
41 " text to examine or demonstrate the \x1b[9mvisual effects\x1b[0m of " +
42 "various graphic design. 一只 A Quick \x1b[31m敏捷的狐 Fox " +
43 "狸跳过了\x1b[0mDog一只懒狗。"
44
45 output, n := text.Wrap(input, 60,
46 text.WrapIndent("\x1b[34m<-indent-> \x1b[0m"),
47 text.WrapPad("\x1b[33m<-pad-> \x1b[0m"),
48 )
49
50 fmt.Printf("output has %d lines\n\n", n)
51
52 fmt.Println("|" + strings.Repeat("-", 58) + "|")
53 fmt.Println(output)
54 fmt.Println("|" + strings.Repeat("-", 58) + "|")
55}
56```
57
58This will print:
59
60
61
62For more details, have a look at the [GoDoc](https://godoc.org/github.com/MichaelMure/go-term-text).
63
64## Origin
65
66This 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.
67
68## Contribute
69
70PRs accepted.
71
72## License
73
74MIT