summaryrefslogtreecommitdiffstats
path: root/src/main.rs
diff options
context:
space:
mode:
authorDan Davison <dandavison7@gmail.com>2020-06-29 18:21:50 -0400
committerDan Davison <dandavison7@gmail.com>2020-06-30 08:00:30 -0400
commita733af869f35e7f00380483865abf42033699c5a (patch)
tree026320aaee86e55bf7dbfd55c0796a0d2a43eea2 /src/main.rs
parentc8d24c27cbb886c109e02c679ddb68dfe18c129c (diff)
Fix --show-syntax-themes
Diffstat (limited to 'src/main.rs')
-rw-r--r--src/main.rs58
1 files changed, 30 insertions, 28 deletions
diff --git a/src/main.rs b/src/main.rs
index a70b83c3..c556b92e 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -226,9 +226,24 @@ where
}
fn show_syntax_themes() -> std::io::Result<()> {
+ let mut opt = cli::Opt::from_args();
+ let assets = HighlightingAssets::new();
+ opt.computed.syntax_set = assets.syntax_set;
+
+ if !(opt.dark || opt.light) {
+ _show_syntax_themes(opt.clone(), true)?;
+ _show_syntax_themes(opt, false)?;
+ } else if opt.light {
+ _show_syntax_themes(opt, true)?;
+ } else {
+ _show_syntax_themes(opt, false)?
+ };
+ Ok(())
+}
+
+fn _show_syntax_themes(mut opt: cli::Opt, is_light_mode: bool) -> std::io::Result<()> {
use bytelines::ByteLines;
use std::io::BufReader;
- let opt = cli::Opt::from_args();
let input = if !atty::is(atty::Stream::Stdin) {
let mut buf = Vec::new();
io::stdin().lock().read_to_end(&mut buf)?;
@@ -248,39 +263,26 @@ index f38589a..0f1bb83 100644
+fn print_cube(num: f64) {
+ let result = f64::powf(num, 3.0);
+ println!(\"The cube of {:.2} is {:.2}.\", num, result);
- }
"
.to_vec()
};
- let stdout = io::stdout();
- let mut stdout = stdout.lock();
- let style = ansi_term::Style::new().bold();
-
+ opt.computed.is_light_mode = is_light_mode;
+ let mut config = config::Config::from(opt);
+ let mut output_type = OutputType::from_mode(PagingMode::Never, None, &config).unwrap();
+ let mut writer = output_type.handle().unwrap();
+ let title_style = ansi_term::Style::new().bold();
let assets = HighlightingAssets::new();
- for (syntax_theme, _) in assets.theme_set.themes.iter() {
- if opt.light && !syntax_theme::is_light_theme(syntax_theme)
- || opt.dark && syntax_theme::is_light_theme(syntax_theme)
- {
- continue;
- }
-
- writeln!(stdout, "\n\nTheme: {}\n", style.paint(syntax_theme))?;
-
- let opt_2 = cli::Opt::from_iter(&[
- "--syntax-theme",
- syntax_theme,
- "--file-style",
- "omit",
- "--hunk-header-style",
- "omit",
- ]);
- let config = config::Config::from(opt_2);
- let mut output_type =
- OutputType::from_mode(PagingMode::QuitIfOneScreen, None, &config).unwrap();
- let mut writer = output_type.handle().unwrap();
-
+ for syntax_theme in assets
+ .theme_set
+ .themes
+ .iter()
+ .filter(|(t, _)| syntax_theme::is_light_theme(t) == is_light_mode)
+ .map(|(t, _)| t)
+ {
+ writeln!(writer, "\n\nTheme: {}\n", title_style.paint(syntax_theme))?;
+ config.syntax_theme = Some(assets.theme_set.themes[syntax_theme.as_str()].clone());
if let Err(error) = delta(
ByteLines::new(BufReader::new(&input[0..])),
&mut writer,