Skip to content

Commit 61ff5ae

Browse files
docs: update docs for focus change event (#784) (#864)
* docs: update docs for focus change event (#784) * docs: update example to include execute command - add space between links
1 parent 080f064 commit 61ff5ae

File tree

1 file changed

+42
-6
lines changed

1 file changed

+42
-6
lines changed

Diff for: src/event.rs

+42-6
Original file line numberDiff line numberDiff line change
@@ -17,20 +17,32 @@
1717
//!
1818
//! **Make sure to enable [raw mode](../terminal/index.html#raw-mode) in order for keyboard events to work properly**
1919
//!
20-
//! ## Mouse Events
20+
//! ## Mouse and Focus Events
2121
//!
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.
2525
//!
2626
//! ## Examples
2727
//!
2828
//! Blocking read:
2929
//!
3030
//! ```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+
//! };
3238
//!
3339
//! fn print_events() -> std::io::Result<()> {
40+
//! execute!(
41+
//! std::io::stdout(),
42+
//! EnableBracketedPaste,
43+
//! EnableFocusChange,
44+
//! EnableMouseCapture
45+
//! )?;
3446
//! loop {
3547
//! // `read()` blocks until an `Event` is available
3648
//! match read()? {
@@ -43,6 +55,12 @@
4355
//! Event::Resize(width, height) => println!("New size {}x{}", width, height),
4456
//! }
4557
//! }
58+
//! execute!(
59+
//! std::io::stdout(),
60+
//! DisableBracketedPaste,
61+
//! DisableFocusChange,
62+
//! DisableMouseCapture
63+
//! )?;
4664
//! Ok(())
4765
//! }
4866
//! ```
@@ -52,9 +70,21 @@
5270
//! ```no_run
5371
//! use std::{time::Duration, io};
5472
//!
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+
//! };
5680
//!
5781
//! fn print_events() -> io::Result<()> {
82+
//! execute!(
83+
//! std::io::stdout(),
84+
//! EnableBracketedPaste,
85+
//! EnableFocusChange,
86+
//! EnableMouseCapture
87+
//! )?;
5888
//! loop {
5989
//! // `poll()` waits for an `Event` for a given time period
6090
//! if poll(Duration::from_millis(500))? {
@@ -73,6 +103,12 @@
73103
//! // Timeout expired and no `Event` is available
74104
//! }
75105
//! }
106+
//! execute!(
107+
//! std::io::stdout(),
108+
//! DisableBracketedPaste,
109+
//! DisableFocusChange,
110+
//! DisableMouseCapture
111+
//! )?;
76112
//! Ok(())
77113
//! }
78114
//! ```

0 commit comments

Comments
 (0)