diff --git a/examples/simple.rs b/examples/simple.rs index f7f893f..2b0d798 100644 --- a/examples/simple.rs +++ b/examples/simple.rs @@ -1,6 +1,6 @@ extern crate libterm; -use libterm::{TermControl, raw_mode, Color}; +use libterm::{TermControl, raw_mode, Color, Mode}; use std::io::{Read, Write, stdout, stdin}; fn main() { @@ -10,7 +10,9 @@ fn main() { stdout.goto(5, 5).unwrap(); stdout.clear().unwrap(); + stdout.mode(Mode::Bold).unwrap(); stdout.write(b"yo, 'q' will exit.").unwrap(); + stdout.reset().unwrap(); stdout.flush().unwrap(); stdout.goto(20, 10).unwrap(); diff --git a/src/control.rs b/src/control.rs index 246e32d..65f9d3c 100644 --- a/src/control.rs +++ b/src/control.rs @@ -1,5 +1,5 @@ use std::io::{Write, Result as IoResult}; -use Color; +use {Color, Mode}; /// Controlling terminals. pub trait TermControl { @@ -21,8 +21,8 @@ pub trait TermControl { fn hide(&mut self) -> IoResult { self.csi(b"?25l") } - /// Reset the style of the cursor. - fn reset_style(&mut self) -> IoResult { + /// Reset the rendition mode. + fn reset(&mut self) -> IoResult { self.csi(b"m") } /// Go to a given position. @@ -71,6 +71,10 @@ pub trait TermControl { b'm', ]) } + /// Set rendition mode (SGR). + fn mode(&mut self, mode: Mode) -> IoResult { + self.rendition(mode as u8) + } } impl TermControl for W { diff --git a/src/lib.rs b/src/lib.rs index c4bf259..34b2da9 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -16,3 +16,6 @@ pub use size::termsize; mod color; pub use color::Color; + +mod mode; +pub use mode::Mode; diff --git a/src/mode.rs b/src/mode.rs new file mode 100644 index 0000000..38faad6 --- /dev/null +++ b/src/mode.rs @@ -0,0 +1,21 @@ +/// A SGR parameter (rendition mode). +pub enum Mode { + /// Reset SGR parameters. + Reset = 0, + /// Bold text. + Bold = 1, + /// Fainted text (not widely supported). + Faint = 2, + /// Italic text. + Italic = 3, + /// Underlined text. + Underline = 4, + /// Blinking text (not widely supported). + Blink = 5, + /// Inverted colors (negative mode). + Invert = 7, + /// Crossed out text (not widely supported). + CrossedOut = 9, + /// Framed text (not widely supported). + Framed = 51, +}