diff --git a/examples/simple.rs b/examples/simple.rs index ce8e107..3991cd3 100644 --- a/examples/simple.rs +++ b/examples/simple.rs @@ -1,6 +1,6 @@ extern crate libterm; -use libterm::{TermControl, IntoRawMode, Color, Style}; +use libterm::{WriteExt, IntoRawMode, Color, Style}; use std::io::{Read, Write, stdout, stdin}; fn main() { diff --git a/src/control.rs b/src/control.rs index d8a6724..59b4d8b 100644 --- a/src/control.rs +++ b/src/control.rs @@ -1,8 +1,11 @@ use std::io::{Write, Result as IoResult}; use {Color, Style}; -/// Controlling terminals. -pub trait TermControl { +/// Extension to the `Write` trait. +/// +/// This extension to the `Write` trait is capable of producing the correct ANSI escape sequences +/// for given commands, effectively controlling the terminal. +pub trait TermWrite { /// Print the CSI (control sequence introducer) followed by a byte string. fn csi(&mut self, b: &[u8]) -> IoResult; @@ -111,7 +114,7 @@ pub trait TermControl { } } -impl TermControl for W { +impl TermWrite for W { fn csi(&mut self, b: &[u8]) -> IoResult { self.write(b"\x1B[").and_then(|x| { self.write(b).map(|y| x + y) diff --git a/src/extra.rs b/src/input.rs similarity index 94% rename from src/extra.rs rename to src/input.rs index d638580..44ad69f 100644 --- a/src/extra.rs +++ b/src/input.rs @@ -2,7 +2,7 @@ use std::io::{Read, Write}; use {IntoRawMode, TerminalError}; /// Extension to `Read` trait. -pub trait ReadExt { +pub trait TermRead { /// Read a password. /// /// EOT and ETX will abort the prompt, returning `None`. Newline or carriage return will @@ -10,7 +10,7 @@ pub trait ReadExt { fn read_passwd(&mut self, writer: &mut W) -> Result, TerminalError>; } -impl ReadExt for R { +impl TermRead for R { fn read_passwd(&mut self, writer: &mut W) -> Result, TerminalError> { let _raw = try!(writer.into_raw_mode()); let mut passbuf = Vec::with_capacity(30); diff --git a/src/lib.rs b/src/lib.rs index ae7451e..0ad5bf7 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -7,7 +7,10 @@ extern crate libc; mod termios; mod control; -pub use control::TermControl; +pub use control::WriteExt; + +mod input; +pub use input::ReadExt; mod error; pub use error::TerminalError; @@ -23,6 +26,3 @@ pub use color::Color; mod style; pub use style::Style; - -mod extra; -pub use extra::ReadExt;