Readme.md

 1# go-term-text
 2
 3[![Build Status](https://travis-ci.org/MichaelMure/go-term-text.svg?branch=master)](https://travis-ci.org/MichaelMure/go-term-text)
 4[![GoDoc](https://godoc.org/github.com/MichaelMure/go-term-text?status.svg)](https://godoc.org/github.com/MichaelMure/go-term-text)
 5[![Go Report Card](https://goreportcard.com/badge/github.com/MichaelMure/go-term-text)](https://goreportcard.com/report/github.com/MichaelMure/go-term-text)
 6[![codecov](https://codecov.io/gh/MichaelMure/go-term-text/branch/master/graph/badge.svg)](https://codecov.io/gh/MichaelMure/go-term-text)
 7[![GitHub license](https://img.shields.io/github/license/MichaelMure/go-term-text.svg)](https://github.com/MichaelMure/go-term-text/blob/master/LICENSE)
 8[![Gitter chat](https://badges.gitter.im/gitterHQ/gitter.png)](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![example output](/img/example.png)
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