summary refs log tree commit diff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-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/main.rs65
-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
8 files changed, 35 insertions, 144 deletions
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/main.rs b/src/main.rs
deleted file mode 100644
index 9d8ed49..0000000
--- a/src/main.rs
+++ /dev/null
@@ -1,65 +0,0 @@
-#![forbid(unsafe_code)]
-use crate::result::Result;
-use crate::terminal::{Input, Terminal};
-
-use std::process;
-use tokio::io::{self, AsyncWriteExt};
-
-pub mod error;
-pub mod result;
-pub mod terminal;
-
-
-#[tokio::main]
-async fn main() -> Result<()> {
-  let result = repl().await;
-  process::exit(match result {
-    Ok(()) => 0,
-    Err(ref e) => {
-      eprintln!("{}", e);
-      1
-    }
-  })
-}
-
-
-async fn repl() -> Result<()> {
-  println!("Hello, terminal!");
-
-  let mut terminal = Terminal::init(io::stdin())?;
-
-  loop {
-    prompt().await?;
-
-    let input = terminal.handle_input().await?;
-
-    match input {
-      Input::String(string) => {
-        println!("{:?} {}", string, string.len());
-        execute(&string).await?
-      },
-      Input::End => break,
-    }
-
-    break;
-  }
-
-  terminal.cleanup()?;
-
-  Ok(())
-}
-
-
-async fn prompt() -> Result<()> {
-  let mut stdout = io::stdout();
-  stdout.write_all("\n$ ".as_bytes()).await?;
-  stdout.flush().await?;
-
-  Ok(())
-}
-
-
-async fn execute(_input: &str) -> Result<()> {
-  Ok(())
-}
-
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};
-