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
This commit is contained in:
illiteratewriter 2024-06-16 18:30:25 +05:30 committed by GitHub
parent 080f06494a
commit 61ff5ae1ce
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -17,20 +17,32 @@
//! //!
//! **Make sure to enable [raw mode](../terminal/index.html#raw-mode) in order for keyboard events to work properly** //! **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 //! Mouse and focus 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) //! [`EnableMouseCapture`](struct.EnableMouseCapture.html) / [`EnableFocusChange`](struct.EnableFocusChange.html) command.
//! for more information. //! See [Command API](../index.html#command-api) for more information.
//! //!
//! ## Examples //! ## Examples
//! //!
//! Blocking read: //! Blocking read:
//! //!
//! ```no_run //! ```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<()> { //! fn print_events() -> std::io::Result<()> {
//! execute!(
//! std::io::stdout(),
//! EnableBracketedPaste,
//! EnableFocusChange,
//! EnableMouseCapture
//! )?;
//! loop { //! loop {
//! // `read()` blocks until an `Event` is available //! // `read()` blocks until an `Event` is available
//! match read()? { //! match read()? {
@ -43,6 +55,12 @@
//! Event::Resize(width, height) => println!("New size {}x{}", width, height), //! Event::Resize(width, height) => println!("New size {}x{}", width, height),
//! } //! }
//! } //! }
//! execute!(
//! std::io::stdout(),
//! DisableBracketedPaste,
//! DisableFocusChange,
//! DisableMouseCapture
//! )?;
//! Ok(()) //! Ok(())
//! } //! }
//! ``` //! ```
@ -52,9 +70,21 @@
//! ```no_run //! ```no_run
//! use std::{time::Duration, io}; //! 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<()> { //! fn print_events() -> io::Result<()> {
//! execute!(
//! std::io::stdout(),
//! EnableBracketedPaste,
//! EnableFocusChange,
//! EnableMouseCapture
//! )?;
//! loop { //! loop {
//! // `poll()` waits for an `Event` for a given time period //! // `poll()` waits for an `Event` for a given time period
//! if poll(Duration::from_millis(500))? { //! if poll(Duration::from_millis(500))? {
@ -73,6 +103,12 @@
//! // Timeout expired and no `Event` is available //! // Timeout expired and no `Event` is available
//! } //! }
//! } //! }
//! execute!(
//! std::io::stdout(),
//! DisableBracketedPaste,
//! DisableFocusChange,
//! DisableMouseCapture
//! )?;
//! Ok(()) //! Ok(())
//! } //! }
//! ``` //! ```