1
0
Fork 0
mirror of https://github.com/zeldaret/oot.git synced 2025-04-09 16:16:23 +00:00

Add colors to sym_info.py full map print ()

This commit is contained in:
Dragorn421 2025-03-26 16:53:39 +01:00 committed by GitHub
parent db90c9fc88
commit b45f3eba2a
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -6,11 +6,13 @@
import argparse
import bisect
from dataclasses import dataclass
import os
from pathlib import Path
from typing import Optional
import struct
import sys
import colorama
import elftools.elf.elffile
import mapfile_parser
@ -228,9 +230,13 @@ def find_symbols_by_name(
return infos
def print_map_file(map_file: mapfile_parser.mapfile.MapFile):
def print_map_file(map_file: mapfile_parser.mapfile.MapFile, *, colors: bool):
for segment in map_file:
print(f"{segment.name}")
print(
f"{colorama.Fore.GREEN if colors else ""}"
f"{segment.name}"
f"{colorama.Fore.RESET if colors else ""}"
)
for file in segment:
# Ignore debug sections
if (
@ -239,7 +245,11 @@ def print_map_file(map_file: mapfile_parser.mapfile.MapFile):
or file.sectionType.startswith(".mdebug")
):
continue
print(f" {file.asStr()}")
print(
f"{colorama.Fore.CYAN if colors else ""}"
f" {file.asStr()}"
f"{colorama.Fore.RESET if colors else ""}"
)
for sym in file:
vram_str = f"{sym.vram:08X}"
if sym.vrom is None:
@ -265,6 +275,12 @@ def sym_info_main():
action="store_true",
help="use the map file and elf in expected/build/ instead of build/",
)
parser.add_argument(
"--color",
help="Whether to print using colors or not",
choices=("never", "always", "auto"),
default="auto",
)
parser.add_argument(
"-v",
"--version",
@ -275,6 +291,17 @@ def sym_info_main():
args = parser.parse_args()
if args.color == "never":
colors = False
elif args.color == "always":
colors = True
else:
# auto
if os.getenv("NO_COLOR"):
colors = False
else:
colors = sys.stdout.isatty()
BUILTMAP = Path("build") / args.oot_version / f"oot-{args.oot_version}.map"
BUILTELF = Path("build") / args.oot_version / f"oot-{args.oot_version}.elf"
@ -301,7 +328,7 @@ def sym_info_main():
sym_name = args.symname
if sym_name is None:
print_map_file(map_file)
print_map_file(map_file, colors=colors)
sys.exit(0)
infos: list[mapfile_parser.mapfile.FoundSymbolInfo] = []