Skip to content

Commit 5c00054

Browse files
committed
feat: proxy ptty sequences to device
Extends the ptty integration so that code running on the device can query the host-side ptty's cursor position (& "Keyboard Enhancement Flags"), which is required for `noline`[^1] to function. See also: rustbox/crossterm@1d223fd [^1]: a rust crate that implements a `no_std` readline clone
1 parent 62cec88 commit 5c00054

File tree

3 files changed

+53
-33
lines changed

3 files changed

+53
-33
lines changed

Cargo.lock

Lines changed: 29 additions & 18 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

espflash/Cargo.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,9 @@ clap = { version = "4.5.4", features = [
3333
], optional = true }
3434
clap_complete = { version = "4.5.2", optional = true }
3535
comfy-table = { version = "7.1.1", optional = true }
36-
crossterm = { version = "0.25.0", optional = true } # 0.26.x and 0.27.x causes issues on Windows
36+
crossterm = { git = "https://github.com/rustbox/crossterm", rev = "1d223fd2bca8b7df795d4f047ad54f7b39edbdbd", optional = true, features = [
37+
"unfiltered-events",
38+
] } # 0.26.x and 0.27.x causes issues on Windows
3739
ctrlc = { version = "3.4.4", optional = true }
3840
# defmt dependencies are pinned since defmt does not guarantee MSRV even for patch releases
3941
defmt-decoder = { version = "0.3.11", features = [

espflash/src/cli/monitor/mod.rs

Lines changed: 21 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ pub fn monitor(
9191
.into_diagnostic()?;
9292

9393
// We are in raw mode until `_raw_mode` is dropped (ie. this function returns).
94-
let _raw_mode = RawModeGuard::new();
94+
let _raw_mode = RawModeGuard::new()?;
9595

9696
let stdout = stdout();
9797
let mut stdout = ResolvingPrinter::new(elf, stdout.lock());
@@ -116,24 +116,31 @@ pub fn monitor(
116116
stdout.flush().ok();
117117

118118
if interactive_mode && poll(Duration::from_secs(0)).into_diagnostic()? {
119-
if let Event::Key(key) = read().into_diagnostic()? {
120-
if key.kind == KeyEventKind::Press {
121-
if key.modifiers.contains(KeyModifiers::CONTROL) {
122-
match key.code {
123-
KeyCode::Char('c') => break,
124-
KeyCode::Char('r') => {
125-
reset_after_flash(&mut serial, pid).into_diagnostic()?;
126-
continue;
119+
match read().into_diagnostic()? {
120+
Event::Key(key) => {
121+
if key.kind == KeyEventKind::Press {
122+
if key.modifiers.contains(KeyModifiers::CONTROL) {
123+
match key.code {
124+
KeyCode::Char('c') => break,
125+
KeyCode::Char('r') => {
126+
reset_after_flash(&mut serial, pid).into_diagnostic()?;
127+
continue;
128+
}
129+
_ => {}
127130
}
128-
_ => {}
129131
}
130-
}
131132

132-
if let Some(bytes) = handle_key_event(key) {
133-
serial.write_all(&bytes).into_diagnostic()?;
134-
serial.flush().into_diagnostic()?;
133+
if let Some(bytes) = handle_key_event(key) {
134+
serial.write_all(&bytes).into_diagnostic()?;
135+
serial.flush().into_diagnostic()?;
136+
}
135137
}
136138
}
139+
Event::Raw(bytes) => {
140+
serial.write_all(&bytes).into_diagnostic()?;
141+
serial.flush().into_diagnostic()?
142+
}
143+
_ => {}
137144
}
138145
}
139146
}

0 commit comments

Comments
 (0)