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

Use upcomping features

This commit is contained in:
RGBCube 2022-11-18 19:56:40 +03:00
parent 00ee837156
commit b5cf7edd09
5 changed files with 25 additions and 37 deletions

View file

@ -4,8 +4,8 @@ import color
fn main() {
p := color.PaintBrush{
fg: color.rgb(0, 0, 0)!,
bg: color.hex(0xffffff)!,
fg: color.rgb(0, 0, 0)!
bg: color.hex(0xffffff)!
styles: [color.bold, color.underline, color.italic]
}

View file

@ -1,21 +0,0 @@
module color
type Color = BasicColor | NoColor | TrueColor
const no_color = NoColor{}
struct NoColor {}
fn (c Color) apply(msg string) string {
return match c {
NoColor { msg }
else { c.apply(msg) }
}
}
fn (c Color) apply_bg(msg string) string {
return match c {
NoColor { msg }
else { c.apply_bg(msg) }
}
}

View file

@ -1,14 +1,15 @@
module color
import term
import datatypes
type Color = BasicColor | TrueColor
const can_show_color = term.can_show_color_on_stdout()
pub struct PaintBrush {
pub:
fg Color = no_color
bg Color = no_color
fg ?Color
bg ?Color
styles []Style
}
@ -17,7 +18,15 @@ pub fn (p &PaintBrush) apply(msg string) string {
return msg
}
mut result := p.bg.apply(p.fg.apply(msg))
mut result := msg
// IS NOT IMPLEMENTED YET !!!
if fg := p.fg {
result = fg.apply(result)
}
if bg := p.bg {
result = bg.apply(result)
}
for style in p.styles {
result = style.apply(result)

View file

@ -35,8 +35,8 @@ pub fn (s Style) apply(msg string) string {
.dim { term.dim }
.italic { term.italic }
.underline { term.underline }
//.slow_blink { term.slow_blink }
//.rapid_blink { term.rapid_blink }
// .slow_blink { term.slow_blink }
// .rapid_blink { term.rapid_blink }
.inverse { term.inverse }
.hidden { term.hidden }
.strikethrough { term.strikethrough }

View file

@ -2,14 +2,6 @@ module color
import term
[noinit]
struct TrueColor {
pub:
r int [required]
g int [required]
b int [required]
}
pub fn rgb(r int, g int, b int) !TrueColor {
if r < 0 || r > 255 || g < 0 || g > 255 || b < 0 || b > 255 {
return error('Red, green and blue must each be between 0 and 255')
@ -25,6 +17,14 @@ pub fn hex(hex int) !TrueColor {
return rgb(hex >> 16, hex >> 8 & 0xFF, hex & 0xFF)!
}
[noinit]
struct TrueColor {
pub:
r int
g int
b int
}
pub fn (c TrueColor) apply(msg string) string {
return term.rgb(c.r, c.g, c.b, msg)
}