1use image::Rgb;
2use syntect::highlighting::Style;
3
4#[derive(clap::ValueEnum, Clone, Copy, Debug)]
6pub enum FgColor {
7 Style,
9 StyleAsciiBrightness,
11}
12
13#[derive(clap::ValueEnum, Clone, Copy, Debug, Eq, PartialEq)]
15pub enum BgColor {
16 Style,
18 StyleCheckerboardDarken,
21 StyleCheckerboardBrighten,
24 HelixEditor,
26}
27
28impl BgColor {
29 pub fn to_rgb(&self, style: Style, file_index: usize, color_modulation: f32) -> Rgb<u8> {
30 match self {
31 BgColor::Style => Rgb([style.background.r, style.background.g, style.background.b]),
32 BgColor::HelixEditor => Rgb([59, 34, 76]),
33 BgColor::StyleCheckerboardDarken | BgColor::StyleCheckerboardBrighten => {
34 let m = if self == &BgColor::StyleCheckerboardBrighten {
35 if file_index % 2 == 0 {
36 1.0 + color_modulation
37 } else {
38 1.0
39 }
40 } else {
41 (file_index % 2 == 0)
42 .then_some(1.0)
43 .unwrap_or_else(|| (1.0_f32 - color_modulation).max(0.0))
44 };
45 Rgb([
46 (style.background.r as f32 * m).min(255.0) as u8,
47 (style.background.g as f32 * m).min(255.0) as u8,
48 (style.background.b as f32 * m).min(255.0) as u8,
49 ])
50 }
51 }
52 }
53}
54
55#[derive(Debug, Copy, Clone)]
57pub struct Options<'a> {
58 pub column_width: u32,
60 pub line_height: u32,
62 pub readable: bool,
64
65 pub show_filenames: bool,
67
68 pub target_aspect_ratio: f64,
69
70 pub threads: usize,
72 pub highlight_truncated_lines: bool,
73
74 pub fg_color: FgColor,
75 pub bg_color: BgColor,
76 pub theme: &'a str,
78
79 pub force_full_columns: bool,
81 pub ignore_files_without_syntax: bool,
83 pub plain: bool,
84 pub display_to_be_processed_file: bool,
85 pub color_modulation: f32,
86 pub tab_spaces: u32,
88 pub line_nums: bool,
89}
90
91impl Default for Options<'_> {
92 fn default() -> Self {
93 Options {
94 column_width: 100,
95 line_height: 2,
96 readable: false,
97 show_filenames: false,
98 target_aspect_ratio: 16. / 9.,
99 threads: num_cpus::get(),
100 highlight_truncated_lines: false,
101 fg_color: FgColor::StyleAsciiBrightness,
102 bg_color: BgColor::Style,
103 theme: "Solarized (dark)",
104 force_full_columns: true,
105 ignore_files_without_syntax: false,
106 plain: false,
107 display_to_be_processed_file: false,
108 color_modulation: 0.3,
109 tab_spaces: 4,
110 line_nums: false,
111 }
112 }
113}
114
115mod highlight;
116use highlight::Cache;
117
118pub(crate) mod function;
119
120mod chunk;
121
122mod dimension;
123use dimension::Dimension;