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

Rendition modes

parent 6f9addc4
No related branches found
No related tags found
No related merge requests found
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();
......
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<usize> {
self.csi(b"?25l")
}
/// Reset the style of the cursor.
fn reset_style(&mut self) -> IoResult<usize> {
/// Reset the rendition mode.
fn reset(&mut self) -> IoResult<usize> {
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<usize> {
self.rendition(mode as u8)
}
}
impl<W: Write> TermControl for W {
......
......@@ -16,3 +16,6 @@ pub use size::termsize;
mod color;
pub use color::Color;
mod mode;
pub use mode::Mode;
/// 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,
}
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