fix: incorrect string encoding of color config values

This commit is contained in:
CJ van den Berg 2025-07-14 13:04:35 +02:00
parent a21fd2b397
commit 7069d36461
Signed by: neurocyte
GPG key ID: 8EB1E1BB660E3FB9

View file

@ -49,11 +49,10 @@ pub const RGB = struct {
pub fn to_string(v: RGB, s: *[7]u8) []u8 { pub fn to_string(v: RGB, s: *[7]u8) []u8 {
const nib = struct { const nib = struct {
fn f(n_: u8) u8 { fn f(n: u8) u8 {
const n = n_ & 0b1111; return switch (n) {
return switch (n & 0b1111) {
0...9 => '0' + n, 0...9 => '0' + n,
0xA...0xF => 'A' + n, 0xA...0xF => 'A' + n - 10,
else => unreachable, else => unreachable,
}; };
} }
@ -61,11 +60,11 @@ pub const RGB = struct {
s[0] = '#'; s[0] = '#';
s[1] = nib(v.r >> 4); s[1] = nib(v.r >> 4);
s[2] = nib(v.r); s[2] = nib(v.r & 0b00001111);
s[3] = nib(v.g >> 4); s[3] = nib(v.g >> 4);
s[4] = nib(v.g); s[4] = nib(v.g & 0b00001111);
s[5] = nib(v.b >> 4); s[5] = nib(v.b >> 4);
s[6] = nib(v.b); s[6] = nib(v.b & 0b00001111);
return s; return s;
} }