summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--examples/line-input/error.rs40
-rw-r--r--examples/line-input/main.rs (renamed from src/main.rs)6
-rw-r--r--src/decoding.rs (renamed from src/terminal/decoding.rs)4
-rw-r--r--src/error.rs48
-rw-r--r--src/lib.rs (renamed from src/terminal.rs)4
-rw-r--r--src/prelude.rs4
-rw-r--r--src/result.rs5
-rw-r--r--src/terminal/error.rs45
-rw-r--r--src/terminal/prelude.rs4
9 files changed, 77 insertions, 83 deletions
diff --git a/examples/line-input/error.rs b/examples/line-input/error.rs
new file mode 100644
index 0000000..88e2795
--- /dev/null
+++ b/examples/line-input/error.rs
@@ -0,0 +1,40 @@
+#![forbid(unsafe_code)]
+
+use line_input::error::TerminalError;
+
+pub type Result<T> = std::result::Result<T, Error>;
+
+#[derive(Debug)]
+pub enum Error {
+  IO(std::io::Error),
+  Terminal(TerminalError),
+}
+
+impl std::error::Error for Error { }
+
+impl std::fmt::Display for Error {
+  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),
+    }
+  }
+}
+
+impl From<()> for Error {
+  fn from(_: ()) -> Error {
+    unreachable!()
+  }
+}
+
+impl From<std::io::Error> for Error {
+  fn from(e: std::io::Error) -> Error {
+    Error::IO(e)
+  }
+}
+
+impl From<TerminalError> for Error {
+  fn from(e: TerminalError) -> Error {
+    Error::Terminal(e)
+  }
+}
diff --git a/src/main.rs b/examples/line-input/main.rs
index 9d8ed49..5da00fe 100644
--- a/src/main.rs
+++ b/examples/line-input/main.rs
@@ -1,13 +1,11 @@
 #![forbid(unsafe_code)]
-use crate::result::Result;
-use crate::terminal::{Input, Terminal};
+use crate::error::Result;
+use line_input::{Input, Terminal};
 
 use std::process;
 use tokio::io::{self, AsyncWriteExt};
 
 pub mod error;
-pub mod result;
-pub mod terminal;
 
 
 #[tokio::main]
diff --git a/src/terminal/decoding.rs b/src/decoding.rs
index 018730e..cba4d76 100644
--- a/src/terminal/decoding.rs
+++ b/src/decoding.rs
@@ -1,7 +1,7 @@
 #![forbid(unsafe_code)]
-use crate::terminal::prelude::*;
+use crate::prelude::*;
 
-use crate::terminal::error;
+use crate::error;
 
 use pin_project::pin_project;
 use pin_utils::pin_mut;
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))
 }
+
diff --git a/src/terminal.rs b/src/lib.rs
index 405a719..3bcec63 100644
--- a/src/terminal.rs
+++ b/src/lib.rs
@@ -1,7 +1,7 @@
 #![forbid(unsafe_code)]
-use crate::terminal::prelude::*;
+use crate::prelude::*;
 
-use crate::terminal::decoding::CharBufReader;
+use crate::decoding::CharBufReader;
 
 use nix::sys::termios::{self, Termios};
 use std::os::unix::io::{AsRawFd, RawFd};
diff --git a/src/prelude.rs b/src/prelude.rs
new file mode 100644
index 0000000..87b1f77
--- /dev/null
+++ b/src/prelude.rs
@@ -0,0 +1,4 @@
+#![forbid(unsafe_code)]
+
+pub use crate::error::{Result, TerminalError};
+
diff --git a/src/result.rs b/src/result.rs
deleted file mode 100644
index b757636..0000000
--- a/src/result.rs
+++ /dev/null
@@ -1,5 +0,0 @@
-#![forbid(unsafe_code)]
-
-use crate::error::Error;
-
-pub type Result<T> = std::result::Result<T, Error>;
diff --git a/src/terminal/error.rs b/src/terminal/error.rs
deleted file mode 100644
index 795f973..0000000
--- a/src/terminal/error.rs
+++ /dev/null
@@ -1,45 +0,0 @@
-#![forbid(unsafe_code)]
-
-pub type Result<T> = std::result::Result<T, TerminalError>;
-
-
-#[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))
-}
-
diff --git a/src/terminal/prelude.rs b/src/terminal/prelude.rs
deleted file mode 100644
index bada817..0000000
--- a/src/terminal/prelude.rs
+++ /dev/null
@@ -1,4 +0,0 @@
-#![forbid(unsafe_code)]
-
-pub use crate::terminal::error::{Result, TerminalError};
-