Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit142d920

Browse files
authored
Merge pull request#8280 from yuankunzhang/support-sane-settings
stty: print non-default control characters
2 parents1bb7930 +a8fe603 commit142d920

File tree

2 files changed

+60
-1
lines changed

2 files changed

+60
-1
lines changed

‎src/uu/stty/src/stty.rs

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,22 @@ use flags::{CONTROL_CHARS, CONTROL_FLAGS, INPUT_FLAGS, LOCAL_FLAGS, OUTPUT_FLAGS
4747

4848
constASCII_DEL:u8 =127;
4949

50+
// Sane defaults for control characters.
51+
constSANE_CONTROL_CHARS:[(S,u8);12] =[
52+
(S::VINTR,3),// ^C
53+
(S::VQUIT,28),// ^\
54+
(S::VERASE,127),// DEL
55+
(S::VKILL,21),// ^U
56+
(S::VEOF,4),// ^D
57+
(S::VSTART,17),// ^Q
58+
(S::VSTOP,19),// ^S
59+
(S::VSUSP,26),// ^Z
60+
(S::VREPRINT,18),// ^R
61+
(S::VWERASE,23),// ^W
62+
(S::VLNEXT,22),// ^V
63+
(S::VDISCARD,15),// ^O
64+
];
65+
5066
#[derive(Clone,Copy,Debug)]
5167
pubstructFlag<T>{
5268
name:&'staticstr,
@@ -694,7 +710,21 @@ fn control_char_to_string(cc: nix::libc::cc_t) -> nix::Result<String> {
694710

695711
fnprint_control_chars(termios:&Termios,opts:&Options) -> nix::Result<()>{
696712
if !opts.all{
697-
// TODO: this branch should print values that differ from defaults
713+
// Print only control chars that differ from sane defaults
714+
letmut printed =false;
715+
for(text, cc_index)inCONTROL_CHARS{
716+
let current_val = termios.control_chars[*cc_indexasusize];
717+
let sane_val =get_sane_control_char(*cc_index);
718+
719+
if current_val != sane_val{
720+
print!("{text} = {}; ", control_char_to_string(current_val)?);
721+
printed =true;
722+
}
723+
}
724+
725+
if printed{
726+
println!();
727+
}
698728
returnOk(());
699729
}
700730

@@ -1025,6 +1055,24 @@ fn combo_to_flags(combo: &str) -> Vec<ArgOptions> {
10251055
flags
10261056
}
10271057

1058+
fnget_sane_control_char(cc_index:S) ->u8{
1059+
for(sane_index, sane_val)inSANE_CONTROL_CHARS{
1060+
if sane_index == cc_index{
1061+
return sane_val;
1062+
}
1063+
}
1064+
// Default values for control chars not in the sane list
1065+
match cc_index{
1066+
S::VEOL =>0,
1067+
S::VEOL2 =>0,
1068+
S::VMIN =>1,
1069+
S::VTIME =>0,
1070+
#[cfg(target_os ="linux")]
1071+
S::VSWTC =>0,
1072+
_ =>0,
1073+
}
1074+
}
1075+
10281076
pubfnuu_app() ->Command{
10291077
Command::new(uucore::util_name())
10301078
.version(uucore::crate_version!())

‎tests/by-util/test_stty.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,17 @@ fn print_all() {
3030
}
3131
}
3232

33+
#[test]
34+
#[ignore ="Fails because cargo test does not run in a tty"]
35+
fnsane_settings(){
36+
new_ucmd!().args(&["intr","^A"]).succeeds();
37+
new_ucmd!().succeeds().stdout_contains("intr = ^A");
38+
new_ucmd!()
39+
.args(&["sane"])
40+
.succeeds()
41+
.stdout_str_check(|s| !s.contains("intr = ^A"));
42+
}
43+
3344
#[test]
3445
fnsave_and_setting(){
3546
new_ucmd!()

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp