Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/cbess/go-textwrap
Simple and pure Go text wrapping port of Python textwrap
https://github.com/cbess/go-textwrap
formatter golang textwrap
Last synced: about 1 month ago
JSON representation
Simple and pure Go text wrapping port of Python textwrap
- Host: GitHub
- URL: https://github.com/cbess/go-textwrap
- Owner: cbess
- License: other
- Created: 2019-09-24T03:24:03.000Z (about 5 years ago)
- Default Branch: master
- Last Pushed: 2019-10-29T22:20:17.000Z (about 5 years ago)
- Last Synced: 2024-04-14T15:44:19.930Z (7 months ago)
- Topics: formatter, golang, textwrap
- Language: Go
- Homepage:
- Size: 6.84 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Go Text Wrapping
It is a lightweight and simple port of the [textwrap](https://docs.python.org/3.6/library/textwrap.html) Python module.
[Soli Deo gloria](https://perfectGod.com)
Features:
- Lightweight. Uses only the Go built-in library (no external deps).
- Simple. Easy to understand code.
- Counts number of words and characters.
- Splits (or groups) text based on character limit (width) per group (each wrap).
- `100%` test coverage.
- [GoDoc](https://godoc.org/github.com/cbess/go-textwrap) documentation### Note
It was only designed to work with English text; it separates words by whitespace.
## Example
```go
import (
"fmt"
"textwrap"
)origText := "Jesus is God. He Saves by grace through faith alone."
result, err := textwrap.WordWrap(origText, 10, -1)
if err != nil {
// handle error
}// check if max word count exceeded
if result.IsValid() {
// print text groups
for idx, text := range result.TextGroups {
fmt.Println("[", idx+1, "]", text)
}
}
```## License
MIT