mirror of
https://github.com/RGBCube/color.v
synced 2025-07-31 09:57:47 +00:00
Fix Brush
This commit is contained in:
parent
d411886407
commit
3f3b453fd4
1 changed files with 17 additions and 8 deletions
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue