Update readme

This commit is contained in:
ticki 2016-06-14 14:29:31 +02:00
parent 49bb0932c7
commit 8bcb946b07
3 changed files with 18 additions and 1 deletions

View File

@ -16,6 +16,7 @@ Features
-------- --------
- Raw mode. - Raw mode.
- 256-color mode.
- Cursor movement. - Cursor movement.
- Color output. - Color output.
- Text formatting. - Text formatting.
@ -24,9 +25,9 @@ Features
- Termios control. - Termios control.
- Password input. - Password input.
- Redox support. - Redox support.
- 256-color mode.
- Panic-free error handling. - Panic-free error handling.
- Special keys events (modifiers, special keys, etc.). - Special keys events (modifiers, special keys, etc.).
- Allocation-free.
- Asynchronous key events. - Asynchronous key events.
and much more. and much more.

View File

@ -19,30 +19,37 @@ pub trait TermWrite {
fn clear(&mut self) -> io::Result<usize> { fn clear(&mut self) -> io::Result<usize> {
self.csi(b"2J") self.csi(b"2J")
} }
/// Clear everything _after_ the cursor. /// Clear everything _after_ the cursor.
fn clear_after(&mut self) -> io::Result<usize> { fn clear_after(&mut self) -> io::Result<usize> {
self.csi(b"J") self.csi(b"J")
} }
/// Clear everything _before_ the cursor. /// Clear everything _before_ the cursor.
fn clear_before(&mut self) -> io::Result<usize> { fn clear_before(&mut self) -> io::Result<usize> {
self.csi(b"1J") self.csi(b"1J")
} }
/// Clear the current line. /// Clear the current line.
fn clear_line(&mut self) -> io::Result<usize> { fn clear_line(&mut self) -> io::Result<usize> {
self.csi(b"2K") self.csi(b"2K")
} }
/// Clear from the cursor until newline. /// Clear from the cursor until newline.
fn clear_until_newline(&mut self) -> io::Result<usize> { fn clear_until_newline(&mut self) -> io::Result<usize> {
self.csi(b"K") self.csi(b"K")
} }
/// Show the cursor. /// Show the cursor.
fn show_cursor(&mut self) -> io::Result<usize> { fn show_cursor(&mut self) -> io::Result<usize> {
self.csi(b"?25h") self.csi(b"?25h")
} }
/// Hide the cursor. /// Hide the cursor.
fn hide_cursor(&mut self) -> io::Result<usize> { fn hide_cursor(&mut self) -> io::Result<usize> {
self.csi(b"?25l") self.csi(b"?25l")
} }
/// Move the cursor `num` spaces to the left. /// Move the cursor `num` spaces to the left.
fn move_cursor_left(&mut self, num: u32) -> io::Result<usize> { fn move_cursor_left(&mut self, num: u32) -> io::Result<usize> {
if num > 0 { if num > 0 {
@ -80,6 +87,7 @@ pub trait TermWrite {
fn reset(&mut self) -> io::Result<usize> { fn reset(&mut self) -> io::Result<usize> {
self.csi(b"m") self.csi(b"m")
} }
/// Restore the defaults. /// Restore the defaults.
/// ///
/// This will reset color, position, cursor state, and so on. It is recommended that you use /// This will reset color, position, cursor state, and so on. It is recommended that you use
@ -110,6 +118,7 @@ pub trait TermWrite {
b'H', b'H',
]) ])
} }
/// Set graphic rendition. /// Set graphic rendition.
fn rendition(&mut self, r: u8) -> io::Result<usize> { fn rendition(&mut self, r: u8) -> io::Result<usize> {
self.csi(&[ self.csi(&[
@ -119,6 +128,7 @@ pub trait TermWrite {
b'm', b'm',
]) ])
} }
/// Set foreground color. /// Set foreground color.
fn color(&mut self, color: Color) -> io::Result<usize> { fn color(&mut self, color: Color) -> io::Result<usize> {
let ansi = color.to_ansi_val(); let ansi = color.to_ansi_val();
@ -134,6 +144,7 @@ pub trait TermWrite {
b'm', b'm',
]) ])
} }
/// Set background color. /// Set background color.
fn bg_color(&mut self, color: Color) -> io::Result<usize> { fn bg_color(&mut self, color: Color) -> io::Result<usize> {
let ansi = color.to_ansi_val(); let ansi = color.to_ansi_val();
@ -149,6 +160,7 @@ pub trait TermWrite {
b'm', b'm',
]) ])
} }
/// Set rendition mode (SGR). /// Set rendition mode (SGR).
fn style(&mut self, mode: Style) -> io::Result<usize> { fn style(&mut self, mode: Style) -> io::Result<usize> {
self.rendition(mode as u8) self.rendition(mode as u8)
@ -159,9 +171,11 @@ impl<W: Write> TermWrite for W {
fn csi(&mut self, b: &[u8]) -> io::Result<usize> { fn csi(&mut self, b: &[u8]) -> io::Result<usize> {
Ok(try!(self.write(b"\x1B[")) + try!(self.write(b))) Ok(try!(self.write(b"\x1B[")) + try!(self.write(b)))
} }
fn osc(&mut self, b: &[u8]) -> io::Result<usize> { fn osc(&mut self, b: &[u8]) -> io::Result<usize> {
Ok(try!(self.write(b"\x1B]")) + try!(self.write(b))) Ok(try!(self.write(b"\x1B]")) + try!(self.write(b)))
} }
fn dsc(&mut self, b: &[u8]) -> io::Result<usize> { fn dsc(&mut self, b: &[u8]) -> io::Result<usize> {
Ok(try!(self.write(b"\x1BP")) + try!(self.write(b))) Ok(try!(self.write(b"\x1BP")) + try!(self.write(b)))
} }

View File

@ -41,6 +41,7 @@ impl<W: Write> Deref for RawTerminal<W> {
&self.output &self.output
} }
} }
impl<W: Write> DerefMut for RawTerminal<W> { impl<W: Write> DerefMut for RawTerminal<W> {
fn deref_mut(&mut self) -> &mut W { fn deref_mut(&mut self) -> &mut W {
&mut self.output &mut self.output
@ -91,6 +92,7 @@ impl<W: Write> IntoRawMode for W {
}) })
} }
} }
#[cfg(target_os = "redox")] #[cfg(target_os = "redox")]
fn into_raw_mode(mut self) -> io::Result<RawTerminal<W>> { fn into_raw_mode(mut self) -> io::Result<RawTerminal<W>> {
use control::TermWrite; use control::TermWrite;