summaryrefslogtreecommitdiffstats
path: root/src/subcommands/show_colors.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/subcommands/show_colors.rs')
-rw-r--r--src/subcommands/show_colors.rs73
1 files changed, 73 insertions, 0 deletions
diff --git a/src/subcommands/show_colors.rs b/src/subcommands/show_colors.rs
new file mode 100644
index 00000000..fd194377
--- /dev/null
+++ b/src/subcommands/show_colors.rs
@@ -0,0 +1,73 @@
+use crate::cli;
+use crate::color;
+use crate::colors;
+use crate::config;
+use crate::delta;
+use crate::git_config;
+use crate::paint;
+use crate::paint::BgShouldFill;
+use crate::style;
+use crate::utils::bat::assets::HighlightingAssets;
+use crate::utils::bat::output::{OutputType, PagingMode};
+
+#[cfg(not(tarpaulin_include))]
+pub fn show_colors() -> std::io::Result<()> {
+ use itertools::Itertools;
+
+ let assets = HighlightingAssets::new();
+ let opt = cli::Opt::from_args_and_git_config(git_config::GitConfig::try_create(), assets);
+ let config = config::Config::from(opt);
+
+ let mut output_type =
+ OutputType::from_mode(PagingMode::QuitIfOneScreen, None, &config).unwrap();
+ let writer = output_type.handle().unwrap();
+
+ let mut painter = paint::Painter::new(writer, &config);
+ painter.set_syntax(Some("ts"));
+ painter.set_highlighter();
+
+ let title_style = ansi_term::Style::new().bold();
+ let mut style = style::Style {
+ is_syntax_highlighted: true,
+ ..style::Style::default()
+ };
+ for (group, color_names) in colors::color_groups().iter().sorted() {
+ writeln!(painter.writer, "\n\n{}\n", title_style.paint(group))?;
+ for (color_name, hex) in color_names {
+ // Two syntax-highlighted lines without background color
+ style.ansi_term_style.background = None;
+ for line in [
+ r#"export function color(): string {{ return "none" }}"#,
+ r#"export function hex(): string {{ return "none" }}"#,
+ ] {
+ painter.syntax_highlight_and_paint_line(
+ line,
+ paint::StyleSectionSpecifier::Style(style),
+ delta::State::HunkZero,
+ BgShouldFill::default(),
+ )
+ }
+ // Two syntax-highlighted lines with background color
+ let color =
+ color::parse_color(color_name, config.true_color, config.git_config.as_ref())
+ .unwrap();
+ style.ansi_term_style.background = Some(color);
+ for line in [
+ &format!(
+ r#"export function color(): string {{ return "{}" }}"#,
+ color_name
+ ),
+ &format!(r#"export function hex(): string {{ return "{}" }}"#, hex),
+ ] {
+ painter.syntax_highlight_and_paint_line(
+ line,
+ paint::StyleSectionSpecifier::Style(style),
+ delta::State::HunkZero,
+ BgShouldFill::default(),
+ )
+ }
+ painter.emit()?;
+ }
+ }
+ Ok(())
+}