summary refs log tree commit diff
path: root/src/terminal
diff options
context:
space:
mode:
authorIrene Knapp <ireneista@gmail.com>2021-01-16 03:05:28 -0800
committerIrene Knapp <ireneista@gmail.com>2021-01-16 03:05:28 -0800
commit380db764e0c5466f1564045c7da40fdde967612c (patch)
tree1007d0d9501ae1d359a2295289fb9bfd431785dd /src/terminal
parent031c033745060fc2c83db5a2bf63fd1942ad3176 (diff)
put the terminal in raw mode; also add a TerminalError type
Diffstat (limited to 'src/terminal')
-rw-r--r--src/terminal/error.rs31
1 files changed, 31 insertions, 0 deletions
diff --git a/src/terminal/error.rs b/src/terminal/error.rs
new file mode 100644
index 0000000..6666e49
--- /dev/null
+++ b/src/terminal/error.rs
@@ -0,0 +1,31 @@
+#[derive(Clone,Debug,Eq,Hash,Ord,PartialEq,PartialOrd)]
+pub enum TerminalError {
+  Input(String),
+  ModeSetting(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)),
+    }
+  }
+}
+
+
+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))
+}
+