diff --git a/color/paintbrush.v b/color/paintbrush.v index aa2fdd7..f8c2b43 100644 --- a/color/paintbrush.v +++ b/color/paintbrush.v @@ -4,6 +4,7 @@ module color pub interface Brush { Style +mut: set_disabled(bool) } @@ -11,12 +12,13 @@ pub interface Brush { pub interface BrushParams { fg ?Color bg ?Color + styles []Style } -pub fn new_brush(styles ...Style, p BrushParams) !Brush { +pub fn new_brush(p BrushParams) !Brush { mut style_counter := map[Style]int{} - for style in styles { + for style in p.styles { if style is Color { return error('A Color was given instead of a Style') } @@ -28,15 +30,19 @@ pub fn new_brush(styles ...Style, p BrushParams) !Brush { } } - return BrushImpl{styles + p.fg, bg} + return BrushImpl{ + fg: p.fg + bg: p.bg + styles: p.styles + } } // Declaration struct BrushImpl { - // The foreground is in styles because it fits that interface - styles []Style + fg ?Color bg ?Color + styles []Style mut: disabled bool } @@ -47,17 +53,20 @@ fn (p &BrushImpl) render(msg string) string { } else { mut result := msg - for style in p.styles { - result = style.render(result) + if fg := p.fg { + result = fg.render(result) } if bg := p.bg { result = bg.render_bg(result) } + for style in p.styles { + result = style.render(result) + } result } } -fn (mut p &BrushImpl) set_disabled(value bool) { +fn (mut p BrushImpl) set_disabled(value bool) { p.disabled = value }