Introduce the EnableMouseCapture and DisableMouseCapture commands (#296)
This commit is contained in:
parent
3ab5b170aa
commit
fe6ddb90f1
@ -2,6 +2,7 @@
|
|||||||
|
|
||||||
- `input` module
|
- `input` module
|
||||||
- Derive 'Copy' for 'KeyEvent'
|
- Derive 'Copy' for 'KeyEvent'
|
||||||
|
- Add the `EnableMouseCapture` and `EnableMouseCapture` commands
|
||||||
- `cursor` module
|
- `cursor` module
|
||||||
- Remove `TerminalCursor`, `cursor`, `Crossterm::cursor()`
|
- Remove `TerminalCursor`, `cursor`, `Crossterm::cursor()`
|
||||||
- Introduce static function `crossterm::cursor::position` in place of `TerminalCursor::pos`
|
- Introduce static function `crossterm::cursor::position` in place of `TerminalCursor::pos`
|
||||||
@ -21,10 +22,10 @@
|
|||||||
- Remove re-export terminal module types at root level, are move those to `crossterm::terminal`
|
- Remove re-export terminal module types at root level, are move those to `crossterm::terminal`
|
||||||
- `style module`
|
- `style module`
|
||||||
- Rename `ObjectStyle` to `ContentStyle`. Now full names are used for methods.
|
- Rename `ObjectStyle` to `ContentStyle`. Now full names are used for methods.
|
||||||
- Rename `StyledObject` to `StyledContent` and made members private.
|
- Rename `StyledObject` to `StyledContent` and made members private.
|
||||||
- Rename `attr` method to `attribute`.
|
- Rename `attr` method to `attribute`.
|
||||||
- Rename `Attribute::NoInverse` to `NoReverse`
|
- Rename `Attribute::NoInverse` to `NoReverse`
|
||||||
|
|
||||||
# Version 0.12.1
|
# Version 0.12.1
|
||||||
|
|
||||||
- All the `crossterm_` crates code was moved to the `crossterm` crate
|
- All the `crossterm_` crates code was moved to the `crossterm` crate
|
||||||
|
40
src/input.rs
40
src/input.rs
@ -38,7 +38,7 @@
|
|||||||
#[cfg(feature = "serde")]
|
#[cfg(feature = "serde")]
|
||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
use crate::utils::Result;
|
use crate::utils::{Command, Result};
|
||||||
|
|
||||||
#[cfg(unix)]
|
#[cfg(unix)]
|
||||||
use self::input::unix::UnixInput;
|
use self::input::unix::UnixInput;
|
||||||
@ -47,6 +47,7 @@ use self::input::windows::WindowsInput;
|
|||||||
use self::input::Input;
|
use self::input::Input;
|
||||||
pub use self::input::{AsyncReader, SyncReader};
|
pub use self::input::{AsyncReader, SyncReader};
|
||||||
|
|
||||||
|
mod ansi;
|
||||||
mod input;
|
mod input;
|
||||||
mod sys;
|
mod sys;
|
||||||
|
|
||||||
@ -423,3 +424,40 @@ impl TerminalInput {
|
|||||||
pub fn input() -> TerminalInput {
|
pub fn input() -> TerminalInput {
|
||||||
TerminalInput::new()
|
TerminalInput::new()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// A command that enables mouse mode
|
||||||
|
///
|
||||||
|
pub struct EnableMouseCapture;
|
||||||
|
|
||||||
|
impl Command for EnableMouseCapture {
|
||||||
|
type AnsiType = String;
|
||||||
|
|
||||||
|
fn ansi_code(&self) -> Self::AnsiType {
|
||||||
|
ansi::enable_mouse_mode_csi_sequence()
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(windows)]
|
||||||
|
fn execute_winapi(&self) -> Result<()> {
|
||||||
|
input().enable_mouse_mode()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// A command that disables mouse event monitoring.
|
||||||
|
///
|
||||||
|
/// Mouse events will be produced by the
|
||||||
|
/// [`AsyncReader`](struct.AsyncReader.html)/[`SyncReader`](struct.SyncReader.html).
|
||||||
|
///
|
||||||
|
pub struct DisableMouseCapture;
|
||||||
|
|
||||||
|
impl Command for DisableMouseCapture {
|
||||||
|
type AnsiType = String;
|
||||||
|
|
||||||
|
fn ansi_code(&self) -> Self::AnsiType {
|
||||||
|
ansi::disable_mouse_mode_csi_sequence()
|
||||||
|
}
|
||||||
|
|
||||||
|
#[cfg(windows)]
|
||||||
|
fn execute_winapi(&self) -> Result<()> {
|
||||||
|
input().disable_mouse_mode()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
23
src/input/ansi.rs
Normal file
23
src/input/ansi.rs
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
//! This module provides input related ANSI escape codes.
|
||||||
|
|
||||||
|
use crate::csi;
|
||||||
|
|
||||||
|
pub(crate) fn enable_mouse_mode_csi_sequence() -> String {
|
||||||
|
format!(
|
||||||
|
"{}h{}h{}h{}h",
|
||||||
|
csi!("?1000"),
|
||||||
|
csi!("?1002"),
|
||||||
|
csi!("?1015"),
|
||||||
|
csi!("?1006")
|
||||||
|
)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub(crate) fn disable_mouse_mode_csi_sequence() -> String {
|
||||||
|
format!(
|
||||||
|
"{}l{}l{}l{}l",
|
||||||
|
csi!("?1006"),
|
||||||
|
csi!("?1015"),
|
||||||
|
csi!("?1002"),
|
||||||
|
csi!("?1000")
|
||||||
|
)
|
||||||
|
}
|
@ -4,10 +4,14 @@ use std::sync::mpsc::Receiver;
|
|||||||
use std::{char, sync::mpsc};
|
use std::{char, sync::mpsc};
|
||||||
|
|
||||||
use crate::utils::Result;
|
use crate::utils::Result;
|
||||||
use crate::{csi, write_cout};
|
use crate::write_cout;
|
||||||
|
|
||||||
use super::{
|
use super::{
|
||||||
super::{sys::unix::internal_event_receiver, InputEvent, InternalEvent, KeyEvent},
|
super::{
|
||||||
|
ansi::{disable_mouse_mode_csi_sequence, enable_mouse_mode_csi_sequence},
|
||||||
|
sys::unix::internal_event_receiver,
|
||||||
|
InputEvent, InternalEvent, KeyEvent,
|
||||||
|
},
|
||||||
Input,
|
Input,
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -50,24 +54,12 @@ impl Input for UnixInput {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn enable_mouse_mode(&self) -> Result<()> {
|
fn enable_mouse_mode(&self) -> Result<()> {
|
||||||
write_cout!(&format!(
|
write_cout!(enable_mouse_mode_csi_sequence())?;
|
||||||
"{}h{}h{}h{}h",
|
|
||||||
csi!("?1000"),
|
|
||||||
csi!("?1002"),
|
|
||||||
csi!("?1015"),
|
|
||||||
csi!("?1006")
|
|
||||||
))?;
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn disable_mouse_mode(&self) -> Result<()> {
|
fn disable_mouse_mode(&self) -> Result<()> {
|
||||||
write_cout!(&format!(
|
write_cout!(disable_mouse_mode_csi_sequence())?;
|
||||||
"{}l{}l{}l{}l",
|
|
||||||
csi!("?1006"),
|
|
||||||
csi!("?1015"),
|
|
||||||
csi!("?1002"),
|
|
||||||
csi!("?1000")
|
|
||||||
))?;
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -216,7 +208,7 @@ impl Iterator for AsyncReader {
|
|||||||
/// `SyncReader` is an individual iterator and it doesn't use `None` to indicate that the iteration is
|
/// `SyncReader` is an individual iterator and it doesn't use `None` to indicate that the iteration is
|
||||||
/// finished. You can expect additional `Some(InputEvent)` after calling `next` even if you have already
|
/// finished. You can expect additional `Some(InputEvent)` after calling `next` even if you have already
|
||||||
/// received `None`. Unfortunately, `None` means that an error occurred, but you're free to call `next`
|
/// received `None`. Unfortunately, `None` means that an error occurred, but you're free to call `next`
|
||||||
/// again. This behavior will be changed in the future to avoid errors consumption.
|
/// again. This behavior will be changed in the future to avoid errors consumption.
|
||||||
///
|
///
|
||||||
/// # Notes
|
/// # Notes
|
||||||
///
|
///
|
||||||
|
@ -169,7 +169,8 @@
|
|||||||
|
|
||||||
#[cfg(feature = "input")]
|
#[cfg(feature = "input")]
|
||||||
pub use input::{
|
pub use input::{
|
||||||
input, AsyncReader, InputEvent, KeyEvent, MouseButton, MouseEvent, SyncReader, TerminalInput,
|
input, AsyncReader, DisableMouseCapture, EnableMouseCapture, InputEvent, KeyEvent, MouseButton,
|
||||||
|
MouseEvent, SyncReader, TerminalInput,
|
||||||
};
|
};
|
||||||
#[cfg(feature = "screen")]
|
#[cfg(feature = "screen")]
|
||||||
pub use screen::{
|
pub use screen::{
|
||||||
|
Loading…
Reference in New Issue
Block a user