Rename WriteExt to TermWrite
This commit is contained in:
parent
62940e52f0
commit
a16cc84ea3
|
@ -1,6 +1,6 @@
|
||||||
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() {
|
||||||
|
|
|
@ -1,8 +1,11 @@
|
||||||
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 {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
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};
|
||||||
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 {
|
||||||
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;
|
||||||
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;
|
||||||
|
|
||||||
mod style;
|
mod style;
|
||||||
pub use style::Style;
|
pub use style::Style;
|
||||||
|
|
||||||
mod extra;
|
|
||||||
pub use extra::ReadExt;
|
|
||||||
|
|
Loading…
Reference in New Issue