Skip to content

Add unconditional (non-word) wrapping #29

@erikgeiser

Description

@erikgeiser

I think general non-word wrapping would be a great addition to this library. This algorithm should just break as soon as the limit is reached. This would also be a great addition to wordwrap, as wordwrap does currently not enforce the given limit if the length of single words already exceeds the limit.

A typical usecase would be to stay confined to the terminal width: In this case word-wrapping is nice but the limit has to be strictly enforced so word-wrapping could be applied first and then the general wrapping.

package main

import (
	"fmt"

	"github.com/muesli/reflow/wordwrap"
	"github.com/muesli/reflow/wrap"

)

func main() {
	test := "AAAAA BBBBBBBBBBB"

	fmt.Println(wordwrap.String(test, 8))
	// output:
	// AAAAA
	// BBBBBBBBBBB

	fmt.Println(wrap.String(wordwrap.String(test, 8), 8))
	// output:
	// AAAAA
	// BBBBBBBB
	// BBB
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions