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

fix(example/smux): don't crash on some control codes #189

Merged
merged 1 commit into from
May 13, 2024
Merged
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
23 changes: 16 additions & 7 deletions examples/smux.rs
Original file line number Diff line number Diff line change
Expand Up @@ -254,25 +254,34 @@ async fn handle_pane_key_event(pane: &mut PtyPane, key: &KeyEvent) -> bool {
let input_bytes = match key.code {
KeyCode::Char(ch) => {
let mut send = vec![ch as u8];
let upper = ch.to_ascii_uppercase();
if key.modifiers == KeyModifiers::CONTROL {
match ch {
'n' => {
match upper {
'N' => {
// Ignore Ctrl+n within a pane
return true;
}
'x' => {
'X' => {
// Close the pane
return false;
}
_ => {
let char = ch.to_ascii_uppercase();
let ascii_val = char as u8;
// Since char is guaranteed to be an ASCII character,
// https://github.com/fyne-io/terminal/blob/master/input.go
// https://gist.github.com/ConnerWill/d4b6c776b509add763e17f9f113fd25b
'2' | '@' | ' ' => send = vec![0],
'3' | '[' => send = vec![27],
'4' | '\\' => send = vec![28],
'5' | ']' => send = vec![29],
'6' | '^' => send = vec![30],
'7' | '-' | '_' => send = vec![31],
char if ('A'..='_').contains(&char) => {
// Since A == 65,
// we can safely subtract 64 to get
// the corresponding control character
let ascii_val = char as u8;
let ascii_to_send = ascii_val - 64;
send = vec![ascii_to_send];
}
_ => {}
}
}
send
Expand Down
Loading