Color text tags

This commit is contained in:
mars 2022-10-09 17:10:58 -06:00
parent dec3406a91
commit ac6eac1375
4 changed files with 35 additions and 14 deletions

View File

@ -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.")

View File

@ -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()

View File

@ -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,

View File

@ -5,6 +5,14 @@ use strum::EnumString;
pub enum TextTagKind {
#[strum(disabled)]
Plain,
Black,
Red,
Green,
Yellow,
Blue,
Magenta,
Cyan,
White,
Italic,
Bold,
Underline,