|
17 | 17 | //!
|
18 | 18 | //! **Make sure to enable [raw mode](../terminal/index.html#raw-mode) in order for keyboard events to work properly**
|
19 | 19 | //!
|
20 |
| -//! ## Mouse Events |
| 20 | +//! ## Mouse and Focus Events |
21 | 21 | //!
|
22 |
| -//! Mouse events are not enabled by default. You have to enable them with the |
23 |
| -//! [`EnableMouseCapture`](struct.EnableMouseCapture.html) command. See [Command API](../index.html#command-api) |
24 |
| -//! for more information. |
| 22 | +//! Mouse and focus events are not enabled by default. You have to enable them with the |
| 23 | +//! [`EnableMouseCapture`](struct.EnableMouseCapture.html) / [`EnableFocusChange`](struct.EnableFocusChange.html) command. |
| 24 | +//! See [Command API](../index.html#command-api) for more information. |
25 | 25 | //!
|
26 | 26 | //! ## Examples
|
27 | 27 | //!
|
28 | 28 | //! Blocking read:
|
29 | 29 | //!
|
30 | 30 | //! ```no_run
|
31 |
| -//! use crossterm::event::{read, Event}; |
| 31 | +//! use crossterm::{ |
| 32 | +//! event::{ |
| 33 | +//! read, DisableBracketedPaste, DisableFocusChange, DisableMouseCapture, EnableBracketedPaste, |
| 34 | +//! EnableFocusChange, EnableMouseCapture, Event, |
| 35 | +//! }, |
| 36 | +//! execute, |
| 37 | +//! }; |
32 | 38 | //!
|
33 | 39 | //! fn print_events() -> std::io::Result<()> {
|
| 40 | +//! execute!( |
| 41 | +//! std::io::stdout(), |
| 42 | +//! EnableBracketedPaste, |
| 43 | +//! EnableFocusChange, |
| 44 | +//! EnableMouseCapture |
| 45 | +//! )?; |
34 | 46 | //! loop {
|
35 | 47 | //! // `read()` blocks until an `Event` is available
|
36 | 48 | //! match read()? {
|
|
43 | 55 | //! Event::Resize(width, height) => println!("New size {}x{}", width, height),
|
44 | 56 | //! }
|
45 | 57 | //! }
|
| 58 | +//! execute!( |
| 59 | +//! std::io::stdout(), |
| 60 | +//! DisableBracketedPaste, |
| 61 | +//! DisableFocusChange, |
| 62 | +//! DisableMouseCapture |
| 63 | +//! )?; |
46 | 64 | //! Ok(())
|
47 | 65 | //! }
|
48 | 66 | //! ```
|
|
52 | 70 | //! ```no_run
|
53 | 71 | //! use std::{time::Duration, io};
|
54 | 72 | //!
|
55 |
| -//! use crossterm::event::{poll, read, Event}; |
| 73 | +//! use crossterm::{ |
| 74 | +//! event::{ |
| 75 | +//! poll, read, DisableBracketedPaste, DisableFocusChange, DisableMouseCapture, |
| 76 | +//! EnableBracketedPaste, EnableFocusChange, EnableMouseCapture, Event, |
| 77 | +//! }, |
| 78 | +//! execute, |
| 79 | +//! }; |
56 | 80 | //!
|
57 | 81 | //! fn print_events() -> io::Result<()> {
|
| 82 | +//! execute!( |
| 83 | +//! std::io::stdout(), |
| 84 | +//! EnableBracketedPaste, |
| 85 | +//! EnableFocusChange, |
| 86 | +//! EnableMouseCapture |
| 87 | +//! )?; |
58 | 88 | //! loop {
|
59 | 89 | //! // `poll()` waits for an `Event` for a given time period
|
60 | 90 | //! if poll(Duration::from_millis(500))? {
|
|
73 | 103 | //! // Timeout expired and no `Event` is available
|
74 | 104 | //! }
|
75 | 105 | //! }
|
| 106 | +//! execute!( |
| 107 | +//! std::io::stdout(), |
| 108 | +//! DisableBracketedPaste, |
| 109 | +//! DisableFocusChange, |
| 110 | +//! DisableMouseCapture |
| 111 | +//! )?; |
76 | 112 | //! Ok(())
|
77 | 113 | //! }
|
78 | 114 | //! ```
|
|
0 commit comments