diff options
| author | Teddy Wing | 2016-04-05 21:05:34 -0400 |
|---|---|---|
| committer | Teddy Wing | 2016-04-05 21:05:34 -0400 |
| commit | 55b07581cf2e414460461e9e1591059b5dc459d3 (patch) | |
| tree | e1829789355d86d04f3c2b0b348101282c05f006 /src/main.rs | |
| parent | 3242b7d4cc1dbc785804fa784151c2ba74da1902 (diff) | |
| download | mutt-alias-auto-add-55b07581cf2e414460461e9e1591059b5dc459d3.tar.bz2 | |
Read stdin
Tried a few different times, copying code from different places. Didn't
quite get it figured out at first.
Wanted to add STDIN lines to a string. Got that working with option 3,
but that `push_str` didn't appear to preserve newlines.
Ended up using this solution from StackOverflow:
http://stackoverflow.com/questions/13579266/how-to-read-user-input-in-rust/36374135#36374135
It adds the lines to a vector instead of a single string. Printing each
line individually then gives us out newlines. This way is probably nicer
also for getting the first line that starts with "From: ".
Diffstat (limited to 'src/main.rs')
| -rw-r--r-- | src/main.rs | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/src/main.rs b/src/main.rs index b7fbd08..135e0c5 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,4 +1,33 @@ +use std::io::{self, BufRead}; +// use std::io::Read; + fn main() { + // let mut input = String::new(); + // io::stdin().read_to_end(&mut input).unwrap(); + // .expect("Failed to read STDIN"); + + // match io::stdin().lock() { + // Ok(s) => s.read_to_string(&mut input), + // Err(e) => panic!("Error: {}", e), + // } + + // let stdin = io::stdin(); + // for line in stdin.lock().lines() { + // input.push_str(&line.unwrap()); + // } + + // let stdin = io::stdin(); + // loop { + // stdin.read_line(&mut input).expect("asdf"); + // } + + let stdin = io::stdin(); + let input: Vec<String> = stdin.lock().lines().map(|line| line.unwrap()).collect(); + + for l in &input { + println!("{}", l); + } + // if alias not new // do nothing // if alias is new |
