Fix examples & merge

This commit is contained in:
ticki 2016-07-23 18:50:33 +02:00
parent 5b94db9663
commit 30afb4c32e
6 changed files with 22 additions and 21 deletions

View File

@ -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);
}

View File

@ -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};

View File

@ -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();
}

View File

@ -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<W: Write>(stdout: &mut W, blue: u8) {

View File

@ -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<Item = Result<u8, Error>>
}
}
#[cfg(test)]
#[test]
fn test_parse_utf8() {
let st = "abcéŷ¤£€ù%323";

View File

@ -1,3 +1,7 @@
//! Scrolling.
use std::fmt;
/// Scroll up.
#[derive(Copy, Clone, PartialEq, Eq)]
pub struct Up(pub u16);