Skip to content

Commit

Permalink
Rename Options::splitter to Options::word_splitter
Browse files Browse the repository at this point in the history
This makes the field consistent with the `wrap_algorithm` and
`word_separator` fields.
  • Loading branch information
mgeisler committed May 30, 2021
1 parent c66ed13 commit a540758
Show file tree
Hide file tree
Showing 9 changed files with 95 additions and 93 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ use textwrap::Options;

fn main() {
let hyphenator = Standard::from_embedded(Language::EnglishUS).unwrap();
let options = Options::new(28).splitter(hyphenator);
let options = Options::new(28).word_splitter(hyphenator);
let text = "textwrap: an efficient and powerful library for wrapping text.";
println!("{}", fill(text, &options);
}
Expand Down
2 changes: 1 addition & 1 deletion benches/linear.rs
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ pub fn benchmark(c: &mut Criterion) {
.join("benches")
.join("la.standard.bincode");
let dictionary = Standard::from_path(Language::Latin, &path).unwrap();
let options = options.splitter(dictionary);
let options = options.word_splitter(dictionary);
group.bench_with_input(BenchmarkId::new("hyphenation", length), &text, |b, text| {
b.iter(|| textwrap::fill(text, &options));
});
Expand Down
2 changes: 1 addition & 1 deletion examples/hyphenation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,6 @@ fn main() {
fn main() {
let text = "textwrap: a small library for wrapping text.";
let dictionary = Standard::from_embedded(Language::EnglishUS).unwrap();
let options = textwrap::Options::new(18).splitter(dictionary);
let options = textwrap::Options::new(18).word_splitter(dictionary);
println!("{}", textwrap::fill(text, &options));
}
30 changes: 15 additions & 15 deletions examples/interactive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ mod unix_only {
Box<dyn word_separators::WordSeparator>,
Box<dyn word_splitters::WordSplitter>,
>,
splitter_label: &str,
word_splitter_label: &str,
stdout: &mut RawTerminal<io::Stdout>,
) -> Result<(), io::Error> {
let mut left_row: u16 = 1;
Expand Down Expand Up @@ -102,7 +102,7 @@ mod unix_only {
"{}- splitter: {}{}{} (cycle with Ctrl-s)",
cursor::Goto(left_col, left_row),
style::Bold,
splitter_label,
word_splitter_label,
style::Reset,
)?;
left_row += 1;
Expand Down Expand Up @@ -237,12 +237,12 @@ mod unix_only {
#[cfg(feature = "smawk")]
wrap_algorithms.push(Box::new(wrap_algorithms::OptimalFit));

let mut splitters: Vec<Box<dyn word_splitters::WordSplitter>> = vec![
let mut word_splitters: Vec<Box<dyn word_splitters::WordSplitter>> = vec![
Box::new(word_splitters::HyphenSplitter),
Box::new(word_splitters::NoHyphenation),
];
let mut splitter_labels: Vec<String> =
splitters.iter().map(|s| format!("{:?}", s)).collect();
let mut word_splitter_labels: Vec<String> =
word_splitters.iter().map(|s| format!("{:?}", s)).collect();

// If you like, you can download more dictionaries from
// https://github.com/tapeinosyne/hyphenation/tree/master/dictionaries
Expand All @@ -258,19 +258,19 @@ mod unix_only {
});

if let Ok(dict) = dictionary {
splitters.insert(0, Box::new(dict));
splitter_labels.insert(0, format!("{} hyphenation", lang.code()));
word_splitters.insert(0, Box::new(dict));
word_splitter_labels.insert(0, format!("{} hyphenation", lang.code()));
}
}

let mut options = Options::new(35)
.break_words(false)
.wrap_algorithm(wrap_algorithms.remove(0))
.splitter(splitters.remove(0))
.word_splitter(word_splitters.remove(0))
.word_separator(
Box::new(word_separators::AsciiSpace) as Box<dyn word_separators::WordSeparator>
);
let mut splitter_label = splitter_labels.remove(0);
let mut word_splitter_label = word_splitter_labels.remove(0);

let args = std::env::args().collect::<Vec<_>>();
let mut text = if args.len() > 1 {
Expand All @@ -294,7 +294,7 @@ mod unix_only {
let stdin = io::stdin();
let mut screen = AlternateScreen::from(io::stdout().into_raw_mode()?);
write!(screen, "{}", cursor::BlinkingUnderline)?;
draw_text(&text, &options, &splitter_label, &mut screen)?;
draw_text(&text, &options, &word_splitter_label, &mut screen)?;

for c in stdin.keys() {
match c? {
Expand All @@ -309,10 +309,10 @@ mod unix_only {
}
Key::Ctrl('s') => {
// We always keep the next splitter at position 0.
std::mem::swap(&mut options.splitter, &mut splitters[0]);
splitters.rotate_left(1);
std::mem::swap(&mut splitter_label, &mut splitter_labels[0]);
splitter_labels.rotate_left(1);
std::mem::swap(&mut options.word_splitter, &mut word_splitters[0]);
word_splitters.rotate_left(1);
std::mem::swap(&mut word_splitter_label, &mut word_splitter_labels[0]);
word_splitter_labels.rotate_left(1);
}
Key::Char(c) => text.push(c),
Key::Backspace => {
Expand All @@ -323,7 +323,7 @@ mod unix_only {
_ => {}
}

draw_text(&text, &options, &splitter_label, &mut screen)?;
draw_text(&text, &options, &word_splitter_label, &mut screen)?;
}

// TODO: change to cursor::DefaultStyle if
Expand Down
4 changes: 2 additions & 2 deletions examples/layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,13 @@ fn main() {
Zero-cost abstractions.";
let mut prev_lines = vec![];

let mut options = Options::new(0).splitter(Box::new(HyphenSplitter) as Box<dyn WordSplitter>);
let mut options = Options::new(0).word_splitter(Box::new(HyphenSplitter) as Box<dyn WordSplitter>);
#[cfg(feature = "hyphenation")]
{
use hyphenation::Load;
let language = hyphenation::Language::EnglishUS;
let dictionary = hyphenation::Standard::from_embedded(language).unwrap();
options.splitter = Box::new(dictionary);
options.word_splitter = Box::new(dictionary);
}

for width in 15..60 {
Expand Down
2 changes: 1 addition & 1 deletion examples/termwidth.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ fn main() {
#[cfg(feature = "hyphenation")]
let (msg, options) = (
"with hyphenation",
Options::with_termwidth().splitter(
Options::with_termwidth().word_splitter(
hyphenation::Standard::from_embedded(hyphenation::Language::EnglishUS).unwrap(),
),
);
Expand Down
Loading

0 comments on commit a540758

Please sign in to comment.