Skip to content

Commit

Permalink
Accept "full" as a value for --width
Browse files Browse the repository at this point in the history
Use the terminal_size crate to use the full terminal width.
  • Loading branch information
brewingcode committed Mar 8, 2018
1 parent 034a5ef commit 389838d
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 3 deletions.
12 changes: 12 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ memmap = "0.5.2"
regex = "0.2.2"
num_cpus = "1.7.0"
ignore = "0.2.2"
terminal_size = "0.1.7"

# [profile.release]
# lto = true
20 changes: 17 additions & 3 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,16 @@ extern crate deque;
extern crate num_cpus;
extern crate regex;
extern crate ignore;
extern crate terminal_size;

use clap::{Arg, App, AppSettings};
use ignore::WalkBuilder;
use terminal_size::{Width, terminal_size};

use std::collections::HashMap;
use std::collections::hash_map::Entry;
use std::thread;
use std::option::Option;

use deque::{Stealer, Stolen};
use regex::Regex;
Expand Down Expand Up @@ -114,9 +117,10 @@ fn main() {
.arg(Arg::with_name("width")
.required(false)
.long("width")
.value_name("WIDTH")
.short("w")
.takes_value(true)
.help("Change width of output (default: 80)"))
.value_name("N")
.help("Change width of output from 80 to N, or use full terminal width with N = `full`"))
.arg(Arg::with_name("target")
.multiple(true)
.help("File or directory to count (multiple arguments accepted)"))
Expand Down Expand Up @@ -162,7 +166,17 @@ fn main() {
};
let mut width: usize = 80;
if matches.is_present("width") {
width = matches.value_of("width").unwrap_or("80").parse::<usize>().unwrap();
let val = matches.value_of("width");
let x: Option<&str> = Some("full");
if val == x {
let size = terminal_size();
if let Some((Width(w), _)) = size {
width = w as usize;
}
}
else {
width = val.unwrap_or("80").parse::<usize>().unwrap();
}
}

let threads = num_cpus::get();
Expand Down

0 comments on commit 389838d

Please sign in to comment.