summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorCatherine Noll <noll.catherine@gmail.com>2021-03-27 22:09:48 -0400
committerCatherine Noll <noll.catherine@gmail.com>2021-03-27 22:20:24 -0400
commit4aaa5f2848e5effcbd0938af374a64a39ab53ae3 (patch)
tree3f67566a951bca29d7b3e6db771cf2f6bd387818
parentd83c438597d29b60c7a4236417e12fa52e67c78c (diff)
Update behavior of --show-themes to rely on the computed is_light_mode
value to determine whether to show light or dark themes by default
-rw-r--r--src/cli.rs10
-rw-r--r--src/main.rs9
2 files changed, 11 insertions, 8 deletions
diff --git a/src/cli.rs b/src/cli.rs
index 60a4d5a7..e90c26d7 100644
--- a/src/cli.rs
+++ b/src/cli.rs
@@ -201,13 +201,11 @@ https://github.com/dandavison/delta/issues.
pub struct Opt {
/// Use default colors appropriate for a light terminal background. For more control, see the
/// style options and --syntax-theme.
- /// When passed in with --show-themes, only light themes will be displayed.
#[structopt(long = "light")]
pub light: bool,
/// Use default colors appropriate for a dark terminal background. For more control, see the
/// style options and --syntax-theme.
- /// When passed in with --show-themes, only dark themes will be displayed.
#[structopt(long = "dark")]
pub dark: bool,
@@ -271,11 +269,13 @@ pub struct Opt {
#[structopt(long = "show-syntax-themes")]
pub show_syntax_themes: bool,
- /// Show all available delta themes, each with an example of highlighted diff output.
+ /// Show available delta themes with an example of highlighted diff output.
/// If diff output is supplied on standard input then this will be used for the demo. For
/// example: `git show --color=always | delta --show-themes`.
- /// When used with the --dark or --light command line arguments, will only show dark or
- /// light themes, respectively.
+ /// By default, if delta is configured to use a light theme (as set by the user or inferred by the
+ /// BAT_THEME), only displays light themes, otherwise will only display dark themes, unless the
+ /// --dark or --light command line arguments are included.
+ /// If both --dark and --light command line arguments are included, will display all themes.
#[structopt(long = "show-themes")]
pub show_themes: bool,
diff --git a/src/main.rs b/src/main.rs
index dcc6ed48..c99fb464 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -68,7 +68,7 @@ fn run_app() -> std::io::Result<i32> {
show_syntax_themes()?;
return Ok(0);
} else if opt.show_themes {
- show_themes(opt.dark, opt.light)?;
+ show_themes(opt.dark, opt.light, opt.computed.is_light_mode)?;
return Ok(0);
}
@@ -312,7 +312,7 @@ where
}
}
-fn show_themes(dark: bool, light: bool) -> std::io::Result<()> {
+fn show_themes(dark: bool, light: bool, computed_theme_is_light: bool) -> std::io::Result<()> {
use bytelines::ByteLines;
use sample_diff::DIFF;
use std::io::BufReader;
@@ -343,7 +343,10 @@ fn show_themes(dark: bool, light: bool) -> std::io::Result<()> {
let is_light_theme = opt.light;
let config = config::Config::from(opt);
- if (dark && is_dark_theme) || (light && is_light_theme) || (!dark && !light) {
+ if (!computed_theme_is_light && is_dark_theme)
+ || (computed_theme_is_light && is_light_theme)
+ || (dark && light)
+ {
writeln!(writer, "\n\nTheme: {}\n", title_style.paint(theme))?;
if let Err(error) = delta(ByteLines::new(BufReader::new(&input[0..])), writer, &config)