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:
+12
-6
@@ -1100,18 +1100,24 @@ def main_(f, paths, *,
|
|||||||
# assign colors/chars/labels to code tiles
|
# assign colors/chars/labels to code tiles
|
||||||
for i, t in enumerate(code.leaves()):
|
for i, t in enumerate(code.leaves()):
|
||||||
t.color = subsystems[t.attrs['subsystem']]['color']
|
t.color = subsystems[t.attrs['subsystem']]['color']
|
||||||
|
|
||||||
if (i, t.attrs['name']) in chars_:
|
if (i, t.attrs['name']) in chars_:
|
||||||
char__ = chars_[i, t.attrs['name']]
|
char__ = chars_[i, t.attrs['name']]
|
||||||
# don't punescape unless we have to
|
if isinstance(char__, str):
|
||||||
if '%' in char__:
|
# don't punescape unless we have to
|
||||||
char__ = punescape(char__, t.attrs['attrs'] | t.attrs)
|
if '%' in char__:
|
||||||
t.char = char__[0] # limit to 1 char
|
char__ = punescape(char__, t.attrs['attrs'] | t.attrs)
|
||||||
|
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']):
|
elif len(t.attrs['subsystem']) < len(t.attrs['name']):
|
||||||
t.char = (t.attrs['name'][len(t.attrs['subsystem']):].lstrip('_')
|
t.char = (t.attrs['name'][len(t.attrs['subsystem']):].lstrip('_')
|
||||||
or '')[0]
|
or '')[0]
|
||||||
else:
|
else:
|
||||||
t.char = (t.attrs['subsystem'].rstrip('_').rsplit('_', 1)[-1]
|
t.char = (t.attrs['subsystem'].rstrip('_').rsplit('_', 1)[-1]
|
||||||
or '')[0]
|
or '')[0]
|
||||||
|
|
||||||
if (i, t.attrs['name']) in labels_:
|
if (i, t.attrs['name']) in labels_:
|
||||||
label__ = labels_[i, t.attrs['name']]
|
label__ = labels_[i, t.attrs['name']]
|
||||||
# don't punescape unless we have to
|
# don't punescape unless we have to
|
||||||
@@ -1254,8 +1260,8 @@ def main_(f, paths, *,
|
|||||||
|
|
||||||
canvas.rect(x__, y__, width__, height__,
|
canvas.rect(x__, y__, width__, height__,
|
||||||
# default to first letter of the last part of the key
|
# default to first letter of the last part of the key
|
||||||
char=(True if braille or dots
|
char=(t.char if getattr(t, 'char', None) is not None
|
||||||
else t.char if getattr(t, 'char', None)
|
else True if braille or dots
|
||||||
else t.key[len(by)-1][0] if t.key and t.key[len(by)-1]
|
else t.key[len(by)-1][0] if t.key and t.key[len(by)-1]
|
||||||
else chars_[0]),
|
else chars_[0]),
|
||||||
color=t.color if t.color is not None else colors_[0])
|
color=t.color if t.color is not None else colors_[0])
|
||||||
|
|||||||
+10
-9
@@ -4339,7 +4339,7 @@ def main_(f, disk, mroots=None, *,
|
|||||||
chars_.extend((char[0], c) for c in psplit(char[1]))
|
chars_.extend((char[0], c) for c in psplit(char[1]))
|
||||||
else:
|
else:
|
||||||
chars_.extend(psplit(char))
|
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)
|
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 []):
|
for type in [b.type] + (['unused'] if args.get('usage') else []):
|
||||||
char__ = chars_[b.block, (type, '0x%x' % b.block)]
|
char__ = chars_[b.block, (type, '0x%x' % b.block)]
|
||||||
if char__ is not None:
|
if char__ is not None:
|
||||||
# don't punescape unless we have to
|
if isinstance(char__, str):
|
||||||
if '%' in char__:
|
# don't punescape unless we have to
|
||||||
char__ = punescape(char__, b.attrs)
|
if '%' in char__:
|
||||||
b.chars[type] = char__[0] # limit to 1 char
|
char__ = punescape(char__, b.attrs)
|
||||||
|
char__ = char__[0] # limit to 1 char
|
||||||
|
b.chars[type] = char__
|
||||||
|
|
||||||
# assign colors based on block type
|
# assign colors based on block type
|
||||||
for b in bmap.values():
|
for b in bmap.values():
|
||||||
@@ -4651,7 +4653,7 @@ def main_(f, disk, mroots=None, *,
|
|||||||
y__ = canvas.height - (y__+1)
|
y__ = canvas.height - (y__+1)
|
||||||
|
|
||||||
canvas.point(x__, y__,
|
canvas.point(x__, y__,
|
||||||
char=True if braille or dots else b.chars[type],
|
char=b.chars[type],
|
||||||
color=b.colors[type])
|
color=b.colors[type])
|
||||||
|
|
||||||
# blocky?
|
# blocky?
|
||||||
@@ -4680,14 +4682,13 @@ def main_(f, disk, mroots=None, *,
|
|||||||
if i in usage__:
|
if i in usage__:
|
||||||
# flip y
|
# flip y
|
||||||
canvas.point(x__+dx, y__+(height__-(dy+1)),
|
canvas.point(x__+dx, y__+(height__-(dy+1)),
|
||||||
char=True if braille or dots
|
char=b.chars[type],
|
||||||
else b.chars[type],
|
|
||||||
color=b.colors[type])
|
color=b.colors[type])
|
||||||
|
|
||||||
# render simple blocks
|
# render simple blocks
|
||||||
else:
|
else:
|
||||||
canvas.rect(x__, y__, width__, height__,
|
canvas.rect(x__, y__, width__, height__,
|
||||||
char=True if braille or dots else b.chars[type],
|
char=b.chars[type],
|
||||||
color=b.colors[type])
|
color=b.colors[type])
|
||||||
|
|
||||||
# print some summary info
|
# print some summary info
|
||||||
|
|||||||
+18
-13
@@ -1457,7 +1457,8 @@ def main(path='-', *,
|
|||||||
chars_.extend((char[0], c) for c in psplit(char[1]))
|
chars_.extend((char[0], c) for c in psplit(char[1]))
|
||||||
else:
|
else:
|
||||||
chars_.extend(psplit(char))
|
chars_.extend(psplit(char))
|
||||||
chars_ = Attr(chars_, defaults=CHARS)
|
chars_ = Attr(chars_,
|
||||||
|
defaults=[True] if braille or dots else CHARS)
|
||||||
|
|
||||||
wear_chars_ = []
|
wear_chars_ = []
|
||||||
for char in 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]))
|
wear_chars_.extend((char[0], c) for c in psplit(char[1]))
|
||||||
else:
|
else:
|
||||||
wear_chars_.extend(psplit(char))
|
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)
|
colors_ = Attr(colors, defaults=COLORS)
|
||||||
|
|
||||||
@@ -1828,10 +1830,12 @@ def main(path='-', *,
|
|||||||
+ ['noop']):
|
+ ['noop']):
|
||||||
char__ = chars_.get((b.block, (op, '0x%x' % b.block)))
|
char__ = chars_.get((b.block, (op, '0x%x' % b.block)))
|
||||||
if char__ is not None:
|
if char__ is not None:
|
||||||
# don't punescape unless we have to
|
if isinstance(char__, str):
|
||||||
if '%' in char__:
|
# don't punescape unless we have to
|
||||||
char__ = punescape(char__, b.attrs)
|
if '%' in char__:
|
||||||
b.chars[op] = char__[0] # limit to 1 char
|
char__ = punescape(char__, b.attrs)
|
||||||
|
char__ = char__[0] # limit to 1 char
|
||||||
|
b.chars[op] = char__
|
||||||
|
|
||||||
# assign colors based on op + block
|
# assign colors based on op + block
|
||||||
for b in bmap.values():
|
for b in bmap.values():
|
||||||
@@ -1852,10 +1856,12 @@ def main(path='-', *,
|
|||||||
for b in bmap.values():
|
for b in bmap.values():
|
||||||
b.wear_chars = []
|
b.wear_chars = []
|
||||||
for char__ in wear_chars_.getall((b.block, '0x%x' % b.block)):
|
for char__ in wear_chars_.getall((b.block, '0x%x' % b.block)):
|
||||||
# don't punescape unless we have to
|
if isinstance(char__, str):
|
||||||
if '%' in char__:
|
# don't punescape unless we have to
|
||||||
char__ = punescape(char__, b.attrs)
|
if '%' in char__:
|
||||||
b.wear_chars.append(char__[0]) # limit to 1 char
|
char__ = punescape(char__, b.attrs)
|
||||||
|
char__ = char__[0] # limit to 1 char
|
||||||
|
b.wear_chars.append(char__)
|
||||||
|
|
||||||
# assign wear colors based on block
|
# assign wear colors based on block
|
||||||
if wear:
|
if wear:
|
||||||
@@ -1939,7 +1945,7 @@ def main(path='-', *,
|
|||||||
y__ = canvas.height - (y__+1)
|
y__ = canvas.height - (y__+1)
|
||||||
|
|
||||||
canvas.point(x__, y__,
|
canvas.point(x__, y__,
|
||||||
char=True if braille or dots else char__,
|
char=char__,
|
||||||
color=color__)
|
color=color__)
|
||||||
|
|
||||||
# blocky?
|
# blocky?
|
||||||
@@ -1964,8 +1970,7 @@ def main(path='-', *,
|
|||||||
if i in range__:
|
if i in range__:
|
||||||
# flip y
|
# flip y
|
||||||
canvas.point(x__+dx, y__+(height__-(dy+1)),
|
canvas.point(x__+dx, y__+(height__-(dy+1)),
|
||||||
char=True if braille or dots
|
char=char__,
|
||||||
else char__,
|
|
||||||
color=color__)
|
color=color__)
|
||||||
|
|
||||||
# print some summary info
|
# print some summary info
|
||||||
|
|||||||
+9
-6
@@ -988,10 +988,13 @@ def main_(f, csv_paths, *,
|
|||||||
for i, t in enumerate(tile.leaves()):
|
for i, t in enumerate(tile.leaves()):
|
||||||
if (i, t.key) in chars_:
|
if (i, t.key) in chars_:
|
||||||
char__ = chars_[i, t.key]
|
char__ = chars_[i, t.key]
|
||||||
# don't punescape unless we have to
|
if isinstance(char__, str):
|
||||||
if '%' in char__:
|
# don't punescape unless we have to
|
||||||
char__ = punescape(char__, t.attrs)
|
if '%' in char__:
|
||||||
t.char = char__[0] # limit to 1 char
|
char__ = punescape(char__, t.attrs)
|
||||||
|
char__ = char__[0] # limit to 1 char
|
||||||
|
t.char = char__
|
||||||
|
|
||||||
if (i, t.key) in labels_:
|
if (i, t.key) in labels_:
|
||||||
label__ = labels_[i, t.key]
|
label__ = labels_[i, t.key]
|
||||||
# don't punescape unless we have to
|
# don't punescape unless we have to
|
||||||
@@ -1133,8 +1136,8 @@ def main_(f, csv_paths, *,
|
|||||||
|
|
||||||
canvas.rect(x__, y__, width__, height__,
|
canvas.rect(x__, y__, width__, height__,
|
||||||
# default to first letter of the last part of the key
|
# default to first letter of the last part of the key
|
||||||
char=(True if braille or dots
|
char=(t.char if getattr(t, 'char', None) is not None
|
||||||
else t.char if getattr(t, 'char', None)
|
else True if braille or dots
|
||||||
else t.key[len(by)-1][0] if t.key and t.key[len(by)-1]
|
else t.key[len(by)-1][0] if t.key and t.key[len(by)-1]
|
||||||
else chars_[0]),
|
else chars_[0]),
|
||||||
color=t.color if t.color is not None else colors_[0])
|
color=t.color if t.color is not None else colors_[0])
|
||||||
|
|||||||
Reference in New Issue
Block a user