From 342bdd01778204e392dc24d7734c0e17b1547b99 Mon Sep 17 00:00:00 2001 From: Martin Geisler Date: Sun, 13 Dec 2020 11:03:11 +0100 Subject: [PATCH] Use command line arguments as initial text in interactive example This makes it super easy to repeatedly test with a custom text. --- examples/interactive.rs | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/examples/interactive.rs b/examples/interactive.rs index d7f3e252..3d3d88cf 100644 --- a/examples/interactive.rs +++ b/examples/interactive.rs @@ -258,8 +258,12 @@ mod unix_only { let mut idx_iter = (0..splitters.len()).collect::>().into_iter().cycle(); - let mut text = String::from( - "Welcome to the interactive demo! The following is from The \ + let args = std::env::args().collect::>(); + let mut text = if args.len() > 1 { + args[1..].join(" ") + } else { + String::from( + "Welcome to the interactive demo! The following is from The \ Emperor’s New Clothes by Hans Christian Andersen. You can edit the \ text!\n\n\ Many years ago there was an Emperor, who was so excessively fond \ @@ -270,7 +274,8 @@ mod unix_only { as one does about any other king or emperor, ‘He is in his council \ chamber,’ here one always said, ‘The Emperor is in his \ dressing-room.’", - ); + ) + }; let stdin = io::stdin(); let mut screen = AlternateScreen::from(io::stdout().into_raw_mode()?);