Skip to content
Snippets Groups Projects
Commit a16cc84e authored by Ticki's avatar Ticki
Browse files

Rename WriteExt to TermWrite

parent 62940e52
No related branches found
No related tags found
No related merge requests found
extern crate libterm; extern crate libterm;
use libterm::{TermControl, IntoRawMode, Color, Style}; use libterm::{WriteExt, IntoRawMode, Color, Style};
use std::io::{Read, Write, stdout, stdin}; use std::io::{Read, Write, stdout, stdin};
fn main() { fn main() {
......
use std::io::{Write, Result as IoResult}; use std::io::{Write, Result as IoResult};
use {Color, Style}; use {Color, Style};
/// Controlling terminals. /// Extension to the `Write` trait.
pub trait TermControl { ///
/// 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. /// Print the CSI (control sequence introducer) followed by a byte string.
fn csi(&mut self, b: &[u8]) -> IoResult<usize>; fn csi(&mut self, b: &[u8]) -> IoResult<usize>;
...@@ -111,7 +114,7 @@ pub trait TermControl { ...@@ -111,7 +114,7 @@ pub trait TermControl {
} }
} }
impl<W: Write> TermControl for W { impl<W: Write> TermWrite for W {
fn csi(&mut self, b: &[u8]) -> IoResult<usize> { fn csi(&mut self, b: &[u8]) -> IoResult<usize> {
self.write(b"\x1B[").and_then(|x| { self.write(b"\x1B[").and_then(|x| {
self.write(b).map(|y| x + y) self.write(b).map(|y| x + y)
......
...@@ -2,7 +2,7 @@ use std::io::{Read, Write}; ...@@ -2,7 +2,7 @@ use std::io::{Read, Write};
use {IntoRawMode, TerminalError}; use {IntoRawMode, TerminalError};
/// Extension to `Read` trait. /// Extension to `Read` trait.
pub trait ReadExt { pub trait TermRead {
/// Read a password. /// Read a password.
/// ///
/// EOT and ETX will abort the prompt, returning `None`. Newline or carriage return will /// EOT and ETX will abort the prompt, returning `None`. Newline or carriage return will
...@@ -10,7 +10,7 @@ pub trait ReadExt { ...@@ -10,7 +10,7 @@ pub trait ReadExt {
fn read_passwd<W: Write>(&mut self, writer: &mut W) -> Result<Option<String>, TerminalError>; fn read_passwd<W: Write>(&mut self, writer: &mut W) -> Result<Option<String>, TerminalError>;
} }
impl<R: Read> ReadExt for R { impl<R: Read> TermRead for R {
fn read_passwd<W: Write>(&mut self, writer: &mut W) -> Result<Option<String>, TerminalError> { fn read_passwd<W: Write>(&mut self, writer: &mut W) -> Result<Option<String>, TerminalError> {
let _raw = try!(writer.into_raw_mode()); let _raw = try!(writer.into_raw_mode());
let mut passbuf = Vec::with_capacity(30); let mut passbuf = Vec::with_capacity(30);
......
...@@ -7,7 +7,10 @@ extern crate libc; ...@@ -7,7 +7,10 @@ extern crate libc;
mod termios; mod termios;
mod control; mod control;
pub use control::TermControl; pub use control::WriteExt;
mod input;
pub use input::ReadExt;
mod error; mod error;
pub use error::TerminalError; pub use error::TerminalError;
...@@ -23,6 +26,3 @@ pub use color::Color; ...@@ -23,6 +26,3 @@ pub use color::Color;
mod style; mod style;
pub use style::Style; pub use style::Style;
mod extra;
pub use extra::ReadExt;
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment