1
Fork 0
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:
Pringlers 2022-11-20 20:01:32 +09:00 committed by GitHub
parent 5895b61733
commit cfe0f2a2c3
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 8 additions and 12 deletions

View file

@ -20,8 +20,8 @@ color.bold.cprintln('Hello World')
import color
brush := color.new_brush(
fg: color.rgb(0, 0, 0)!
bg: color.hex(0xffffff)!
fg: color.rgb(0, 0, 0)
bg: color.hex(0xffffff)
style: [color.bold, color.underline, color.italic]
)!

View file

@ -2,11 +2,7 @@ module color
import term
pub fn rgb(r int, g int, b int) !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')
}
pub fn rgb(r u8, g u8, b u8) Color {
return TrueColor{
r: r
g: g
@ -14,14 +10,14 @@ pub fn rgb(r int, g int, b int) !Color {
}
}
pub fn hex(hex int) !Color {
return rgb(hex >> 16, hex >> 8 & 0xFF, hex & 0xFF)!
pub fn hex(hex int) Color {
return rgb(u8(hex >> 16), u8(hex >> 8 & 0xFF), u8(hex & 0xFF))
}
struct TrueColor {
r int
g int
b int
r u8
g u8
b u8
}
fn (c TrueColor) render(msg string) string {