]> git.proxmox.com Git - rustc.git/blob - vendor/textwrap/examples/termwidth.rs
New upstream version 1.72.1+dfsg1
[rustc.git] / vendor / textwrap / examples / termwidth.rs
1 #[cfg(feature = "hyphenation")]
2 extern crate hyphenation;
3 extern crate textwrap;
4
5 #[cfg(feature = "hyphenation")]
6 use hyphenation::{Language, Load, Standard};
7 #[cfg(feature = "term_size")]
8 use textwrap::Wrapper;
9
10 #[cfg(not(feature = "term_size"))]
11 fn main() {
12 println!("Please enable the term_size feature to run this example.");
13 }
14
15 #[cfg(feature = "term_size")]
16 fn main() {
17 #[cfg(not(feature = "hyphenation"))]
18 fn new_wrapper<'a>() -> (&'static str, Wrapper<'a, textwrap::HyphenSplitter>) {
19 ("without hyphenation", Wrapper::with_termwidth())
20 }
21
22 #[cfg(feature = "hyphenation")]
23 fn new_wrapper<'a>() -> (&'static str, Wrapper<'a, Standard>) {
24 let dictionary = Standard::from_embedded(Language::EnglishUS).unwrap();
25 (
26 "with hyphenation",
27 Wrapper::with_splitter(textwrap::termwidth(), dictionary),
28 )
29 }
30
31 let example = "Memory safety without garbage collection. \
32 Concurrency without data races. \
33 Zero-cost abstractions.";
34 // Create a new Wrapper -- automatically set the width to the
35 // current terminal width.
36 let (msg, wrapper) = new_wrapper();
37 println!("Formatted {} in {} columns:", msg, wrapper.width);
38 println!("----");
39 println!("{}", wrapper.fill(example));
40 println!("----");
41 }