@@ -36,6 +36,7 @@ use flags::{CONTROL_CHARS, CONTROL_FLAGS, INPUT_FLAGS, LOCAL_FLAGS, OUTPUT_FLAGS
36
36
37
37
const USAGE : & str = help_usage ! ( "stty.md" ) ;
38
38
const SUMMARY : & str = help_about ! ( "stty.md" ) ;
39
+ const ASCII_DEL : u8 = 127 ;
39
40
40
41
#[ derive( Clone , Copy , Debug ) ]
41
42
pub struct Flag < T > {
@@ -209,7 +210,7 @@ fn stty(opts: &Options) -> UResult<()> {
209
210
let Some ( new_cc) = settings_iter. next ( ) else {
210
211
return Err ( USimpleError :: new (
211
212
1 ,
212
- format ! ( "no mapping specified for '{setting}'" ) ,
213
+ format ! ( "missing argument to '{setting}'" ) ,
213
214
) ) ;
214
215
} ;
215
216
if let ControlFlow :: Break ( false ) =
@@ -490,9 +491,9 @@ fn apply_baud_rate_flag(termios: &mut Termios, input: &str) -> ControlFlow<bool>
490
491
fn apply_char_mapping (
491
492
termios : & mut Termios ,
492
493
control_char_index : SpecialCharacterIndices ,
493
- new_cc : & str ,
494
+ new_val : & str ,
494
495
) -> ControlFlow < bool > {
495
- if let Some ( val) = string_to_control_char ( new_cc ) {
496
+ if let Some ( val) = string_to_control_char ( new_val ) {
496
497
termios. control_chars [ control_char_index as usize ] = val;
497
498
return ControlFlow :: Break ( true ) ;
498
499
}
@@ -507,9 +508,8 @@ fn apply_char_mapping(
507
508
// c. decimal, no prefix
508
509
// 3. Disabling the control character: '^-' or 'undef'
509
510
//
510
- // This function returns the ascii value of the given char , or None if the input cannot be parsed
511
+ // This function returns the ascii value of valid control chars , or None if the input is invalid
511
512
fn string_to_control_char ( s : & str ) -> Option < u8 > {
512
- // try to parse int, then char
513
513
if s == "undef" || s == "^-" {
514
514
return Some ( 0 ) ;
515
515
}
@@ -526,16 +526,15 @@ fn string_to_control_char(s: &str) -> Option<u8> {
526
526
// try to parse ^<char> or just <char>
527
527
let mut chars = s. chars ( ) ;
528
528
match ( chars. next ( ) , chars. next ( ) ) {
529
- ( Some ( '^' ) , Some ( c) ) if c . is_ascii_alphabetic ( ) => {
530
- // subract by '@' to turn the char into the ascii value of '^<char> '
529
+ ( Some ( '^' ) , Some ( c) ) => {
530
+ // special case: ascii value of '^?' is greater than '? '
531
531
if c == '?' {
532
- println ! ( "{}" , ( c . to_ascii_uppercase ( ) as u8 ) . wrapping_sub ( b'@' ) ) ;
532
+ return Some ( ASCII_DEL ) ;
533
533
}
534
+ // subract by '@' to turn the char into the ascii value of '^<char>'
534
535
Some ( ( c. to_ascii_uppercase ( ) as u8 ) . wrapping_sub ( b'@' ) )
535
536
}
536
- ( Some ( c) , None ) => {
537
- Some ( c as u8 )
538
- }
537
+ ( Some ( c) , _) => Some ( c as u8 ) ,
539
538
_ => None ,
540
539
}
541
540
}
0 commit comments