make screen panic messages somewhat more useful

some panic messages are hundreds of characters long, most of them
are path hashes or paths to crates that are less useful.

truncate any panic messages to the last set of displayable
characters, so that the "most useful" portion (e.g. file name
and line number) are always visible in a panic.
This commit is contained in:
bunnie 2025-11-28 18:41:53 +08:00
parent 106f7153a1
commit 3b1784d346

View file

@ -124,7 +124,17 @@ pub(crate) fn panic_handler_thread(
}
.get();
let s = unsafe { core::str::from_utf8_unchecked(&body.buf.as_slice()[..len]) };
append_string(s, &mut display);
const MAX_CHARS: usize = 7 * 18; // 7 lines by 18 characters is what the display can hold
if s.chars().count() <= MAX_CHARS {
append_string(s, &mut display);
} else {
// truncate very long panic messages to just show the *end* as that contains the useful
// information (the front tends to be stuff like path information in the build)
append_string(
s.char_indices().rev().take(MAX_CHARS).last().map(|(i, _)| &s[i..]).unwrap(),
&mut display,
);
}
display.draw();
}
}