Merge pull request #251 from mgeisler/release-0.13.1

Release 0.13.1
tree: 3ce4665f0276ebc0e5dcdc42108cff8d6404632e
  1. .github/
  2. .gitignore
  4. Cargo.toml
  7. benches/
  8. examples/
  9. src/
  10. tests/


Textwrap is a library for word wrapping text. You can use it to format strings for display in commandline applications. The crate name and interface is inspired by the Python textwrap module.


To use textwrap, add this to your Cargo.toml file:

textwrap = "0.13"

This gives you the text wrapping without of the optional Cargo features listed next.


If you would like to have automatic language-sensitive hyphenation, enable the hyphenation feature:

textwrap = { version = "0.13", features = ["hyphenation"] }

This gives you hyphenation support for US English. Please see the hyphenation example for an executable demo. Read the Getting Started section below to see how to load the hyphenation patterns for other languages.


To conveniently wrap text at the current terminal width, enable the terminal_size feature:

textwrap = { version = "0.13", features = ["terminal_size"] }

Please see the termwidth example for how to use this feature.


API documentation

Getting Started

Word wrapping is easy using the fill function:

fn main() {

The output is wrapped within 28 columns:

textwrap: an efficient
and powerful library for
wrapping text.



Without look ahead, the first line would be longer and the text would look like this:

textwrap: an efficient and
powerful library for
wrapping text.




use hyphenation::{Language, Load, Standard};
use textwrap::Options;

fn main() {

The output now looks like this:

textwrap: an efficient and
powerful library for wrap-
ping text.


Wrapping Strings at Compile Time





Run the demo with

$ cargo run --example interactive

The demo needs a Linux terminal to function.

Release History


