Skip to content

Commit

Permalink
Fix panic when columns < NO_LANG_HEADER_ROW_LEN (#331)
Browse files Browse the repository at this point in the history
$ cargo run -- --columns=66
    thread 'main' panicked at 'attempt to subtract with overflow',
    src/cli_utils.rs:64:17
  • Loading branch information
ocisly authored and XAMPPRocky committed May 6, 2019
1 parent e10c19a commit c2a1665
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,16 +47,18 @@ fn main() -> Result<(), Box<Error>> {
process::exit(0);
}

let columns = cli.columns.or(config.columns).unwrap_or_else(|| {
if cli.files {
term_size::dimensions().map_or(FALLBACK_ROW_LEN, |(w, _)| {
w.max(FALLBACK_ROW_LEN)
})
} else {
FALLBACK_ROW_LEN
}
});

let columns = cli
.columns
.or(config.columns)
.or_else(|| {
if cli.files {
term_size::dimensions().map(|(w, _)| w)
} else {
None
}
})
.unwrap_or(FALLBACK_ROW_LEN)
.max(FALLBACK_ROW_LEN);

let row = "-".repeat(columns);

Expand Down

0 comments on commit c2a1665

Please sign in to comment.