text-formatting.rs 882 B

12345678910111213141516171819202122
  1. use gecliht;
  2. fn main () {
  3. let languages = ["Rust", "Ruby", "Java"];
  4. println!("Working with languages {}.", gecliht::words_with_commas(&languages));
  5. // display large piece of text
  6. let text = "Miss Bennet’s astonishment was soon lessened by the strong sisterly partiality which made any admiration of Elizabeth appear perfectly natural; and all surprise was shortly lost in other feelings. She was sorry that Mr. Darcy should have delivered his sentiments in a manner so little suited to recommend them; but still more was she grieved for the unhappiness which her sister’s refusal must have given him.";
  7. display_text(&text, 80);
  8. display_text(&text, 40);
  9. }
  10. fn display_text(text: &str, width: usize) {
  11. println!("\n{:->width$}", "-", width=width);
  12. for line in gecliht::word_wrap(&text, width).iter() {
  13. println!("{}", line);
  14. }
  15. }