use std::borrow::Cow;
use textwrap::Options;
use textwrap::WordSeparator;
use textwrap::WordSplitter;
pub fn options<'a>() -> Options<'a> {
let opts = Options::with_termwidth()
.break_words(false)
.word_separator(WordSeparator::AsciiSpace)
.word_splitter(WordSplitter::NoHyphenation);
if cfg!(test) {
opts.with_width(80)
} else {
opts
}
}
pub trait TextWrapOptionsExt {
fn subtract_width(self, decrease: usize) -> Self;
fn with_width(self, width: usize) -> Self;
fn wrap<'s>(&self, text: &'s str) -> Vec<Cow<'s, str>>;
fn fill(&self, text: &str) -> String;
}
impl<'a> TextWrapOptionsExt for Options<'a> {
fn subtract_width(mut self, decrease: usize) -> Self {
self.width -= decrease;
self
}
fn with_width(mut self, width: usize) -> Self {
self.width = width;
self
}
fn wrap<'s>(&self, text: &'s str) -> Vec<Cow<'s, str>> {
textwrap::wrap(text, self)
}
fn fill(&self, text: &str) -> String {
textwrap::fill(text, self)
}
}