summaryrefslogtreecommitdiffstats
path: root/src/cli
diff options
context:
space:
mode:
authorCanop <cano.petrole@gmail.com>2021-06-15 19:00:51 +0200
committerCanop <cano.petrole@gmail.com>2021-06-15 19:00:51 +0200
commitcd1d2c361690043e485d398fe8634268e07af365 (patch)
tree9c501bdaf92c56722ee4c51111bc12e626548309 /src/cli
parent304313d81a6d16c49e25568767abb66a8d4a069e (diff)
better handling of auto color mode
- deciding whether to use no-style when there's no --color argument is made twice: for app running and for export when leaving - remove the deprecated `--no-style` launch argument (use `--color no` instead) - deprecate the `--out` argument (redirecting the output is the recommanded solution) Fix #397
Diffstat (limited to 'src/cli')
-rw-r--r--src/cli/app_launch_args.rs6
-rw-r--r--src/cli/clap_args.rs9
-rw-r--r--src/cli/mod.rs27
3 files changed, 13 insertions, 29 deletions
diff --git a/src/cli/app_launch_args.rs b/src/cli/app_launch_args.rs
index 8618444..a1fe479 100644
--- a/src/cli/app_launch_args.rs
+++ b/src/cli/app_launch_args.rs
@@ -13,11 +13,11 @@ use {
/// life of the program
pub struct AppLaunchArgs {
pub root: PathBuf, // what should be the initial root
- pub file_export_path: Option<String>, // where to write the produced path (if required with --out)
+ pub file_export_path: Option<String>, // where to write the produced path (if required with --out) - deprecated
pub cmd_export_path: Option<String>, // where to write the produced command (if required with --outcmd)
pub tree_options: TreeOptions, // initial tree options
pub commands: Option<String>, // commands passed as cli argument, still unparsed
pub height: Option<u16>, // an optional height to replace the screen's one
- pub no_style: bool, // whether to remove all styles (including colors)
- pub listen: Option<String>,
+ pub color: Option<bool>, // whether to display colors and styles
+ pub listen: Option<String>, // if some, broot will start in serve mode on this socket
}
diff --git a/src/cli/clap_args.rs b/src/cli/clap_args.rs
index 5331326..bf4fe69 100644
--- a/src/cli/clap_args.rs
+++ b/src/cli/clap_args.rs
@@ -180,10 +180,11 @@ pub fn clap_app() -> clap::App<'static, 'static> {
.takes_value(true),
)
.arg(
- clap::Arg::with_name("file-export-path")
+ clap::Arg::with_name("file-export-path") // deprecated since broot 1.6
.short("o")
.long("out")
.takes_value(true)
+ .hidden(true)
.help("Where to write the produced path (if any)"),
)
.arg(
@@ -192,12 +193,6 @@ pub fn clap_app() -> clap::App<'static, 'static> {
.help("Install or reinstall the br shell function"),
)
.arg(
- clap::Arg::with_name("no-style")
- .hidden(true) // we're deprecating this in favor of --color
- .long("no-style")
- .help("Whether to remove all style and colors from exported tree"),
- )
- .arg(
clap::Arg::with_name("set-install-state")
.long("set-install-state")
.takes_value(true)
diff --git a/src/cli/mod.rs b/src/cli/mod.rs
index 64ecf95..6f84164 100644
--- a/src/cli/mod.rs
+++ b/src/cli/mod.rs
@@ -28,11 +28,10 @@ use {
event::{DisableMouseCapture, EnableMouseCapture},
terminal::{EnterAlternateScreen, LeaveAlternateScreen},
QueueableCommand,
- tty::IsTty,
},
std::{
env,
- io::{self, Write, stdout},
+ io::{self, Write},
path::{Path, PathBuf},
},
};
@@ -75,10 +74,6 @@ fn get_root_path(cli_args: &ArgMatches<'_>) -> Result<PathBuf, ProgramError> {
Ok(canonicalize_root(&root)?)
}
-fn is_output_piped() -> bool {
- !stdout().is_tty()
-}
-
/// run the application, and maybe return a launchable
/// which must be run after broot
pub fn run() -> Result<Option<Launchable>, ProgramError> {
@@ -148,18 +143,12 @@ pub fn run() -> Result<Option<Launchable>, ProgramError> {
let file_export_path = cli_matches.value_of("file-export-path").map(str::to_string);
let cmd_export_path = cli_matches.value_of("cmd-export-path").map(str::to_string);
let commands = cli_matches.value_of("commands").map(str::to_string);
- let (no_style, must_show_selection_mark) = {
- if cli_matches.is_present("no-style") {
- (true, is_output_piped())
- } else {
- match cli_matches.value_of("color") {
- Some("yes") => (false, false),
- Some("no") => (true, !is_output_piped()),
- _ => (is_output_piped(), false),
- }
- }
- };
let height = cli_matches.value_of("height").and_then(|s| s.parse().ok());
+ let color = match cli_matches.value_of("color") {
+ Some("yes") => Some(true),
+ Some("no") => Some(false),
+ _ => None,
+ };
let root = get_root_path(&cli_matches)?;
@@ -190,10 +179,10 @@ pub fn run() -> Result<Option<Launchable>, ProgramError> {
tree_options,
commands,
height,
- no_style,
+ color,
listen: cli_matches.value_of("listen").map(str::to_string),
};
- if must_show_selection_mark {
+ if color == Some(false) {
launch_args.tree_options.show_selection_mark = true;
}