Function cursive::utils::prefix [] [src]

pub fn prefix<'a, I>(iter: I, available_width: usize, delimiter: &str) -> Prefix where I: Iterator<Item=&'a str>

Computes the length (number of bytes) and width of a prefix that fits in the given width.

Takes non-breakable elements from iter, while keeping the string width under width (and adding the length of delimiter between each element).

Given total_text = iter.collect().join(delimiter), the result is the length of the longest prefix of width or less cells, without breaking inside an element.

Example:

extern crate unicode_segmentation;
use unicode_segmentation::UnicodeSegmentation;

let my_text = "blah...";
// This returns the number of bytes for a prefix of `my_text` that
// fits within 5 cells.
prefix(my_text.graphemes(true), 5, "");