diff --git a/Cargo.lock b/Cargo.lock index fd81c3c..e0c0751 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -124,6 +124,7 @@ dependencies = [ "memmap 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)", "num_cpus 1.7.0 (registry+https://github.com/rust-lang/crates.io-index)", "regex 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", + "terminal_size 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)", ] [[package]] @@ -212,6 +213,16 @@ dependencies = [ "winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "terminal_size" +version = "0.1.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "kernel32-sys 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.32 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.2.8 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "termion" version = "1.5.1" @@ -314,6 +325,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index" "checksum same-file 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "d931a44fdaa43b8637009e7632a02adc4f2b2e0733c08caa4cf00e8da4a117a7" "checksum strsim 0.6.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b4d15c810519a91cf877e7e36e63fe068815c678181439f2f29e2562147c3694" "checksum term_size 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "e2b6b55df3198cc93372e85dd2ed817f0e38ce8cc0f22eb32391bfad9c4bf209" +"checksum terminal_size 0.1.7 (registry+https://github.com/rust-lang/crates.io-index)" = "ef4f7fdb2a063032d361d9a72539380900bc3e0cd9ffc9ca8b677f8c855bae0f" "checksum termion 1.5.1 (registry+https://github.com/rust-lang/crates.io-index)" = "689a3bdfaab439fd92bc87df5c4c78417d3cbe537487274e9b0b2dce76e92096" "checksum textwrap 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "df8e08afc40ae3459e4838f303e465aa50d823df8d7f83ca88108f6d3afe7edd" "checksum thread_local 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "1697c4b57aeeb7a536b647165a2825faddffb1d3bad386d507709bd51a90bb14" diff --git a/Cargo.toml b/Cargo.toml index 5086a50..ba86174 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -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 diff --git a/src/main.rs b/src/main.rs index 61607a6..d10f62e 100644 --- a/src/main.rs +++ b/src/main.rs @@ -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; @@ -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)")) @@ -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::().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::().unwrap(); + } } let threads = num_cpus::get();