termion/examples/click.rs

36 lines
975 B
Rust
Raw Normal View History

2016-07-23 18:03:03 +01:00
extern crate termion;
use termion::event::{Key, Event, MouseEvent};
2016-07-23 19:41:43 +01:00
use termion::input::{TermRead, MouseTerminal};
2016-07-23 18:03:03 +01:00
use termion::raw::IntoRawMode;
use std::io::{Write, stdout, stdin};
fn main() {
let stdin = stdin();
2016-07-23 19:41:43 +01:00
let mut stdout = MouseTerminal::from(stdout().into_raw_mode().unwrap());
2016-07-23 18:03:03 +01:00
2017-03-24 20:53:05 +00:00
write!(stdout,
"{}{}q to exit. Click, click, click!",
termion::clear::All,
termion::cursor::Goto(1, 1))
.unwrap();
2016-07-23 18:03:03 +01:00
stdout.flush().unwrap();
for c in stdin.events() {
let evt = c.unwrap();
match evt {
Event::Key(Key::Char('q')) => break,
Event::Mouse(me) => {
match me {
MouseEvent::Press(_, x, y) => {
write!(stdout, "{}x", termion::cursor::Goto(x, y)).unwrap();
2017-03-24 20:53:05 +00:00
}
2016-07-23 18:03:03 +01:00
_ => (),
}
}
_ => {}
}
stdout.flush().unwrap();
}
}