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

..03-May-2022-

LICENSE.mdH A D28-Aug-20181.1 KiB

README.mdH A D28-Aug-20181 KiB

go.modH A D28-Aug-201840

wordwrap.goH A D28-Aug-20181.6 KiB

wordwrap_test.goH A D28-Aug-20181.7 KiB

README.md

1# go-wordwrap
2
3`go-wordwrap` (Golang package: `wordwrap`) is a package for Go that
4automatically wraps words into multiple lines. The primary use case for this
5is in formatting CLI output, but of course word wrapping is a generally useful
6thing to do.
7
8## Installation and Usage
9
10Install using `go get github.com/mitchellh/go-wordwrap`.
11
12Full documentation is available at
13http://godoc.org/github.com/mitchellh/go-wordwrap
14
15Below is an example of its usage ignoring errors:
16
17```go
18wrapped := wordwrap.WrapString("foo bar baz", 3)
19fmt.Println(wrapped)
20```
21
22Would output:
23
24```
25foo
26bar
27baz
28```
29
30## Word Wrap Algorithm
31
32This library doesn't use any clever algorithm for word wrapping. The wrapping
33is actually very naive: whenever there is whitespace or an explicit linebreak.
34The goal of this library is for word wrapping CLI output, so the input is
35typically pretty well controlled human language. Because of this, the naive
36approach typically works just fine.
37
38In the future, we'd like to make the algorithm more advanced. We would do
39so without breaking the API.
40