Skip to content

Commit

Permalink
docs: update docs for focus change event (#784) (#864)
Browse files Browse the repository at this point in the history
* docs: update docs for focus change event (#784)

* docs: update example to include execute command

- add space between links
  • Loading branch information
illiteratewriter authored Jun 16, 2024
1 parent 080f064 commit 61ff5ae
Showing 1 changed file with 42 additions and 6 deletions.
48 changes: 42 additions & 6 deletions src/event.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,32 @@
//!
//! **Make sure to enable [raw mode](../terminal/index.html#raw-mode) in order for keyboard events to work properly**
//!
//! ## Mouse Events
//! ## Mouse and Focus Events
//!
//! Mouse events are not enabled by default. You have to enable them with the
//! [`EnableMouseCapture`](struct.EnableMouseCapture.html) command. See [Command API](../index.html#command-api)
//! for more information.
//! Mouse and focus events are not enabled by default. You have to enable them with the
//! [`EnableMouseCapture`](struct.EnableMouseCapture.html) / [`EnableFocusChange`](struct.EnableFocusChange.html) command.
//! See [Command API](../index.html#command-api) for more information.
//!
//! ## Examples
//!
//! Blocking read:
//!
//! ```no_run
//! use crossterm::event::{read, Event};
//! use crossterm::{
//! event::{
//! read, DisableBracketedPaste, DisableFocusChange, DisableMouseCapture, EnableBracketedPaste,
//! EnableFocusChange, EnableMouseCapture, Event,
//! },
//! execute,
//! };
//!
//! fn print_events() -> std::io::Result<()> {
//! execute!(
//! std::io::stdout(),
//! EnableBracketedPaste,
//! EnableFocusChange,
//! EnableMouseCapture
//! )?;
//! loop {
//! // `read()` blocks until an `Event` is available
//! match read()? {
Expand All @@ -43,6 +55,12 @@
//! Event::Resize(width, height) => println!("New size {}x{}", width, height),
//! }
//! }
//! execute!(
//! std::io::stdout(),
//! DisableBracketedPaste,
//! DisableFocusChange,
//! DisableMouseCapture
//! )?;
//! Ok(())
//! }
//! ```
Expand All @@ -52,9 +70,21 @@
//! ```no_run
//! use std::{time::Duration, io};
//!
//! use crossterm::event::{poll, read, Event};
//! use crossterm::{
//! event::{
//! poll, read, DisableBracketedPaste, DisableFocusChange, DisableMouseCapture,
//! EnableBracketedPaste, EnableFocusChange, EnableMouseCapture, Event,
//! },
//! execute,
//! };
//!
//! fn print_events() -> io::Result<()> {
//! execute!(
//! std::io::stdout(),
//! EnableBracketedPaste,
//! EnableFocusChange,
//! EnableMouseCapture
//! )?;
//! loop {
//! // `poll()` waits for an `Event` for a given time period
//! if poll(Duration::from_millis(500))? {
Expand All @@ -73,6 +103,12 @@
//! // Timeout expired and no `Event` is available
//! }
//! }
//! execute!(
//! std::io::stdout(),
//! DisableBracketedPaste,
//! DisableFocusChange,
//! DisableMouseCapture
//! )?;
//! Ok(())
//! }
//! ```
Expand Down

0 comments on commit 61ff5ae

Please sign in to comment.