diff --git a/src/uu/stty/src/flags.rs b/src/uu/stty/src/flags.rs index 14042ff7045..e564011b5bc 100644 --- a/src/uu/stty/src/flags.rs +++ b/src/uu/stty/src/flags.rs @@ -17,10 +17,10 @@ pub const CONTROL_FLAGS: [Flag; 12] = [ Flag::new("parenb", C::PARENB), Flag::new("parodd", C::PARODD), Flag::new("cmspar", C::CMSPAR), - Flag::new("cs5", C::CS5).group(C::CSIZE), - Flag::new("cs6", C::CS6).group(C::CSIZE), - Flag::new("cs7", C::CS7).group(C::CSIZE), - Flag::new("cs8", C::CS8).group(C::CSIZE).sane(), + Flag::new_grouped("cs5", C::CS5, C::CSIZE), + Flag::new_grouped("cs6", C::CS6, C::CSIZE), + Flag::new_grouped("cs7", C::CS7, C::CSIZE), + Flag::new_grouped("cs8", C::CS8, C::CSIZE).sane(), Flag::new("hupcl", C::HUPCL), Flag::new("cstopb", C::CSTOPB), Flag::new("cread", C::CREAD).sane(), @@ -57,22 +57,22 @@ pub const OUTPUT_FLAGS: [Flag; 24] = [ Flag::new("onlret", O::ONLRET), Flag::new("ofill", O::OFILL), Flag::new("ofdel", O::OFDEL), - Flag::new("nl0", O::NL0).group(O::NLDLY).sane(), - Flag::new("nl1", O::NL1).group(O::NLDLY), - Flag::new("cr0", O::CR0).group(O::CRDLY).sane(), - Flag::new("cr1", O::CR1).group(O::CRDLY), - Flag::new("cr2", O::CR2).group(O::CRDLY), - Flag::new("cr3", O::CR3).group(O::CRDLY), - Flag::new("tab0", O::TAB0).group(O::TABDLY).sane(), - Flag::new("tab1", O::TAB1).group(O::TABDLY), - Flag::new("tab2", O::TAB2).group(O::TABDLY), - Flag::new("tab3", O::TAB3).group(O::TABDLY), - Flag::new("bs0", O::BS0).group(O::BSDLY).sane(), - Flag::new("bs1", O::BS1).group(O::BSDLY), - Flag::new("vt0", O::VT0).group(O::VTDLY).sane(), - Flag::new("vt1", O::VT1).group(O::VTDLY), - Flag::new("ff0", O::FF0).group(O::FFDLY).sane(), - Flag::new("ff1", O::FF1).group(O::FFDLY), + Flag::new_grouped("nl0", O::NL0, O::NLDLY).sane(), + Flag::new_grouped("nl1", O::NL1, O::NLDLY), + Flag::new_grouped("cr0", O::CR0, O::CRDLY).sane(), + Flag::new_grouped("cr1", O::CR1, O::CRDLY), + Flag::new_grouped("cr2", O::CR2, O::CRDLY), + Flag::new_grouped("cr3", O::CR3, O::CRDLY), + Flag::new_grouped("tab0", O::TAB0, O::TABDLY).sane(), + Flag::new_grouped("tab1", O::TAB1, O::TABDLY), + Flag::new_grouped("tab2", O::TAB2, O::TABDLY), + Flag::new_grouped("tab3", O::TAB3, O::TABDLY), + Flag::new_grouped("bs0", O::BS0, O::BSDLY).sane(), + Flag::new_grouped("bs1", O::BS1, O::BSDLY), + Flag::new_grouped("vt0", O::VT0, O::VTDLY).sane(), + Flag::new_grouped("vt1", O::VT1, O::VTDLY), + Flag::new_grouped("ff0", O::FF0, O::FFDLY).sane(), + Flag::new_grouped("ff1", O::FF1, O::FFDLY), ]; pub const LOCAL_FLAGS: [Flag; 18] = [ diff --git a/src/uu/stty/src/stty.rs b/src/uu/stty/src/stty.rs index 5cabe6da60d..c53c01557c4 100644 --- a/src/uu/stty/src/stty.rs +++ b/src/uu/stty/src/stty.rs @@ -37,10 +37,7 @@ pub struct Flag { group: Option, } -impl Flag -where - T: Copy, -{ +impl Flag { pub const fn new(name: &'static str, flag: T) -> Self { Self { name, @@ -51,25 +48,24 @@ where } } - pub const fn hidden(&self) -> Self { + pub const fn new_grouped(name: &'static str, flag: T, group: T) -> Self { Self { - show: false, - ..*self + name, + flag, + show: true, + sane: false, + group: Some(group), } } - pub const fn sane(&self) -> Self { - Self { - sane: true, - ..*self - } + pub const fn hidden(mut self) -> Self { + self.show = false; + self } - pub const fn group(&self, group: T) -> Self { - Self { - group: Some(group), - ..*self - } + pub const fn sane(mut self) -> Self { + self.sane = true; + self } }