Skip to content
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
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

### Fixed

- [Windows] Fixed a crash in monitor when espflash is connected via USB Serial/JTAG, and the user is typing into the monitor but the device is not reading serial input. (#943)

### Removed

## [4.0.1] - 2025-07-07
Expand Down
23 changes: 20 additions & 3 deletions espflash/src/cli/monitor/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
//! in our monitor the output is displayed immediately upon reading.

use std::{
io::{ErrorKind, Read, Write, stdout},
io::{self, ErrorKind, Read, Write, stdout},
time::Duration,
};

Expand Down Expand Up @@ -173,14 +173,31 @@ fn handle_user_input(serial: &mut Port, pid: u16, non_interactive: bool) -> Resu
}

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

Ok(true)
}

trait ErrorExt {
fn ignore_timeout(self) -> Self;
}

impl ErrorExt for Result<(), io::Error> {
fn ignore_timeout(self) -> Self {
match self {
Ok(_) => Ok(()),
Err(e) if e.kind() == ErrorKind::TimedOut => Ok(()),
Err(e) => Err(e),
}
}
}

fn key_event() -> std::io::Result<Option<KeyEvent>> {
if !poll(Duration::ZERO)? {
return Ok(None);
Expand Down