From d4e20a4741a4966fbb0b8162ed7cdf47007ca7b8 Mon Sep 17 00:00:00 2001 From: Joe Wilm Date: Sun, 1 Jan 2017 19:09:27 -0800 Subject: Improve error handling for clipboard actions Previously, these could have crashed alacritty. Now, they simply print an error message in Red to stderr. The Red format wrapper was moved to a central location where both main.rs and the alacritty lib can access it. --- src/util.rs | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) (limited to 'src/util.rs') diff --git a/src/util.rs b/src/util.rs index cd8bc9a1..44f7b3de 100644 --- a/src/util.rs +++ b/src/util.rs @@ -35,6 +35,26 @@ pub fn limit(value: T, min: T, max: T) -> T { cmp::min(cmp::max(value, min), max) } +/// Utilities for writing to the +pub mod fmt { + use std::fmt; + + /// Write a `Display` or `Debug` escaped with Red + pub struct Red(pub T); + + impl fmt::Display for Red { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + write!(f, "\x1b[31m{}\x1b[0m", self.0) + } + } + + impl fmt::Debug for Red { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + write!(f, "\x1b[31m{:?}\x1b[0m", self.0) + } + } +} + #[cfg(test)] mod tests { use super::limit; -- cgit v1.2.3-54-g00ecf