Skip to content

Commit f2a9f4b

Browse files
ptx: implement -t/--typeset-mode to change default width to 100 (#10856)
Co-authored-by: Sylvestre Ledru <sylvestre@debian.org>
1 parent 49e35bd commit f2a9f4b

File tree

3 files changed

+37
-0
lines changed

3 files changed

+37
-0
lines changed

‎src/uu/ptx/locales/en-US.ftl‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ ptx-help-gap-size = gap size in columns between output fields
2121
ptx-help-ignore-file = read ignore word list from FILE
2222
ptx-help-only-file = read only word list from this FILE
2323
ptx-help-references = first field of each line is a reference
24+
ptx-help-typeset-mode = change the default width from 72 to 100
2425
ptx-help-width = output width in columns, reference excluded
2526
2627
# Error messages

‎src/uu/ptx/src/ptx.rs‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -247,6 +247,8 @@ fn get_config(matches: &mut clap::ArgMatches) -> UResult<Config> {
247247
.expect(err_msg)
248248
.parse()
249249
.map_err(PtxError::ParseError)?;
250+
} else if matches.get_flag(options::TYPESET_MODE) {
251+
config.line_width = 100;
250252
}
251253
if matches.contains_id(options::GAP_SIZE) {
252254
config.gap_size = matches
@@ -894,6 +896,7 @@ mod options {
894896
pub static IGNORE_FILE: &str = "ignore-file";
895897
pub static ONLY_FILE: &str = "only-file";
896898
pub static REFERENCES: &str = "references";
899+
pub static TYPESET_MODE: &str = "typeset-mode";
897900
pub static WIDTH: &str = "width";
898901
}
899902

@@ -1070,6 +1073,13 @@ pub fn uu_app() -> Command {
10701073
.value_name("FILE")
10711074
.action(ArgAction::SetTrue),
10721075
)
1076+
.arg(
1077+
Arg::new(options::TYPESET_MODE)
1078+
.short('t')
1079+
.long(options::TYPESET_MODE)
1080+
.help(translate!("ptx-help-typeset-mode"))
1081+
.action(ArgAction::SetTrue),
1082+
)
10731083
.arg(
10741084
Arg::new(options::WIDTH)
10751085
.short('w')

‎tests/by-util/test_ptx.rs‎

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -356,6 +356,32 @@ fn test_narrow_width_with_long_reference_no_panic() {
356356
.stdout_only(":1 content\n");
357357
}
358358

359+
#[test]
360+
fn test_typeset_mode_default_width_100() {
361+
new_ucmd!()
362+
.args(&["-t"])
363+
.pipe_in("bar\n")
364+
.succeeds()
365+
.stdout_only(format!("{}bar\n", " ".repeat(53)));
366+
}
367+
368+
#[test]
369+
fn test_typeset_mode_w_overrides_t() {
370+
new_ucmd!()
371+
.args(&["-t", "-w", "10"])
372+
.pipe_in("bar\n")
373+
.succeeds()
374+
.stdout_only(format!("{}bar\n", " ".repeat(8)));
375+
}
376+
377+
#[test]
378+
fn test_default_width_72() {
379+
new_ucmd!()
380+
.pipe_in("bar\n")
381+
.succeeds()
382+
.stdout_only(format!("{}bar\n", " ".repeat(39)));
383+
}
384+
359385
#[test]
360386
fn test_invalid_regex_word_trailing_backslash() {
361387
new_ucmd!().args(&["-W", "bar\\"]).succeeds().no_stderr();

0 commit comments

Comments
 (0)