2016-07-20 00:00:22 +01:00
|
|
|
extern crate termion;
|
|
|
|
|
2016-10-26 10:55:47 +01:00
|
|
|
use termion::event::*;
|
2017-03-12 20:18:32 +00:00
|
|
|
use termion::cursor::{self, DetectCursorPos};
|
2016-07-23 19:41:43 +01:00
|
|
|
use termion::input::{TermRead, MouseTerminal};
|
2016-07-23 17:50:33 +01:00
|
|
|
use termion::raw::IntoRawMode;
|
2016-10-26 10:55:47 +01:00
|
|
|
use std::io::{self, Write};
|
2016-07-20 00:00:22 +01:00
|
|
|
|
2016-07-23 17:50:33 +01:00
|
|
|
fn main() {
|
2016-10-26 10:55:47 +01:00
|
|
|
let stdin = io::stdin();
|
|
|
|
let mut stdout = MouseTerminal::from(io::stdout().into_raw_mode().unwrap());
|
2016-07-20 00:00:22 +01:00
|
|
|
|
2016-09-07 10:05:41 +01:00
|
|
|
writeln!(stdout,
|
|
|
|
"{}{}q to exit. Type stuff, use alt, click around...",
|
|
|
|
termion::clear::All,
|
|
|
|
termion::cursor::Goto(1, 1))
|
|
|
|
.unwrap();
|
2016-07-20 00:00:22 +01:00
|
|
|
|
|
|
|
for c in stdin.events() {
|
|
|
|
let evt = c.unwrap();
|
|
|
|
match evt {
|
|
|
|
Event::Key(Key::Char('q')) => break,
|
|
|
|
Event::Mouse(me) => {
|
|
|
|
match me {
|
|
|
|
MouseEvent::Press(_, a, b) |
|
2016-09-07 10:05:41 +01:00
|
|
|
MouseEvent::Release(a, b) |
|
|
|
|
MouseEvent::Hold(a, b) => {
|
2016-10-26 10:55:47 +01:00
|
|
|
write!(stdout, "{}", cursor::Goto(a, b)).unwrap();
|
2017-03-12 20:18:32 +00:00
|
|
|
let (x, y) = stdout.cursor_pos().unwrap();
|
|
|
|
write!(stdout,
|
|
|
|
"{}{}Cursor is at: ({},{}){}",
|
|
|
|
cursor::Goto(5, 5),
|
|
|
|
termion::clear::UntilNewline,
|
|
|
|
x,
|
|
|
|
y,
|
|
|
|
cursor::Goto(a, b)).unwrap();
|
2016-07-20 00:00:22 +01:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
_ => {}
|
|
|
|
}
|
2016-10-26 10:55:47 +01:00
|
|
|
|
2016-07-20 00:00:22 +01:00
|
|
|
stdout.flush().unwrap();
|
|
|
|
}
|
|
|
|
}
|