Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/uu/ptx/locales/en-US.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
10 changes: 10 additions & 0 deletions src/uu/ptx/src/ptx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,8 @@ fn get_config(matches: &mut clap::ArgMatches) -> UResult<Config> {
.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
Expand Down Expand Up @@ -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";
}

Expand Down Expand Up @@ -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')
Expand Down
26 changes: 26 additions & 0 deletions tests/by-util/test_ptx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
Loading