#![forbid(unsafe_code)] pub type Result = std::result::Result; #[derive(Clone,Debug,Eq,Hash,Ord,PartialEq,PartialOrd)] pub enum TerminalError { Input(String), ModeSetting(String), Internal(String), } impl std::error::Error for TerminalError { } impl std::fmt::Display for TerminalError { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { match self { TerminalError::Input(s) => f.write_fmt(format_args!( "Can't read terminal input: {}", s)), TerminalError::ModeSetting(s) => f.write_fmt(format_args!( "Can't set terminal mode: {}", s)), TerminalError::Internal(s) => f.write_fmt(format_args!( "Internal error regarding the terminal: {}", s)), } } } pub fn input(e: impl std::error::Error) -> TerminalError { TerminalError::ModeSetting(format!("{}", e)) } pub fn mode_setting(e: impl std::error::Error) -> TerminalError { TerminalError::ModeSetting(format!("{}", e)) } pub fn internal(e: impl std::error::Error) -> TerminalError { TerminalError::Internal(format!("{}", e)) }