Open-Awesome
CategoriesAlternativesStacksSelf-HostedExplore
Open-Awesome

© 2026 Open-Awesome. Curated for the developer elite.

TermsPrivacyAboutGitHubRSS
  1. Home
  2. Rust
  3. textwrap

textwrap

MITRust0.16.2

A Rust library for wrapping and indenting text with optimal-fit algorithms and hyphenation support.

GitHubGitHub
523 stars53 forks0 contributors

What is textwrap?

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.

Target Audience

Rust developers building command-line tools, terminal applications, or systems that generate formatted text output, such as PDFs or canvas-based UIs.

Value Proposition

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.

Overview

An efficient and powerful Rust library for word wrapping text.

Use Cases

Best For

  • Formatting command-line program output for terminal display
  • Wrapping text in proportional fonts for PDF generation
  • Rendering wrapped text on HTML5 canvases using WebAssembly
  • Applications requiring multilingual hyphenation support
  • Optimizing text layout with minimal gaps at line ends
  • Reducing binary size by enabling only necessary text-wrapping features

Not Ideal For

  • Applications requiring rich text formatting with styles, colors, or multiple fonts
  • Projects with extremely tight binary size constraints where even optional features are prohibitive
  • Real-time GUI applications needing frequent, dynamic text reflow with minimal latency

Pros & Cons

Pros

Optimal-Fit Algorithm

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.

Configurable and Modular

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.

Unicode and Hyphenation Support

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.

Compile-Time Wrapping

Provides procedural macros through the textwrap-macros crate for wrapping strings known at compile time, improving performance for static text.

Cons

Binary Size Overhead

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.

Platform Limitations

The interactive demo, key for feature exploration, only works on Linux terminals, limiting usability for developers on Windows or macOS.

Complex Advanced Setup

Hyphenation requires loading external patterns and configuring WordSplitter, adding steps and potential dependency management issues compared to basic usage.

Frequently Asked Questions

Quick Stats

Stars523
Forks53
Contributors0
Open Issues24
Last commit7 days ago
CreatedSince 2016

Tags

#formatting#unicode#hyphenation#typography#wasm#text#rust#text-formatting#cli-tools

Built With

R
Rust

Included in

Rust56.6k
Auto-fetched 17 hours ago

Related Projects

ripgrep-allripgrep-all

rga: ripgrep, but also search in PDFs, E-Books, Office documents, zip, tar.gz, etc.

Stars9,765
Forks216
Last commit4 months ago
KreuzbergKreuzberg

A polyglot document intelligence framework with a Rust core. Extract text, metadata, images, and structured information from PDFs, Office documents, images, and 97+ formats. Available for Rust, Python, Ruby, Java, Go, PHP, Elixir, C#, R, C, TypeScript (Node/Bun/Wasm/Deno)- or use via CLI, REST API, or MCP server.

Stars8,691
Forks526
Last commit17 hours ago
grexgrex

A command-line tool and Rust library with Python bindings for generating regular expressions from user-provided test cases

Stars8,161
Forks196
Last commit4 months ago
MelodyMelody

Melody is a language that compiles to regular expressions and aims to be more readable and maintainable

Stars4,745
Forks57
Last commit1 year ago
Community-curated · Updated weekly · 100% open source

Found a gem we're missing?

Open-Awesome is built by the community, for the community. Submit a project, suggest an awesome list, or help improve the catalog on GitHub.

Submit a projectStar on GitHub