diff options
author | cc <cc@localhost> | 2025-08-28 02:02:37 -0700 |
---|---|---|
committer | cc <cc@localhost> | 2025-08-28 02:02:58 -0700 |
commit | b2bb714ad8287a33a1ee399999e340471b0bb4b4 (patch) | |
tree | 9a7567ef8e8cbd9dab0dc91f4c33e2ef2100ed3c /src/lib.rs | |
parent | 6b82dd150073836e57a148d7eccae5276b9baea7 (diff) |
Unifying label formats
Diffstat (limited to 'src/lib.rs')
-rw-r--r-- | src/lib.rs | 58 |
1 files changed, 25 insertions, 33 deletions
@@ -1,16 +1,14 @@ -mod large_label_format; mod label_format; pub mod binfile; -pub use large_label_format::LargeLabelFormat; -pub use label_format::LabelFormat; +use crate::label_format::{LabelFormat,LabelU16}; -pub(crate) fn flood_u32(source: &LargeLabelFormat, destination: &mut Vec<u16>, +pub(crate) fn flood<T: LabelU16 + PartialEq + Copy, R: LabelU16 + PartialEq + Copy>(source: &LabelFormat<T>, destination: &mut Vec<R>, x: usize, y: usize, - from_color: u32, to_color: u16) { + from_color: T, to_color: R) { let width = source.width; let destination_color = destination[x + y * width]; - if destination_color != 0 { + if destination_color != destination_color.zero() { return; } let source_color = source.buffer[x + y * width]; @@ -19,42 +17,36 @@ pub(crate) fn flood_u32(source: &LargeLabelFormat, destination: &mut Vec<u16>, } destination[x + y * width] = to_color; if x > 0 { - flood_u32(source, destination, x-1, y, from_color, to_color); + flood(source, destination, x-1, y, from_color, to_color); } if (x+1) < width { - flood_u32(source, destination, x+1, y, from_color, to_color); + flood(source, destination, x+1, y, from_color, to_color); } if y > 0 { - flood_u32(source, destination, x, y-1, from_color, to_color); + flood(source, destination, x, y-1, from_color, to_color); } if (y+1) < source.height { - flood_u32(source, destination, x, y+1, from_color, to_color); + flood(source, destination, x, y+1, from_color, to_color); } } -pub(crate) fn flood_u16(source: &LabelFormat, destination: &mut Vec<u16>, - x: usize, y: usize, - from_color: u16, to_color: u16) { - let width = source.width; - let destination_color = destination[x + y * width]; - if destination_color != 0 { - return; +pub(crate) mod color { + pub(crate) fn reset_color() { + print!("\x1b[0m"); } - let source_color = source.buffer[x + y * width]; - if source_color != from_color { - return; - } - destination[x + y * width] = to_color; - if x > 0 { - flood_u16(source, destination, x-1, y, from_color, to_color); - } - if (x+1) < width { - flood_u16(source, destination, x+1, y, from_color, to_color); - } - if y > 0 { - flood_u16(source, destination, x, y-1, from_color, to_color); - } - if (y+1) < source.height { - flood_u16(source, destination, x, y+1, from_color, to_color); + + // Set background color from a number + pub(crate) fn set_color(color: usize) { + if color == 0 { + reset_color(); + return; + } + let paint_color = color-1; + let paint_color = paint_color % 13; + if paint_color < 7 { + print!("\x1b[{}m", 40 + (paint_color+1)); + } else { + print!("\x1b[{}m", 100 + (paint_color+1-7)); + } } } |