Skip to content

sttk/linebreak

Repository files navigation

A library for breaking a given text into lines within a specified width. This library also supports per-line indentation.

Import declaration

To use this package in your code, the following import declaration is necessary.

import "github.com/sttk/linebreak"

Usage

The following code breaks the argument text into lines within the terminal width, and outputs them to stdout.

iter := linebreak.New(text, linebreak.TermCols())
for {
	line, more := iter.Next()
	fmt.Println(line)
	if !more {
		break
	}
}

Supporting Go versions

This library supports Go 1.18 or later.

Actual test results for each Go version:

% gvm-fav
Now using version go1.18.10
go version go1.18.10 darwin/amd64
ok  	github.com/sttk/linebreak	0.164s	coverage: 98.3% of statements

Now using version go1.19.13
go version go1.19.13 darwin/amd64
ok  	github.com/sttk/linebreak	0.170s	coverage: 98.3% of statements

Now using version go1.20.14
go version go1.20.14 darwin/amd64
ok  	github.com/sttk/linebreak	0.127s	coverage: 98.3% of statements

Now using version go1.21.7
go version go1.21.7 darwin/amd64
ok  	github.com/sttk/linebreak	0.159s	coverage: 98.3% of statements

Now using version go1.22
go version go1.22.0 darwin/amd64
ok  	github.com/sttk/linebreak	0.128s	coverage: 98.3% of statements

Back to go1.22
Now using version go1.22

License

Copyright (C) 2023-2024 Takayuki Sato

This program is free software under MIT License.
See the file LICENSE in this distribution for more details.

About

A library for breaking a given text into lines within a specified width.

Resources

License

Stars

Watchers

Forks

Packages

No packages published