add experimental null char handling

This commit is contained in:
Vinzenz Schroeter 2025-07-12 13:57:19 +02:00
parent c3b9ecf402
commit 5dcdd0f311
3 changed files with 34 additions and 11 deletions

View file

@ -22,6 +22,11 @@ pub struct Cli {
help = "Set default log level lower. You can also change this via the RUST_LOG environment variable." help = "Set default log level lower. You can also change this via the RUST_LOG environment variable."
)] )]
pub verbose: bool, pub verbose: bool,
#[arg(
long,
help = "When receiving a null byte as a char in the CharGridCommand, do not overwrite any pixels instead of clearing all pixels."
)]
pub experimental_null_char_handling: bool,
} }
#[derive(Parser, Debug)] #[derive(Parser, Debug)]

View file

@ -22,6 +22,7 @@ pub struct CommandExecutionContext<'t> {
luma: &'t RwLock<BrightnessGrid>, luma: &'t RwLock<BrightnessGrid>,
cp437_font: Cp437Font, cp437_font: Cp437Font,
font_renderer: FontRenderer8x8, font_renderer: FontRenderer8x8,
experimental_null_char_handling: bool,
} }
#[must_use] #[must_use]
@ -193,20 +194,30 @@ impl CommandExecute for CharGridCommand {
for char_y in 0usize..grid.height() { for char_y in 0usize..grid.height() {
for char_x in 0usize..grid.width() { for char_x in 0usize..grid.width() {
let char = grid.get(char_x, char_y); let char = grid.get(char_x, char_y);
trace!("drawing {char}"); let mut bitmap_window = {
let pixel_x = (char_x + x) * TILE_SIZE;
let pixel_x = (char_x + x) * TILE_SIZE; let pixel_y = (char_y + y) * TILE_SIZE;
let pixel_y = (char_y + y) * TILE_SIZE; display
if let Err(e) = context.font_renderer.render(
char,
&mut display
.window_mut( .window_mut(
pixel_x..pixel_x + TILE_SIZE, pixel_x..pixel_x + TILE_SIZE,
pixel_y..pixel_y + TILE_SIZE, pixel_y..pixel_y + TILE_SIZE,
) )
.unwrap(), .unwrap()
) { };
if char == '\0' {
if context.experimental_null_char_handling {
trace!("skipping {char:?}");
} else {
bitmap_window.fill(false);
}
continue;
}
trace!("drawing {char}");
if let Err(e) =
context.font_renderer.render(char, &mut bitmap_window)
{
error!( error!(
"stopping drawing text because char draw failed: {e}" "stopping drawing text because char draw failed: {e}"
); );
@ -256,12 +267,14 @@ impl<'t> CommandExecutionContext<'t> {
display: &'t RwLock<Bitmap>, display: &'t RwLock<Bitmap>,
luma: &'t RwLock<BrightnessGrid>, luma: &'t RwLock<BrightnessGrid>,
font_renderer: FontRenderer8x8, font_renderer: FontRenderer8x8,
experimental_null_char_handling: bool,
) -> Self { ) -> Self {
CommandExecutionContext { CommandExecutionContext {
display, display,
luma, luma,
font_renderer, font_renderer,
cp437_font: Cp437Font::default(), cp437_font: Cp437Font::default(),
experimental_null_char_handling,
} }
} }
} }

View file

@ -39,7 +39,12 @@ fn main() {
.font .font
.map(FontRenderer8x8::from_name) .map(FontRenderer8x8::from_name)
.unwrap_or_else(FontRenderer8x8::default); .unwrap_or_else(FontRenderer8x8::default);
let context = CommandExecutionContext::new(&display, &luma, font_renderer); let context = CommandExecutionContext::new(
&display,
&luma,
font_renderer,
cli.experimental_null_char_handling,
);
let mut udp_server = UdpServer::new( let mut udp_server = UdpServer::new(
cli.bind, cli.bind,
stop_udp_rx, stop_udp_rx,