From 85b9b61dd8a44e92ced13505c8faf4882061a1d1 Mon Sep 17 00:00:00 2001 From: Tuomas Tynkkynen Date: Sat, 8 Jul 2023 01:35:58 +0300 Subject: [PATCH] stty: Finish '--save' support Argument parsing for this exists, but the option doesn't change output in any way. Finish the support. Closes #3862 --- src/uu/stty/src/stty.rs | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/src/uu/stty/src/stty.rs b/src/uu/stty/src/stty.rs index e09662471..6b77f175a 100644 --- a/src/uu/stty/src/stty.rs +++ b/src/uu/stty/src/stty.rs @@ -244,12 +244,30 @@ fn print_terminal_size(termios: &Termios, opts: &Options) -> nix::Result<()> { Ok(()) } +fn print_in_save_format(termios: &Termios) { + print!( + "{:x}:{:x}:{:x}:{:x}", + termios.input_flags.bits(), + termios.output_flags.bits(), + termios.control_flags.bits(), + termios.local_flags.bits() + ); + for cc in termios.control_chars { + print!(":{cc:x}"); + } + println!(); +} + fn print_settings(termios: &Termios, opts: &Options) -> nix::Result<()> { - print_terminal_size(termios, opts)?; - print_flags(termios, opts, CONTROL_FLAGS); - print_flags(termios, opts, INPUT_FLAGS); - print_flags(termios, opts, OUTPUT_FLAGS); - print_flags(termios, opts, LOCAL_FLAGS); + if opts.save { + print_in_save_format(termios); + } else { + print_terminal_size(termios, opts)?; + print_flags(termios, opts, CONTROL_FLAGS); + print_flags(termios, opts, INPUT_FLAGS); + print_flags(termios, opts, OUTPUT_FLAGS); + print_flags(termios, opts, LOCAL_FLAGS); + } Ok(()) }