From ac6eac13754b5a206f04e1a01ccd522df18faafa Mon Sep 17 00:00:00 2001 From: mars Date: Sun, 9 Oct 2022 17:10:58 -0600 Subject: [PATCH] Color text tags --- assets/test.sex | 13 +++++++++++++ src/layout.rs | 18 ++++++++++++++---- src/style.rs | 10 ---------- src/tag.rs | 8 ++++++++ 4 files changed, 35 insertions(+), 14 deletions(-) diff --git a/assets/test.sex b/assets/test.sex index 35ce19f..bccfbed 100644 --- a/assets/test.sex +++ b/assets/test.sex @@ -41,6 +41,19 @@ lines.") (strikethrough (bold (italic (underline "EVERYTHING AT ONCE")))) ".") +(p + "You can write every color in the " + (red "te") + (green "rm") + (yellow "in") + (blue "al") + " " + (magenta "ra") + (cyan "in") + (white "bo") + (black "w") + ".") + (h3 "Styling " (italic "even ") "works " (bold "in ") (strikethrough "headers.")) (h3 "Super long header: Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.") diff --git a/src/layout.rs b/src/layout.rs index 2b03b69..be3e9a7 100644 --- a/src/layout.rs +++ b/src/layout.rs @@ -49,13 +49,23 @@ impl TextTag { pub fn style(&self, style: &Stylesheet) -> String { let string = self.style_children(style); + use ansi_term::{Style, Color}; use TextTagKind::*; + let s = Style::new(); let painter = match self.kind { Plain => return string, - Underline => style.underline, - Bold => style.bold, - Italic => style.italic, - Strikethrough => style.strikethrough, + Black => Color::Black.into(), + Red => Color::Red.into(), + Green => Color::Green.into(), + Yellow => Color::Yellow.into(), + Blue => Color::Blue.into(), + Magenta => Color::Purple.into(), + Cyan => Color::Cyan.into(), + White => Color::White.into(), + Underline => s.underline(), + Bold => s.bold(), + Italic => s.italic(), + Strikethrough => s.strikethrough(), }; painter.paint(string).to_string() diff --git a/src/style.rs b/src/style.rs index 6500fa4..2aa4781 100644 --- a/src/style.rs +++ b/src/style.rs @@ -5,11 +5,6 @@ pub struct Stylesheet { pub header_style_float: Style, pub header_style_floor: Style, pub header_prefix: String, - pub p: Style, - pub underline: Style, - pub bold: Style, - pub italic: Style, - pub strikethrough: Style, pub bullet: Style, pub ul_prefix: String, pub list_indent: usize, @@ -23,11 +18,6 @@ impl Default for Stylesheet { header_style_float: Blue.bold(), header_style_floor: Blue.bold().underline(), header_prefix: "#".to_string(), - p: Style::new(), - underline: Style::new().underline(), - bold: Style::new().bold(), - italic: Style::new().italic(), - strikethrough: Style::new().strikethrough(), bullet: Black.into(), ul_prefix: "*".to_string(), list_indent: 4, diff --git a/src/tag.rs b/src/tag.rs index f05cddc..a408d41 100644 --- a/src/tag.rs +++ b/src/tag.rs @@ -5,6 +5,14 @@ use strum::EnumString; pub enum TextTagKind { #[strum(disabled)] Plain, + Black, + Red, + Green, + Yellow, + Blue, + Magenta, + Cyan, + White, Italic, Bold, Underline,