Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename Options::splitter to Options::word_splitter #369

Merged
merged 1 commit into from
May 30, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,15 +75,15 @@ automatic hyphenation for [about 70 languages][patterns] via
high-quality TeX hyphenation patterns.

Your program must load the hyphenation pattern and configure
`Options::splitter` to use it:
`Options::word_splitter` to use it:

```rust
use hyphenation::{Language, Load, Standard};
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