summaryrefslogtreecommitdiffstats
path: root/third_party/rust/textwrap/examples/termwidth.rs
diff options
context:
space:
mode:
Diffstat (limited to 'third_party/rust/textwrap/examples/termwidth.rs')
-rw-r--r--third_party/rust/textwrap/examples/termwidth.rs21
1 files changed, 21 insertions, 0 deletions
diff --git a/third_party/rust/textwrap/examples/termwidth.rs b/third_party/rust/textwrap/examples/termwidth.rs
new file mode 100644
index 0000000000..7d81a5c654
--- /dev/null
+++ b/third_party/rust/textwrap/examples/termwidth.rs
@@ -0,0 +1,21 @@
+#[cfg(feature = "term_size")]
+extern crate textwrap;
+
+#[cfg(not(feature = "term_size"))]
+fn main() {
+ println!("Please enable the term_size feature to run this example.");
+}
+
+#[cfg(feature = "term_size")]
+fn main() {
+ let example = "Memory safety without garbage collection. \
+ Concurrency without data races. \
+ Zero-cost abstractions.";
+ // Create a new Wrapper -- automatically set the width to the
+ // current terminal width.
+ let wrapper = textwrap::Wrapper::with_termwidth();
+ println!("Formatted in within {} columns:", wrapper.width);
+ println!("----");
+ println!("{}", wrapper.fill(example));
+ println!("----");
+}