A Rust library for wrapping and indenting text with optimal-fit algorithms and hyphenation support.
Textwrap is a Rust library for wrapping and indenting text, designed to format dynamic output for command-line programs and other applications like PDF generation or WebAssembly-based rendering. It solves the problem of making text fit within specified widths while maintaining readability and aesthetic balance.
Rust developers building command-line tools, terminal applications, or systems that generate formatted text output, such as PDFs or canvas-based UIs.
Developers choose Textwrap for its efficient optimal-fit algorithm, support for Unicode and hyphenation, and modular design that allows them to pay only for the features they use, keeping binaries small.
An efficient and powerful Rust library for word wrapping text.
Open-Awesome is built by the community, for the community. Submit a project, suggest an awesome list, or help improve the catalog on GitHub.
Uses look-ahead to minimize gaps at line ends for balanced text, as demonstrated with the 'smawk' feature enabling smarter line breaks compared to basic wrapping.
Offers customizable wrap algorithms and word splitters via the Options struct, and allows enabling only necessary features to keep binaries lean, as highlighted in the Cargo features documentation.
Handles Unicode strings by default and supports hyphenation for about 70 languages using high-quality TeX patterns via an optional feature, though it adds binary size.
Provides procedural macros through the textwrap-macros crate for wrapping strings known at compile time, improving performance for static text.
Enabling features like hyphenation significantly increases binary size (e.g., 88 KB for US-English patterns), which can be a drawback for resource-constrained environments.
The interactive demo, key for feature exploration, only works on Linux terminals, limiting usability for developers on Windows or macOS.
Hyphenation requires loading external patterns and configuring WordSplitter, adding steps and potential dependency management issues compared to basic usage.