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

Rename .apply to .color

This commit is contained in:
RGBCube 2022-11-18 20:13:36 +03:00
parent 7a2ae90fb3
commit a4617fa1e2
8 changed files with 19 additions and 19 deletions

View file

@ -9,8 +9,8 @@ An easier way to print colored text to the terminal
```v
import color
println(color.red.apply('Hello World'))
println(color.bold.apply('Hello World'))
println(color.red.color('Hello World'))
println(color.bold.color('Hello World'))
```
## Advanced
@ -24,5 +24,5 @@ p := color.PaintBrush{
styles: [color.bold, color.underline, color.italic]
}
print(p.apply('Hello World'))
print(p.color('Hello World'))
```

View file

@ -3,6 +3,6 @@ module main
import color
fn main() {
println(color.red.apply('Hello World'))
println(color.bold.apply('Hello World'))
println(color.red.color('Hello World'))
println(color.bold.color('Hello World'))
}

View file

@ -9,5 +9,5 @@ fn main() {
styles: [color.bold, color.underline, color.italic]
}
print(p.apply('Hello World'))
print(p.color('Hello World'))
}

View file

@ -40,7 +40,7 @@ enum BasicColor {
bright_white
}
pub fn (c BasicColor) apply(msg string) string {
pub fn (c BasicColor) color(msg string) string {
func := match c {
.black { term.black }
.red { term.red }
@ -62,7 +62,7 @@ pub fn (c BasicColor) apply(msg string) string {
return func(msg)
}
pub fn (c BasicColor) apply_bg(msg string) string {
pub fn (c BasicColor) color_bg(msg string) string {
func := match c {
.black { term.bg_black }
.red { term.bg_red }

View file

@ -3,10 +3,10 @@ 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) color(msg string) string {
return c.color(msg)
}
fn (c Color) apply_bg(msg string) string {
return c.apply_bg(msg)
fn (c Color) color_bg(msg string) string {
return c.color_bg(msg)
}

View file

@ -11,7 +11,7 @@ pub:
styles []Style
}
pub fn (p &PaintBrush) apply(msg string) string {
pub fn (p &PaintBrush) color(msg string) string {
if !color.can_show_color {
return msg
}
@ -19,14 +19,14 @@ pub fn (p &PaintBrush) apply(msg string) string {
mut result := msg
if fg := p.fg {
result = fg.apply(result)
result = fg.color(result)
}
if bg := p.bg {
result = bg.apply(result)
result = bg.color(result)
}
for style in p.styles {
result = style.apply(result)
result = style.color(result)
}
return result

View file

@ -28,7 +28,7 @@ enum Style {
strikethrough
}
pub fn (s Style) apply(msg string) string {
pub fn (s Style) color(msg string) string {
func := match s {
.reset { term.reset }
.bold { term.bold }

View file

@ -25,10 +25,10 @@ pub:
b int
}
pub fn (c TrueColor) apply(msg string) string {
pub fn (c TrueColor) color(msg string) string {
return term.rgb(c.r, c.g, c.b, msg)
}
pub fn (c TrueColor) apply_bg(msg string) string {
pub fn (c TrueColor) color_bg(msg string) string {
return term.bg_rgb(c.r, c.g, c.b, msg)
}