1
Fork 0
mirror of https://github.com/RGBCube/color.v synced 2025-08-01 10:27:45 +00:00

Fix Brush

This commit is contained in:
RGBCube 2022-11-20 21:11:52 +03:00
parent d411886407
commit 3f3b453fd4

View file

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