diff --git a/examples/color.rs b/examples/color.rs index 6cddc6f..16071be 100644 --- a/examples/color.rs +++ b/examples/color.rs @@ -2,14 +2,9 @@ extern crate termion; use termion::{color, style}; -use std::io; - fn main() { println!("{}Red", color::Fg(color::Red)); - println!("{}Blue", color::Fg(color::Blue)); - println!("{}Blue'n'Bold{}", style::Bold, style::Reset); - println!("{}Just plain italic", style::Italic); } diff --git a/examples/keys.rs b/examples/keys.rs index cda9641..3317a5a 100644 --- a/examples/keys.rs +++ b/examples/keys.rs @@ -1,6 +1,7 @@ extern crate termion; -use termion::input::{TermRead, Key}; +use termion::event::Key; +use termion::input::TermRead; use termion::raw::IntoRawMode; use std::io::{Write, stdout, stdin}; diff --git a/examples/mouse.rs b/examples/mouse.rs index 9d8a598..0c1c595 100644 --- a/examples/mouse.rs +++ b/examples/mouse.rs @@ -1,24 +1,22 @@ extern crate termion; -fn main() { - use termion::{TermRead, TermWrite, IntoRawMode, Key, Event, MouseEvent}; - use std::io::{Write, stdout, stdin}; +use termion::event::{Key, Event, MouseEvent}; +use termion::input::TermRead; +use termion::raw::IntoRawMode; +use std::io::{Write, stdout, stdin}; +fn main() { let stdin = stdin(); let mut stdout = stdout().into_raw_mode().unwrap().with_mouse().unwrap(); - stdout.clear().unwrap(); - stdout.goto(0, 0).unwrap(); - stdout.write(b"q to exit. Type stuff, use alt, click around...").unwrap(); - stdout.flush().unwrap(); + write!(stdout, "{}{}q to exit. Type stuff, use alt, click around...", termion::clear::All, termion::cursor::Goto(1, 1)).unwrap(); - let mut x = 0; - let mut y = 0; + let mut x = 1; + let mut y = 1; for c in stdin.events() { - stdout.goto(5, 5).unwrap(); - stdout.clear_line().unwrap(); let evt = c.unwrap(); + writeln!(stdout, "{:?}{}{}", evt, termion::cursor::Goto(5, 5), termion::clear::CurrentLine).unwrap(); match evt { Event::Key(Key::Char('q')) => break, Event::Mouse(me) => { @@ -32,10 +30,9 @@ fn main() { } _ => {} } - println!("{:?}", evt); - stdout.goto(x, y).unwrap(); + writeln!(stdout, "{:?}{}", evt, termion::cursor::Goto(x, y)).unwrap(); stdout.flush().unwrap(); } - stdout.show_cursor().unwrap(); + write!(stdout, "{}", termion::cursor::Show).unwrap(); } diff --git a/examples/rainbow.rs b/examples/rainbow.rs index 06c2710..03c2282 100644 --- a/examples/rainbow.rs +++ b/examples/rainbow.rs @@ -2,8 +2,9 @@ extern crate termion; +use termion::event::Key; +use termion::input::TermRead; use termion::raw::IntoRawMode; -use termion::input::{TermRead, Key}; use std::io::{Write, stdout, stdin}; fn rainbow(stdout: &mut W, blue: u8) { diff --git a/src/event.rs b/src/event.rs index fde57f4..8d533d9 100644 --- a/src/event.rs +++ b/src/event.rs @@ -1,3 +1,5 @@ +//! Mouse and key events. + use std::io::{Error, ErrorKind}; use std::ascii::AsciiExt; use std::str; @@ -273,6 +275,7 @@ where I: Iterator> } } +#[cfg(test)] #[test] fn test_parse_utf8() { let st = "abcéŷ¤£€ù%323"; diff --git a/src/scroll.rs b/src/scroll.rs index 5bdf4d7..2744507 100644 --- a/src/scroll.rs +++ b/src/scroll.rs @@ -1,3 +1,7 @@ +//! Scrolling. + +use std::fmt; + /// Scroll up. #[derive(Copy, Clone, PartialEq, Eq)] pub struct Up(pub u16);