Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make monitor only send key on press, not on release #661

Merged
merged 1 commit into from
Aug 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Fixed
- Downgrade crossterm and update time crates (#659)
- Monitor now only sends key presses on key down events

### Changed

Expand Down
25 changes: 14 additions & 11 deletions espflash/src/cli/monitor/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ use std::{
time::Duration,
};

use crossterm::event::KeyEventKind;
use crossterm::{
event::{poll, read, Event, KeyCode, KeyEvent, KeyModifiers},
terminal::{disable_raw_mode, enable_raw_mode},
Expand Down Expand Up @@ -116,20 +117,22 @@ pub fn monitor(

if interactive_mode && poll(Duration::from_secs(0)).into_diagnostic()? {
if let Event::Key(key) = read().into_diagnostic()? {
if key.modifiers.contains(KeyModifiers::CONTROL) {
match key.code {
KeyCode::Char('c') => break,
KeyCode::Char('r') => {
reset_after_flash(&mut serial, pid).into_diagnostic()?;
continue;
if key.kind == KeyEventKind::Press {
if key.modifiers.contains(KeyModifiers::CONTROL) {
match key.code {
KeyCode::Char('c') => break,
KeyCode::Char('r') => {
reset_after_flash(&mut serial, pid).into_diagnostic()?;
continue;
}
_ => {}
}
_ => {}
}
}

if let Some(bytes) = handle_key_event(key) {
serial.write_all(&bytes).into_diagnostic()?;
serial.flush().into_diagnostic()?;
if let Some(bytes) = handle_key_event(key) {
serial.write_all(&bytes).into_diagnostic()?;
serial.flush().into_diagnostic()?;
}
}
}
}
Expand Down