diff --git a/src/uu/ptx/locales/en-US.ftl b/src/uu/ptx/locales/en-US.ftl index 9d62b4ae4b6..c9d991c9bf9 100644 --- a/src/uu/ptx/locales/en-US.ftl +++ b/src/uu/ptx/locales/en-US.ftl @@ -21,6 +21,7 @@ ptx-help-gap-size = gap size in columns between output fields ptx-help-ignore-file = read ignore word list from FILE ptx-help-only-file = read only word list from this FILE ptx-help-references = first field of each line is a reference +ptx-help-typeset-mode = change the default width from 72 to 100 ptx-help-width = output width in columns, reference excluded # Error messages diff --git a/src/uu/ptx/src/ptx.rs b/src/uu/ptx/src/ptx.rs index 7749ecc998a..f23c4ac8ba5 100644 --- a/src/uu/ptx/src/ptx.rs +++ b/src/uu/ptx/src/ptx.rs @@ -247,6 +247,8 @@ fn get_config(matches: &mut clap::ArgMatches) -> UResult { .expect(err_msg) .parse() .map_err(PtxError::ParseError)?; + } else if matches.get_flag(options::TYPESET_MODE) { + config.line_width = 100; } if matches.contains_id(options::GAP_SIZE) { config.gap_size = matches @@ -894,6 +896,7 @@ mod options { pub static IGNORE_FILE: &str = "ignore-file"; pub static ONLY_FILE: &str = "only-file"; pub static REFERENCES: &str = "references"; + pub static TYPESET_MODE: &str = "typeset-mode"; pub static WIDTH: &str = "width"; } @@ -1070,6 +1073,13 @@ pub fn uu_app() -> Command { .value_name("FILE") .action(ArgAction::SetTrue), ) + .arg( + Arg::new(options::TYPESET_MODE) + .short('t') + .long(options::TYPESET_MODE) + .help(translate!("ptx-help-typeset-mode")) + .action(ArgAction::SetTrue), + ) .arg( Arg::new(options::WIDTH) .short('w') diff --git a/tests/by-util/test_ptx.rs b/tests/by-util/test_ptx.rs index 63ac3ca8fd4..2e66470bf26 100644 --- a/tests/by-util/test_ptx.rs +++ b/tests/by-util/test_ptx.rs @@ -356,6 +356,32 @@ fn test_narrow_width_with_long_reference_no_panic() { .stdout_only(":1 content\n"); } +#[test] +fn test_typeset_mode_default_width_100() { + new_ucmd!() + .args(&["-t"]) + .pipe_in("bar\n") + .succeeds() + .stdout_only(format!("{}bar\n", " ".repeat(53))); +} + +#[test] +fn test_typeset_mode_w_overrides_t() { + new_ucmd!() + .args(&["-t", "-w", "10"]) + .pipe_in("bar\n") + .succeeds() + .stdout_only(format!("{}bar\n", " ".repeat(8))); +} + +#[test] +fn test_default_width_72() { + new_ucmd!() + .pipe_in("bar\n") + .succeeds() + .stdout_only(format!("{}bar\n", " ".repeat(39))); +} + #[test] fn test_invalid_regex_word_trailing_backslash() { new_ucmd!().args(&["-W", "bar\\"]).succeeds().no_stderr();