mirror of
https://github.com/RGBCube/color.v
synced 2025-08-01 10:27:45 +00:00
Use u8 instead of i32(int) for TrueColor
This will save memory
This commit is contained in:
parent
5895b61733
commit
cfe0f2a2c3
2 changed files with 8 additions and 12 deletions
|
@ -20,8 +20,8 @@ color.bold.cprintln('Hello World')
|
||||||
import color
|
import color
|
||||||
|
|
||||||
brush := color.new_brush(
|
brush := color.new_brush(
|
||||||
fg: color.rgb(0, 0, 0)!
|
fg: color.rgb(0, 0, 0)
|
||||||
bg: color.hex(0xffffff)!
|
bg: color.hex(0xffffff)
|
||||||
style: [color.bold, color.underline, color.italic]
|
style: [color.bold, color.underline, color.italic]
|
||||||
)!
|
)!
|
||||||
|
|
||||||
|
|
|
@ -2,11 +2,7 @@ module color
|
||||||
|
|
||||||
import term
|
import term
|
||||||
|
|
||||||
pub fn rgb(r int, g int, b int) !Color {
|
pub fn rgb(r u8, g u8, b u8) Color {
|
||||||
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 TrueColor{
|
return TrueColor{
|
||||||
r: r
|
r: r
|
||||||
g: g
|
g: g
|
||||||
|
@ -14,14 +10,14 @@ pub fn rgb(r int, g int, b int) !Color {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn hex(hex int) !Color {
|
pub fn hex(hex int) Color {
|
||||||
return rgb(hex >> 16, hex >> 8 & 0xFF, hex & 0xFF)!
|
return rgb(u8(hex >> 16), u8(hex >> 8 & 0xFF), u8(hex & 0xFF))
|
||||||
}
|
}
|
||||||
|
|
||||||
struct TrueColor {
|
struct TrueColor {
|
||||||
r int
|
r u8
|
||||||
g int
|
g u8
|
||||||
b int
|
b u8
|
||||||
}
|
}
|
||||||
|
|
||||||
fn (c TrueColor) render(msg string) string {
|
fn (c TrueColor) render(msg string) string {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue