Skip to content
Snippets Groups Projects
Commit 8ccc67cf authored by ticki's avatar ticki
Browse files

Update the mouse example.

We use click and drag.
parent 44c84792
No related branches found
No related tags found
No related merge requests found
extern crate termion; extern crate termion;
use termion::event::{Key, Event, MouseEvent}; use termion::event::*;
use termion::cursor;
use termion::input::{TermRead, MouseTerminal}; use termion::input::{TermRead, MouseTerminal};
use termion::raw::IntoRawMode; use termion::raw::IntoRawMode;
use std::io::{Write, stdout, stdin}; use std::io::{self, Write};
fn main() { fn main() {
let stdin = stdin(); let stdin = io::stdin();
let mut stdout = MouseTerminal::from(stdout().into_raw_mode().unwrap()); let mut stdout = MouseTerminal::from(io::stdout().into_raw_mode().unwrap());
writeln!(stdout, writeln!(stdout,
"{}{}q to exit. Type stuff, use alt, click around...", "{}{}q to exit. Type stuff, use alt, click around...",
...@@ -15,9 +16,6 @@ fn main() { ...@@ -15,9 +16,6 @@ fn main() {
termion::cursor::Goto(1, 1)) termion::cursor::Goto(1, 1))
.unwrap(); .unwrap();
let mut x = 5;
let mut y = 5;
for c in stdin.events() { for c in stdin.events() {
let evt = c.unwrap(); let evt = c.unwrap();
match evt { match evt {
...@@ -27,22 +25,13 @@ fn main() { ...@@ -27,22 +25,13 @@ fn main() {
MouseEvent::Press(_, a, b) | MouseEvent::Press(_, a, b) |
MouseEvent::Release(a, b) | MouseEvent::Release(a, b) |
MouseEvent::Hold(a, b) => { MouseEvent::Hold(a, b) => {
x = a; write!(stdout, "{}", cursor::Goto(a, b)).unwrap();
y = b;
} }
} }
} }
_ => {} _ => {}
} }
write!(stdout,
"{}{} {:?}{}",
termion::clear::All,
termion::cursor::Goto(x, y),
evt,
termion::cursor::Goto(x, y))
.unwrap();
stdout.flush().unwrap(); stdout.flush().unwrap();
} }
write!(stdout, "{}", termion::cursor::Show).unwrap();
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment