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 iter.HasNext() {
	line, _ := iter.Next()
	fmt.Println(line)
}

Or

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

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.458s	coverage: 95.6% of statements

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

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

Now using version go1.21.13
go version go1.21.13 darwin/amd64
ok  	github.com/sttk/linebreak	0.468s	coverage: 95.6% of statements

Now using version go1.22.12
go version go1.22.12 darwin/amd64
ok  	github.com/sttk/linebreak	0.470s	coverage: 95.6% of statements

Now using version go1.23.10
go version go1.23.10 darwin/amd64
ok  	github.com/sttk/linebreak	0.473s	coverage: 95.6% of statements

Now using version go1.24.6
go version go1.24.6 darwin/amd64
ok  	github.com/sttk/linebreak	0.483s	coverage: 95.6% of statements

Now using version go1.25.0
go version go1.25.0 darwin/amd64
ok  	github.com/sttk/linebreak	0.476s	coverage: 95.6% of statements

Back to go1.25.0
Now using version go1.25.0

License

Copyright (C) 2023-2025 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