Rename WriteExt to TermWrite

This commit is contained in:
Ticki 2016-03-08 21:39:24 +01:00
parent 62940e52f0
commit a16cc84ea3
4 changed files with 13 additions and 10 deletions

View File

@ -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() {

View File

@ -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<usize>;
@ -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> {
self.write(b"\x1B[").and_then(|x| {
self.write(b).map(|y| x + y)

View File

@ -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<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> {
let _raw = try!(writer.into_raw_mode());
let mut passbuf = Vec::with_capacity(30);

View File

@ -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;