diff options
author | mia <mia@mia.jetzt> | 2024-04-07 05:27:59 -0700 |
---|---|---|
committer | mia <mia@mia.jetzt> | 2024-04-07 05:27:59 -0700 |
commit | 9045e56c8e342b3eb3069274e6f0211238f7ca24 (patch) | |
tree | 4b9be14550db8c695c6480c7acb75c1ccf1c6c27 /src/main.rs | |
parent | f169357f4e7a7b6e25acd5e4bdffc91679162631 (diff) | |
download | cgit-syntect-9045e56c8e342b3eb3069274e6f0211238f7ca24.tar.gz cgit-syntect-9045e56c8e342b3eb3069274e6f0211238f7ca24.zip |
theme generation cleanups v0.1.0
Diffstat (limited to 'src/main.rs')
-rw-r--r-- | src/main.rs | 37 |
1 files changed, 23 insertions, 14 deletions
diff --git a/src/main.rs b/src/main.rs index e353666..9cc7b85 100644 --- a/src/main.rs +++ b/src/main.rs @@ -43,10 +43,17 @@ fn theme() { let mut scopes_gen = Vec::new(); let mut global_css = String::new(); + let credit = match (theme.name, theme.author) { + (None, None) => "".to_string(), + (None, Some(author)) => format!("/* theme by {author} */\n"), + (Some(name), None) => format!("/* {name} theme */\n"), + (Some(name), Some(author)) => format!("/* {name} theme by {author} */\n"), + }; + global_css.push_str(&credit); global_css.push_str(".highlight {\n"); if let Some(bg) = theme.settings.background { global_css.push_str(" background-color: #"); - global_css.extend(hex_color(bg)); + global_css.push_str(&hex_color(bg)); global_css.push_str(";\n"); } global_css.push_str("}\n"); @@ -62,13 +69,13 @@ fn theme() { if let Some(fg) = item.style.foreground { css.push_str(" color: #"); - css.extend(hex_color(fg)); + css.push_str(&hex_color(fg)); css.push_str(";\n"); } if let Some(bg) = item.style.background { css.push_str(" background-color: #"); - css.extend(hex_color(bg)); + css.push_str(&hex_color(bg)); css.push_str(";\n"); } @@ -108,18 +115,20 @@ fn selectors_to_string(selectors: ScopeSelectors) -> String { scopes.join(", ") } -fn hex_color(color: Color) -> [char; 8] { +fn hex_color(color: Color) -> String { const HEX_DIGIT_LOOKUP: &[u8; 16] = b"0123456789abcdef"; - [ - HEX_DIGIT_LOOKUP[(color.r >> 4) as usize] as char, - HEX_DIGIT_LOOKUP[(color.r & 0xf) as usize] as char, - HEX_DIGIT_LOOKUP[(color.g >> 4) as usize] as char, - HEX_DIGIT_LOOKUP[(color.g & 0xf) as usize] as char, - HEX_DIGIT_LOOKUP[(color.b >> 4) as usize] as char, - HEX_DIGIT_LOOKUP[(color.b & 0xf) as usize] as char, - HEX_DIGIT_LOOKUP[(color.a >> 4) as usize] as char, - HEX_DIGIT_LOOKUP[(color.a & 0xf) as usize] as char, - ] + let mut hex = String::with_capacity(8); + hex.push(HEX_DIGIT_LOOKUP[(color.r >> 4) as usize] as char); + hex.push(HEX_DIGIT_LOOKUP[(color.r & 0xf) as usize] as char); + hex.push(HEX_DIGIT_LOOKUP[(color.g >> 4) as usize] as char); + hex.push(HEX_DIGIT_LOOKUP[(color.g & 0xf) as usize] as char); + hex.push(HEX_DIGIT_LOOKUP[(color.b >> 4) as usize] as char); + hex.push(HEX_DIGIT_LOOKUP[(color.b & 0xf) as usize] as char); + if color.a != 0xff { + hex.push(HEX_DIGIT_LOOKUP[(color.a >> 4) as usize] as char); + hex.push(HEX_DIGIT_LOOKUP[(color.a & 0xf) as usize] as char); + } + hex } fn highlight() { |