1
0
Fork 0
mirror of https://github.com/zeldaret/oot.git synced 2025-06-07 17:11:50 +00:00

Add colors to sym_info.py full map print (#2474)

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 argparse
import bisect import bisect
from dataclasses import dataclass from dataclasses import dataclass
import os
from pathlib import Path from pathlib import Path
from typing import Optional from typing import Optional
import struct import struct
import sys import sys
import colorama
import elftools.elf.elffile import elftools.elf.elffile
import mapfile_parser import mapfile_parser
@ -228,9 +230,13 @@ def find_symbols_by_name(
return infos 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: 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: for file in segment:
# Ignore debug sections # Ignore debug sections
if ( if (
@ -239,7 +245,11 @@ def print_map_file(map_file: mapfile_parser.mapfile.MapFile):
or file.sectionType.startswith(".mdebug") or file.sectionType.startswith(".mdebug")
): ):
continue 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: for sym in file:
vram_str = f"{sym.vram:08X}" vram_str = f"{sym.vram:08X}"
if sym.vrom is None: if sym.vrom is None:
@ -265,6 +275,12 @@ def sym_info_main():
action="store_true", action="store_true",
help="use the map file and elf in expected/build/ instead of build/", 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( parser.add_argument(
"-v", "-v",
"--version", "--version",
@ -275,6 +291,17 @@ def sym_info_main():
args = parser.parse_args() 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" BUILTMAP = Path("build") / args.oot_version / f"oot-{args.oot_version}.map"
BUILTELF = Path("build") / args.oot_version / f"oot-{args.oot_version}.elf" BUILTELF = Path("build") / args.oot_version / f"oot-{args.oot_version}.elf"
@ -301,7 +328,7 @@ def sym_info_main():
sym_name = args.symname sym_name = args.symname
if sym_name is None: if sym_name is None:
print_map_file(map_file) print_map_file(map_file, colors=colors)
sys.exit(0) sys.exit(0)
infos: list[mapfile_parser.mapfile.FoundSymbolInfo] = [] infos: list[mapfile_parser.mapfile.FoundSymbolInfo] = []