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:
parent
00ee837156
commit
b5cf7edd09
5 changed files with 25 additions and 37 deletions
|
@ -4,8 +4,8 @@ import color
|
||||||
|
|
||||||
fn main() {
|
fn main() {
|
||||||
p := color.PaintBrush{
|
p := color.PaintBrush{
|
||||||
fg: color.rgb(0, 0, 0)!,
|
fg: color.rgb(0, 0, 0)!
|
||||||
bg: color.hex(0xffffff)!,
|
bg: color.hex(0xffffff)!
|
||||||
styles: [color.bold, color.underline, color.italic]
|
styles: [color.bold, color.underline, color.italic]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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) }
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -1,14 +1,15 @@
|
||||||
module color
|
module color
|
||||||
|
|
||||||
import term
|
import term
|
||||||
import datatypes
|
|
||||||
|
type Color = BasicColor | TrueColor
|
||||||
|
|
||||||
const can_show_color = term.can_show_color_on_stdout()
|
const can_show_color = term.can_show_color_on_stdout()
|
||||||
|
|
||||||
pub struct PaintBrush {
|
pub struct PaintBrush {
|
||||||
pub:
|
pub:
|
||||||
fg Color = no_color
|
fg ?Color
|
||||||
bg Color = no_color
|
bg ?Color
|
||||||
styles []Style
|
styles []Style
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -17,7 +18,15 @@ pub fn (p &PaintBrush) apply(msg string) string {
|
||||||
return msg
|
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 {
|
for style in p.styles {
|
||||||
result = style.apply(result)
|
result = style.apply(result)
|
||||||
|
|
|
@ -35,8 +35,8 @@ pub fn (s Style) apply(msg string) string {
|
||||||
.dim { term.dim }
|
.dim { term.dim }
|
||||||
.italic { term.italic }
|
.italic { term.italic }
|
||||||
.underline { term.underline }
|
.underline { term.underline }
|
||||||
//.slow_blink { term.slow_blink }
|
// .slow_blink { term.slow_blink }
|
||||||
//.rapid_blink { term.rapid_blink }
|
// .rapid_blink { term.rapid_blink }
|
||||||
.inverse { term.inverse }
|
.inverse { term.inverse }
|
||||||
.hidden { term.hidden }
|
.hidden { term.hidden }
|
||||||
.strikethrough { term.strikethrough }
|
.strikethrough { term.strikethrough }
|
||||||
|
|
|
@ -2,14 +2,6 @@ module color
|
||||||
|
|
||||||
import term
|
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 {
|
pub fn rgb(r int, g int, b int) !TrueColor {
|
||||||
if r < 0 || r > 255 || g < 0 || g > 255 || b < 0 || b > 255 {
|
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')
|
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)!
|
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 {
|
pub fn (c TrueColor) apply(msg string) string {
|
||||||
return term.rgb(c.r, c.g, c.b, msg)
|
return term.rgb(c.r, c.g, c.b, msg)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue