From 30893f1c788770b68380daf4724a8b510be901c9 Mon Sep 17 00:00:00 2001 From: RGBCube Date: Fri, 18 Nov 2022 20:01:39 +0300 Subject: [PATCH] Make it work (except the builder error) --- color/color.v | 12 ++++++++++++ color/paintbrush.v | 16 +++++++++++----- 2 files changed, 23 insertions(+), 5 deletions(-) create mode 100644 color/color.v diff --git a/color/color.v b/color/color.v new file mode 100644 index 0000000..de6f9ed --- /dev/null +++ b/color/color.v @@ -0,0 +1,12 @@ +module color + +type Color = BasicColor | TrueColor + +// I have no idea why this is needed +fn (c Color) apply(msg string) string { + return c.apply(msg) +} + +fn (c Color) apply_bg(msg string) string { + return c.apply_bg(msg) +} diff --git a/color/paintbrush.v b/color/paintbrush.v index 907b162..1815a24 100644 --- a/color/paintbrush.v +++ b/color/paintbrush.v @@ -2,8 +2,6 @@ module color import term -type Color = BasicColor | TrueColor - const can_show_color = term.can_show_color_on_stdout() pub struct PaintBrush { @@ -21,11 +19,19 @@ pub fn (p &PaintBrush) apply(msg string) string { mut result := msg // IS NOT IMPLEMENTED YET !!! - if fg := p.fg { + // if fg := p.fg { + // result = fg.apply(result) + // } + // if bg := p.bg { + // result = bg.apply(result) + // } + fg := p.fg or { unsafe { nil } } + if !isnil(fg) { result = fg.apply(result) } - if bg := p.bg { - result = bg.apply(result) + bg := p.bg or { unsafe { nil } } + if !isnil(fg) { + result = bg.apply_bg(result) } for style in p.styles {