scripts: treemaps: Fixed crashes when there's nothing to show

Crashing on invalid input isn't the _worst_ behavior, but with a few
tweaks we can make these scripts more-or-less noop in such cases. This
is useful when running with -k/--keep-open since intermediate file
states often contain garbage.

(Ironically one of the precise problems littlefs is trying to solve.)

Also added a special case to treemap.py/codemap.py to not output the
canvas if there's nothing to show and height is implicit. Otherwise the
history mode with -n/--lines ends up filled with blank lines.

Note this makes -H1 subtly different from no -H/--height, with -H1
printing a blank line if there is nothing to show. The -H1 behavior may
also be useful in niche cases where you want that part of the screen
cleared.

---

This was found while trying to run codemap.py -k -n5 during compilation.
GCC writes object files incrementally, and this was breaking our script.
This commit is contained in:
Christopher Haster
2025-04-10 19:28:29 -05:00
parent fc5bfdae14
commit cb5cbb9241
3 changed files with 26 additions and 0 deletions

View File

@ -1090,6 +1090,11 @@ def main_(f, csv_paths, *,
((tile.value * to_scale) / (width_*xscale))
/ yscale)
# as a special case, if height is implicit and we have nothing to
# show, don't print anything
if height is None and tile.value == 0:
height_ = 1 if not no_header else 0
# create a canvas
canvas = Canvas(
width_,