mirror of
https://github.com/bootandy/dust.git
synced 2026-06-08 11:29:05 +03:00
[core] New flag: width
Add support for width flag https://github.com/bootandy/dust/issues/126 Requested because some people may cat the output All terminal height/width detection is now in the main file. One method now has too many args for clippy, this complaint is valid and in the future we should consider pulling these out into a separate object.
This commit is contained in:
+25
-1
@@ -17,6 +17,7 @@ mod display;
|
||||
mod utils;
|
||||
|
||||
static DEFAULT_NUMBER_OF_LINES: usize = 30;
|
||||
static DEFAULT_TERMINAL_WIDTH: usize = 80;
|
||||
|
||||
#[cfg(windows)]
|
||||
fn init_color(no_color: bool) -> bool {
|
||||
@@ -52,6 +53,15 @@ fn get_height_of_terminal() -> usize {
|
||||
}
|
||||
}
|
||||
|
||||
fn get_width_of_terminal() -> usize {
|
||||
// Windows CI runners detect a very low terminal width
|
||||
if let Some((Width(w), Height(_h))) = terminal_size() {
|
||||
max(w as usize, DEFAULT_TERMINAL_WIDTH)
|
||||
} else {
|
||||
DEFAULT_TERMINAL_WIDTH
|
||||
}
|
||||
}
|
||||
|
||||
fn main() {
|
||||
let default_height = get_height_of_terminal();
|
||||
let def_num_str = default_height.to_string();
|
||||
@@ -71,7 +81,7 @@ fn main() {
|
||||
Arg::with_name("number_of_lines")
|
||||
.short("n")
|
||||
.long("number-of-lines")
|
||||
.help("Number of lines of output to show")
|
||||
.help("Number of lines of output to show. This is Height, (but h is help)")
|
||||
.takes_value(true)
|
||||
.default_value(def_num_str.as_ref()),
|
||||
)
|
||||
@@ -132,6 +142,14 @@ fn main() {
|
||||
.long("ignore_hidden")
|
||||
.help("Obey .git_ignore rules & Do not display hidden files"),
|
||||
)
|
||||
.arg(
|
||||
Arg::with_name("width")
|
||||
.short("w")
|
||||
.long("terminal_width")
|
||||
.takes_value(true)
|
||||
.number_of_values(1)
|
||||
.help("Specify width of output overriding the auto detection of terminal width"),
|
||||
)
|
||||
|
||||
.arg(Arg::with_name("inputs").multiple(true))
|
||||
.get_matches();
|
||||
@@ -151,6 +169,11 @@ fn main() {
|
||||
}
|
||||
};
|
||||
|
||||
let terminal_width = match value_t!(options.value_of("width"), usize) {
|
||||
Ok(v) => v,
|
||||
Err(_) => get_width_of_terminal(),
|
||||
};
|
||||
|
||||
let depth = options.value_of("depth").and_then(|depth| {
|
||||
depth
|
||||
.parse::<usize>()
|
||||
@@ -197,6 +220,7 @@ fn main() {
|
||||
!options.is_present("reverse"),
|
||||
no_colors,
|
||||
options.is_present("no_bars"),
|
||||
terminal_width,
|
||||
by_filecount,
|
||||
tree,
|
||||
);
|
||||
|
||||
Reference in New Issue
Block a user