scripts: Gave explicit chars priority over braille/dots

This allows for combining braille/dots with custom chars for specific
elements:

  $ ./scripts/codemap.py lfs.o -H16 -: -.lfsr_rbyd_appendrattr=A

Note this is already how plot.py works, letting braille/dots take
priority in the new scripts/reworks was just an oversight.
This commit is contained in:
Christopher Haster
2025-04-10 14:27:58 -05:00
parent edc6c7ec99
commit 2fb115b84b
4 changed files with 49 additions and 34 deletions

View File

@@ -1100,18 +1100,24 @@ def main_(f, paths, *,
# assign colors/chars/labels to code tiles
for i, t in enumerate(code.leaves()):
t.color = subsystems[t.attrs['subsystem']]['color']
if (i, t.attrs['name']) in chars_:
char__ = chars_[i, t.attrs['name']]
if isinstance(char__, str):
# don't punescape unless we have to
if '%' in char__:
char__ = punescape(char__, t.attrs['attrs'] | t.attrs)
t.char = char__[0] # limit to 1 char
char__ = char__[0] # limit to 1 char
t.char = char__
elif braille or dots:
t.char = True
elif len(t.attrs['subsystem']) < len(t.attrs['name']):
t.char = (t.attrs['name'][len(t.attrs['subsystem']):].lstrip('_')
or '')[0]
else:
t.char = (t.attrs['subsystem'].rstrip('_').rsplit('_', 1)[-1]
or '')[0]
if (i, t.attrs['name']) in labels_:
label__ = labels_[i, t.attrs['name']]
# don't punescape unless we have to
@@ -1254,8 +1260,8 @@ def main_(f, paths, *,
canvas.rect(x__, y__, width__, height__,
# default to first letter of the last part of the key
char=(True if braille or dots
else t.char if getattr(t, 'char', None)
char=(t.char if getattr(t, 'char', None) is not None
else True if braille or dots
else t.key[len(by)-1][0] if t.key and t.key[len(by)-1]
else chars_[0]),
color=t.color if t.color is not None else colors_[0])

View File

@@ -4339,7 +4339,7 @@ def main_(f, disk, mroots=None, *,
chars_.extend((char[0], c) for c in psplit(char[1]))
else:
chars_.extend(psplit(char))
chars_ = Attr(chars_, defaults=CHARS)
chars_ = Attr(chars_, defaults=[True] if braille or dots else CHARS)
colors_ = Attr(colors, defaults=COLORS)
@@ -4584,10 +4584,12 @@ def main_(f, disk, mroots=None, *,
for type in [b.type] + (['unused'] if args.get('usage') else []):
char__ = chars_[b.block, (type, '0x%x' % b.block)]
if char__ is not None:
if isinstance(char__, str):
# don't punescape unless we have to
if '%' in char__:
char__ = punescape(char__, b.attrs)
b.chars[type] = char__[0] # limit to 1 char
char__ = char__[0] # limit to 1 char
b.chars[type] = char__
# assign colors based on block type
for b in bmap.values():
@@ -4651,7 +4653,7 @@ def main_(f, disk, mroots=None, *,
y__ = canvas.height - (y__+1)
canvas.point(x__, y__,
char=True if braille or dots else b.chars[type],
char=b.chars[type],
color=b.colors[type])
# blocky?
@@ -4680,14 +4682,13 @@ def main_(f, disk, mroots=None, *,
if i in usage__:
# flip y
canvas.point(x__+dx, y__+(height__-(dy+1)),
char=True if braille or dots
else b.chars[type],
char=b.chars[type],
color=b.colors[type])
# render simple blocks
else:
canvas.rect(x__, y__, width__, height__,
char=True if braille or dots else b.chars[type],
char=b.chars[type],
color=b.colors[type])
# print some summary info

View File

@@ -1457,7 +1457,8 @@ def main(path='-', *,
chars_.extend((char[0], c) for c in psplit(char[1]))
else:
chars_.extend(psplit(char))
chars_ = Attr(chars_, defaults=CHARS)
chars_ = Attr(chars_,
defaults=[True] if braille or dots else CHARS)
wear_chars_ = []
for char in wear_chars:
@@ -1465,7 +1466,8 @@ def main(path='-', *,
wear_chars_.extend((char[0], c) for c in psplit(char[1]))
else:
wear_chars_.extend(psplit(char))
wear_chars_ = Attr(wear_chars_, defaults=WEAR_CHARS)
wear_chars_ = Attr(wear_chars_,
defaults=[True] if braille or dots else WEAR_CHARS)
colors_ = Attr(colors, defaults=COLORS)
@@ -1828,10 +1830,12 @@ def main(path='-', *,
+ ['noop']):
char__ = chars_.get((b.block, (op, '0x%x' % b.block)))
if char__ is not None:
if isinstance(char__, str):
# don't punescape unless we have to
if '%' in char__:
char__ = punescape(char__, b.attrs)
b.chars[op] = char__[0] # limit to 1 char
char__ = char__[0] # limit to 1 char
b.chars[op] = char__
# assign colors based on op + block
for b in bmap.values():
@@ -1852,10 +1856,12 @@ def main(path='-', *,
for b in bmap.values():
b.wear_chars = []
for char__ in wear_chars_.getall((b.block, '0x%x' % b.block)):
if isinstance(char__, str):
# don't punescape unless we have to
if '%' in char__:
char__ = punescape(char__, b.attrs)
b.wear_chars.append(char__[0]) # limit to 1 char
char__ = char__[0] # limit to 1 char
b.wear_chars.append(char__)
# assign wear colors based on block
if wear:
@@ -1939,7 +1945,7 @@ def main(path='-', *,
y__ = canvas.height - (y__+1)
canvas.point(x__, y__,
char=True if braille or dots else char__,
char=char__,
color=color__)
# blocky?
@@ -1964,8 +1970,7 @@ def main(path='-', *,
if i in range__:
# flip y
canvas.point(x__+dx, y__+(height__-(dy+1)),
char=True if braille or dots
else char__,
char=char__,
color=color__)
# print some summary info

View File

@@ -988,10 +988,13 @@ def main_(f, csv_paths, *,
for i, t in enumerate(tile.leaves()):
if (i, t.key) in chars_:
char__ = chars_[i, t.key]
if isinstance(char__, str):
# don't punescape unless we have to
if '%' in char__:
char__ = punescape(char__, t.attrs)
t.char = char__[0] # limit to 1 char
char__ = char__[0] # limit to 1 char
t.char = char__
if (i, t.key) in labels_:
label__ = labels_[i, t.key]
# don't punescape unless we have to
@@ -1133,8 +1136,8 @@ def main_(f, csv_paths, *,
canvas.rect(x__, y__, width__, height__,
# default to first letter of the last part of the key
char=(True if braille or dots
else t.char if getattr(t, 'char', None)
char=(t.char if getattr(t, 'char', None) is not None
else True if braille or dots
else t.key[len(by)-1][0] if t.key and t.key[len(by)-1]
else chars_[0]),
color=t.color if t.color is not None else colors_[0])