mirror of
https://github.com/RGBCube/color.v
synced 2025-08-01 10:27:45 +00:00
Use inline ifs
This commit is contained in:
parent
dceda93727
commit
3345868729
4 changed files with 82 additions and 82 deletions
|
@ -22,10 +22,9 @@ enum BasicColor {
|
|||
}
|
||||
|
||||
fn (c BasicColor) render(msg string) string {
|
||||
if no_color {
|
||||
return msg
|
||||
}
|
||||
|
||||
return if no_color {
|
||||
msg
|
||||
} else {
|
||||
func := match c {
|
||||
.black { term.black }
|
||||
.red { term.red }
|
||||
|
@ -45,14 +44,14 @@ fn (c BasicColor) render(msg string) string {
|
|||
.bright_white { term.bright_white }
|
||||
}
|
||||
|
||||
return func(msg)
|
||||
func(msg)
|
||||
}
|
||||
}
|
||||
|
||||
fn (c BasicColor) render_bg(msg string) string {
|
||||
if no_color {
|
||||
return msg
|
||||
}
|
||||
|
||||
return if no_color {
|
||||
msg
|
||||
} else {
|
||||
func := match c {
|
||||
.black { term.bg_black }
|
||||
.red { term.bg_red }
|
||||
|
@ -72,5 +71,6 @@ fn (c BasicColor) render_bg(msg string) string {
|
|||
.bright_white { term.bright_bg_white }
|
||||
}
|
||||
|
||||
return func(msg)
|
||||
func(msg)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -37,10 +37,9 @@ pub fn new_brush(p BrushParams) !Brush {
|
|||
}
|
||||
|
||||
pub fn (p &Brush) render(msg string) string {
|
||||
if no_color || p.disabled {
|
||||
return msg
|
||||
}
|
||||
|
||||
return if no_color || p.disabled {
|
||||
msg
|
||||
} else {
|
||||
mut result := msg
|
||||
|
||||
if fg := p.fg {
|
||||
|
@ -53,7 +52,8 @@ pub fn (p &Brush) render(msg string) string {
|
|||
result = style.render(result)
|
||||
}
|
||||
|
||||
return result
|
||||
result
|
||||
}
|
||||
}
|
||||
|
||||
pub fn (p &Brush) cprint(msg string) {
|
||||
|
|
|
@ -16,10 +16,9 @@ enum Style {
|
|||
}
|
||||
|
||||
pub fn (s Style) render(msg string) string {
|
||||
if no_color {
|
||||
return msg
|
||||
}
|
||||
|
||||
return if no_color {
|
||||
msg
|
||||
} else {
|
||||
func := match s {
|
||||
.reset { term.reset }
|
||||
.bold { term.bold }
|
||||
|
@ -33,5 +32,6 @@ pub fn (s Style) render(msg string) string {
|
|||
.strikethrough { term.strikethrough }
|
||||
}
|
||||
|
||||
return func(msg)
|
||||
func(msg)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -21,17 +21,17 @@ struct TrueColor {
|
|||
}
|
||||
|
||||
fn (c TrueColor) render(msg string) string {
|
||||
if no_color {
|
||||
return msg
|
||||
return if no_color {
|
||||
msg
|
||||
} else {
|
||||
term.rgb(c.r, c.g, c.b, msg)
|
||||
}
|
||||
|
||||
return term.rgb(c.r, c.g, c.b, msg)
|
||||
}
|
||||
|
||||
fn (c TrueColor) render_bg(msg string) string {
|
||||
if no_color {
|
||||
return msg
|
||||
return if no_color {
|
||||
msg
|
||||
} else {
|
||||
term.bg_rgb(c.r, c.g, c.b, msg)
|
||||
}
|
||||
|
||||
return term.bg_rgb(c.r, c.g, c.b, msg)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue