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 ```v
import color import color
println(color.red.apply('Hello World')) println(color.red.color('Hello World'))
println(color.bold.apply('Hello World')) println(color.bold.color('Hello World'))
``` ```
## Advanced ## Advanced
@ -24,5 +24,5 @@ p := color.PaintBrush{
styles: [color.bold, color.underline, color.italic] 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 import color
fn main() { fn main() {
println(color.red.apply('Hello World')) println(color.red.color('Hello World'))
println(color.bold.apply('Hello World')) println(color.bold.color('Hello World'))
} }

View file

@ -9,5 +9,5 @@ fn main() {
styles: [color.bold, color.underline, color.italic] 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 bright_white
} }
pub fn (c BasicColor) apply(msg string) string { pub fn (c BasicColor) color(msg string) string {
func := match c { func := match c {
.black { term.black } .black { term.black }
.red { term.red } .red { term.red }
@ -62,7 +62,7 @@ pub fn (c BasicColor) apply(msg string) string {
return func(msg) return func(msg)
} }
pub fn (c BasicColor) apply_bg(msg string) string { pub fn (c BasicColor) color_bg(msg string) string {
func := match c { func := match c {
.black { term.bg_black } .black { term.bg_black }
.red { term.bg_red } .red { term.bg_red }

View file

@ -3,10 +3,10 @@ module color
type Color = BasicColor | TrueColor type Color = BasicColor | TrueColor
// I have no idea why this is needed // I have no idea why this is needed
fn (c Color) apply(msg string) string { fn (c Color) color(msg string) string {
return c.apply(msg) return c.color(msg)
} }
fn (c Color) apply_bg(msg string) string { fn (c Color) color_bg(msg string) string {
return c.apply_bg(msg) return c.color_bg(msg)
} }

View file

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

View file

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

View file

@ -25,10 +25,10 @@ pub:
b int 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) 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) return term.bg_rgb(c.r, c.g, c.b, msg)
} }