aboutsummaryrefslogtreecommitdiffstats
path: root/vendor/github.com/MichaelMure/go-term-text/Readme.md
blob: 25722ee9028c7ce0fdc082a12bf8f9f4227ebfb1 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
# go-term-text

[![Build Status](https://travis-ci.org/MichaelMure/go-term-text.svg?branch=master)](https://travis-ci.org/MichaelMure/go-term-text)
[![GoDoc](https://godoc.org/github.com/MichaelMure/go-term-text?status.svg)](https://godoc.org/github.com/MichaelMure/go-term-text)
[![Go Report Card](https://goreportcard.com/badge/github.com/MichaelMure/go-term-text)](https://goreportcard.com/report/github.com/MichaelMure/go-term-text)
[![codecov](https://codecov.io/gh/MichaelMure/go-term-text/branch/master/graph/badge.svg)](https://codecov.io/gh/MichaelMure/go-term-text)
[![GitHub license](https://img.shields.io/github/license/MichaelMure/go-term-text.svg)](https://github.com/MichaelMure/go-term-text/blob/master/LICENSE)
[![Gitter chat](https://badges.gitter.im/gitterHQ/gitter.png)](https://gitter.im/the-git-bug/Lobby)

`go-term-text` is a go package implementing a collection of algorithms to help format and manipulate text for the terminal.

In particular, `go-term-text`:
- support wide characters (chinese, japanese ...) and emoji
- handle properly ANSI escape sequences

Included algorithms cover:
- wrapping with padding and indentation
- padding
- text length
- trimming
- alignment
- escape sequence extraction and reapplication
- escape sequence snapshot and simplification
- truncation

## Example

```go
package main

import (
	"fmt"
	"strings"

	"github.com/MichaelMure/go-term-text"
)

func main() {
	input := "The \x1b[1mLorem ipsum\x1b[0m text is typically composed of " +
    		"pseudo-Latin words. It is commonly used as \x1b[3mplaceholder\x1b[0m" +
    		" text to examine or demonstrate the \x1b[9mvisual effects\x1b[0m of " +
    		"various graphic design. 一只 A Quick \x1b[31m敏捷的狐 Fox " +
    		"狸跳过了\x1b[0mDog一只懒狗。"

	output, n := text.Wrap(input, 60,
            text.WrapIndent("\x1b[34m<-indent-> \x1b[0m"),
            text.WrapPad("\x1b[33m<-pad-> \x1b[0m"),
    )

	fmt.Printf("output has %d lines\n\n", n)

	fmt.Println("|" + strings.Repeat("-", 58) + "|")
	fmt.Println(output)
	fmt.Println("|" + strings.Repeat("-", 58) + "|")
}
```

This will print:

![example output](/img/example.png)

For more details, have a look at the [GoDoc](https://godoc.org/github.com/MichaelMure/go-term-text).

## Origin

This 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.

## Contribute

PRs accepted.

## License

MIT