Name Description Size
columns.rs Functionality for wrapping text into columns. 6364
core.rs Building blocks for advanced wrapping functionality. The functions and structs in this module can be used to implement advanced wrapping functionality when [`wrap()`](crate::wrap()) [`fill()`](crate::fill()) don't do what you want. In general, you want to follow these steps when wrapping something: 1. Split your input into [`Fragment`]s. These are abstract blocks of text or content which can be wrapped into lines. See [`WordSeparator`](crate::word_separators::WordSeparator) for how to do this for text. 2. Potentially split your fragments into smaller pieces. This allows you to implement things like hyphenation. If you use the `Word` type, you can use [`WordSplitter`](crate::WordSplitter) enum for this. 3. Potentially break apart fragments that are still too large to fit on a single line. This is implemented in [`break_words`]. 4. Finally take your fragments and put them into lines. There are two algorithms for this in the [`wrap_algorithms`](crate::wrap_algorithms) module: [`wrap_optimal_fit`](crate::wrap_algorithms::wrap_optimal_fit) and [`wrap_first_fit`](crate::wrap_algorithms::wrap_first_fit). The former produces better line breaks, the latter is faster. 5. Iterate through the slices returned by the wrapping functions and construct your lines of output. Please [open an issue](https://github.com/mgeisler/textwrap/) if the functionality here is not sufficient or if you have ideas for improving it. We would love to hear from you! 16374
fill.rs Functions for filling text. 9262
fuzzing.rs Fuzzing helpers. 736
indentation.rs Functions related to adding and removing indentation from lines of text. The functions here can be used to uniformly indent or dedent (unindent) word wrapped lines of text. 8272
lib.rs 7989
line_ending.rs Line ending detection and conversion. 2646
options.rs Options for wrapping text. 10227
refill.rs Functionality for unfilling and refilling text. 10994
termwidth.rs Functions related to the terminal size. 1581
word_separators.rs Functionality for finding words. In order to wrap text, we need to know where the legal break points are, i.e., where the words of the text are. This means that we need to define what a "word" is. A simple approach is to simply split the text on whitespace, but this does not work for East-Asian languages such as Chinese or Japanese where there are no spaces between words. Breaking a long sequence of emojis is another example where line breaks might be wanted even if there are no whitespace to be found. The [`WordSeparator`] enum is responsible for determining where there words are in a line of text. Please refer to the enum and its variants for more information. 16397
word_splitters.rs Word splitting functionality. To wrap text into lines, long words sometimes need to be split across lines. The [`WordSplitter`] enum defines this functionality. 10455
wrap.rs Functions for wrapping text. 22166
wrap_algorithms
wrap_algorithms.rs Word wrapping algorithms. After a text has been broken into words (or [`Fragment`]s), one now has to decide how to break the fragments into lines. The simplest algorithm for this is implemented by [`wrap_first_fit()`]: it uses no look-ahead and simply adds fragments to the line as long as they fit. However, this can lead to poor line breaks if a large fragment almost-but-not-quite fits on a line. When that happens, the fragment is moved to the next line and it will leave behind a large gap. A more advanced algorithm, implemented by [`wrap_optimal_fit()`], will take this into account. The optimal-fit algorithm considers all possible line breaks and will attempt to minimize the gaps left behind by overly short lines. While both algorithms run in linear time, the first-fit algorithm is about 4 times faster than the optimal-fit algorithm. 14964