summary refs log tree commit diff
path: root/src/error.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/error.rs')
-rw-r--r--src/error.rs48
1 files changed, 27 insertions, 21 deletions
diff --git a/src/error.rs b/src/error.rs
index 426ebf5..795f973 100644
--- a/src/error.rs
+++ b/src/error.rs
@@ -1,39 +1,45 @@
 #![forbid(unsafe_code)]
 
-use crate::terminal::error::TerminalError;
+pub type Result<T> = std::result::Result<T, TerminalError>;
 
 
-#[derive(Debug)]
-pub enum Error {
-  IO(std::io::Error),
-  Terminal(TerminalError),
+#[derive(Clone,Debug,Eq,Hash,Ord,PartialEq,PartialOrd)]
+pub enum TerminalError {
+  Input(String),
+  ModeSetting(String),
+  Internal(String),
 }
 
-impl std::error::Error for Error { }
+impl std::error::Error for TerminalError { }
 
-impl std::fmt::Display for Error {
+impl std::fmt::Display for TerminalError {
   fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
     match self {
-      Error::IO(e) => e.fmt(f),
-      Error::Terminal(e) => e.fmt(f),
+      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)),
     }
   }
 }
 
-impl From<()> for Error {
-  fn from(_: ()) -> Error {
-    unreachable!()
-  }
+
+pub fn input(e: impl std::error::Error) -> TerminalError {
+  TerminalError::ModeSetting(format!("{}", e))
 }
 
-impl From<std::io::Error> for Error {
-  fn from(e: std::io::Error) -> Error {
-    Error::IO(e)
-  }
+
+pub fn mode_setting(e: impl std::error::Error) -> TerminalError {
+  TerminalError::ModeSetting(format!("{}", e))
 }
 
-impl From<TerminalError> for Error {
-  fn from(e: TerminalError) -> Error {
-    Error::Terminal(e)
-  }
+
+pub fn internal(e: impl std::error::Error) -> TerminalError {
+  TerminalError::Internal(format!("{}", e))
 }
+