From b5cf7edd0997e9d5d480f981588a412e20fac955 Mon Sep 17 00:00:00 2001 From: RGBCube Date: Fri, 18 Nov 2022 19:56:40 +0300 Subject: [PATCH] Use upcomping features --- builder_error2.v | 4 ++-- color/color.v | 21 --------------------- color/paintbrush.v | 17 +++++++++++++---- color/style.v | 4 ++-- color/true_color.v | 16 ++++++++-------- 5 files changed, 25 insertions(+), 37 deletions(-) delete mode 100644 color/color.v diff --git a/builder_error2.v b/builder_error2.v index dc45d8a..63b4fa1 100644 --- a/builder_error2.v +++ b/builder_error2.v @@ -4,8 +4,8 @@ import color fn main() { p := color.PaintBrush{ - fg: color.rgb(0, 0, 0)!, - bg: color.hex(0xffffff)!, + fg: color.rgb(0, 0, 0)! + bg: color.hex(0xffffff)! styles: [color.bold, color.underline, color.italic] } diff --git a/color/color.v b/color/color.v deleted file mode 100644 index 258802e..0000000 --- a/color/color.v +++ /dev/null @@ -1,21 +0,0 @@ -module color - -type Color = BasicColor | NoColor | TrueColor - -const no_color = NoColor{} - -struct NoColor {} - -fn (c Color) apply(msg string) string { - return match c { - NoColor { msg } - else { c.apply(msg) } - } -} - -fn (c Color) apply_bg(msg string) string { - return match c { - NoColor { msg } - else { c.apply_bg(msg) } - } -} diff --git a/color/paintbrush.v b/color/paintbrush.v index d14b24f..907b162 100644 --- a/color/paintbrush.v +++ b/color/paintbrush.v @@ -1,14 +1,15 @@ module color import term -import datatypes + +type Color = BasicColor | TrueColor const can_show_color = term.can_show_color_on_stdout() pub struct PaintBrush { pub: - fg Color = no_color - bg Color = no_color + fg ?Color + bg ?Color styles []Style } @@ -17,7 +18,15 @@ pub fn (p &PaintBrush) apply(msg string) string { return msg } - mut result := p.bg.apply(p.fg.apply(msg)) + mut result := msg + + // IS NOT IMPLEMENTED YET !!! + if fg := p.fg { + result = fg.apply(result) + } + if bg := p.bg { + result = bg.apply(result) + } for style in p.styles { result = style.apply(result) diff --git a/color/style.v b/color/style.v index dd3d1de..516ec24 100644 --- a/color/style.v +++ b/color/style.v @@ -35,8 +35,8 @@ pub fn (s Style) apply(msg string) string { .dim { term.dim } .italic { term.italic } .underline { term.underline } - //.slow_blink { term.slow_blink } - //.rapid_blink { term.rapid_blink } + // .slow_blink { term.slow_blink } + // .rapid_blink { term.rapid_blink } .inverse { term.inverse } .hidden { term.hidden } .strikethrough { term.strikethrough } diff --git a/color/true_color.v b/color/true_color.v index 8864fea..e0e1d19 100644 --- a/color/true_color.v +++ b/color/true_color.v @@ -2,14 +2,6 @@ module color import term -[noinit] -struct TrueColor { -pub: - r int [required] - g int [required] - b int [required] -} - pub fn rgb(r int, g int, b int) !TrueColor { if r < 0 || r > 255 || g < 0 || g > 255 || b < 0 || b > 255 { return error('Red, green and blue must each be between 0 and 255') @@ -25,6 +17,14 @@ pub fn hex(hex int) !TrueColor { return rgb(hex >> 16, hex >> 8 & 0xFF, hex & 0xFF)! } +[noinit] +struct TrueColor { +pub: + r int + g int + b int +} + pub fn (c TrueColor) apply(msg string) string { return term.rgb(c.r, c.g, c.b, msg) }