diff options
author | Jesse Luehrs <doy@tozt.net> | 2018-05-14 17:57:40 -0400 |
---|---|---|
committer | Jesse Luehrs <doy@tozt.net> | 2018-05-14 17:57:40 -0400 |
commit | e28033a794f70f0051c5d47651da90830dd6d1ad (patch) | |
tree | 0db7fd966f493460bc02ce5867a63d5ddd37c90a | |
parent | b9c09de9f20b78601710470e12d798b8656d8d00 (diff) | |
download | fancy-prompt-e28033a794f70f0051c5d47651da90830dd6d1ad.tar.gz fancy-prompt-e28033a794f70f0051c5d47651da90830dd6d1ad.zip |
create terminal objects directly from a writer
-rw-r--r-- | src/colors.rs | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/src/colors.rs b/src/colors.rs index 15155cc..ab5e179 100644 --- a/src/colors.rs +++ b/src/colors.rs @@ -1,6 +1,8 @@ use std; use term; +use std::io::Write; + #[derive(Debug, Clone)] pub enum ShellType { Unknown, @@ -129,9 +131,16 @@ impl Colors { color: Option<&term::color::Color>, text: &str, ) { - let mut t = term::stdout().unwrap(); - self.print_color(&mut *t, color); + let mut t = term::TerminfoTerminal::new(std::io::stdout()).unwrap(); + self.print_color(&mut t, color); write!(t, "{}", text).unwrap(); + self.print_reset(&mut t); + } + + fn print_reset<W: std::io::Write>( + &self, + t: &mut term::Terminal<Output=W>, + ) { self.print_wrapped(|| { t.reset().unwrap(); }) |