Skip to content

Commit 67d8665

Browse files
committed
Improved rich logging
1 parent 705d384 commit 67d8665

3 files changed

Lines changed: 45 additions & 34 deletions

File tree

src/northlighttools/binfnt/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ def cmd_decompile(
4343
output_dir.mkdir(parents=True, exist_ok=True)
4444

4545
with Progress(
46-
SpinnerColumn(finished_text="\u2713"),
46+
SpinnerColumn(finished_text=":white_check_mark:"),
4747
TextColumn("[progress.description]{task.description}"),
4848
) as progress:
4949
task = progress.add_task("Decompiling...", total=1)
@@ -82,7 +82,7 @@ def cmd_compile(
8282
separate_chars = not input_file.with_suffix(".png").exists()
8383

8484
with Progress(
85-
SpinnerColumn(finished_text="\u2713"),
85+
SpinnerColumn(finished_text=":white_check_mark:"),
8686
TextColumn("[progress.description]{task.description}"),
8787
) as progress:
8888
task = progress.add_task("Compiling...", total=1)

src/northlighttools/rmdp/__init__.py

Lines changed: 40 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
from pathlib import Path
22
from typing import Annotated
33

4+
import humanize
45
import typer
6+
from rich import print
7+
from rich.console import Console
58
from rich.progress import (
69
BarColumn,
710
MofNCompleteColumn,
@@ -12,6 +15,7 @@
1215
TimeElapsedColumn,
1316
TimeRemainingColumn,
1417
)
18+
from rich.table import Table
1519

1620
from northlighttools.rmdp.enumerators.endianness import Endianness, EndiannessChoice
1721
from northlighttools.rmdp.enumerators.package_version import (
@@ -55,15 +59,15 @@ def info(
5559
)
5660
package = Package(header_path=bin_path)
5761

58-
typer.echo(f"Endianness: {package.endianness}")
59-
typer.echo(f"Version: {package.version.name} ({package.version.value})")
60-
typer.echo(f"Number of folders: {len(package.folders)}")
61-
typer.echo(f"Number of files: {len(package.files)}")
62+
print(f"Endianness: {package.endianness} ({package.endianness.name.title()})")
63+
print(
64+
f"Version: {package.version} ({package.version.name.replace('_', ' ').title()})"
65+
)
66+
print(f"Number of folders: {len(package.folders)}")
67+
print(f"Number of files: {len(package.files)}")
6268

6369
if print_unknown_metadata:
64-
typer.echo("Unknown metadata:")
65-
for key, value in package.unknown_data.items():
66-
typer.echo(f" {key}: {value}")
70+
print("Unknown metadata:", package.unknown_data)
6771

6872

6973
@app.command(name="list", help="Lists files in a Remedy Package")
@@ -79,6 +83,7 @@ def contents(
7983
),
8084
],
8185
):
86+
console = Console()
8287
bin_path, _ = get_archive_paths(archive_path)
8388

8489
with Progress(transient=True) as progress:
@@ -88,9 +93,17 @@ def contents(
8893
)
8994
package = Package(header_path=bin_path)
9095

96+
table = Table("File Path", "Size", "Offset")
97+
9198
for file in package.files:
9299
file_path = package.get_file_path(file)
93-
typer.echo(f"{file_path} (Size: {file.size} bytes, Offset: {file.offset})")
100+
table.add_row(
101+
str(file_path),
102+
humanize.naturalsize(file.size),
103+
hex(file.offset),
104+
)
105+
106+
console.print(table)
94107

95108

96109
@app.command(help="Extracts a Remedy Package")
@@ -127,27 +140,26 @@ def extract(
127140
)
128141
package = Package(header_path=bin_path)
129142

130-
progress = Progress(
131-
SpinnerColumn(finished_text="\u2713"),
143+
with Progress(
144+
SpinnerColumn(finished_text=":white_check_mark:"),
132145
TextColumn("[progress.description]{task.description}"),
133146
BarColumn(),
134147
MofNCompleteColumn(),
135148
TaskProgressColumn(),
136149
TimeElapsedColumn(),
137150
TimeRemainingColumn(),
138-
)
139-
140-
with progress and rmdp_path.open("rb") as f:
141-
for file in progress.track(
142-
package.files,
143-
description="Extracting files...",
144-
):
145-
file_path = package.get_file_path(file)
146-
output_path = output_dir / file_path
151+
) as progress:
152+
with rmdp_path.open("rb") as f:
153+
for file in progress.track(
154+
package.files,
155+
description="Extracting files...",
156+
):
157+
file_path = package.get_file_path(file)
158+
output_path = output_dir / file_path
147159

148-
progress.console.log(f"Extracting {file_path}...")
160+
progress.console.log(f"Extracting {file_path}...")
149161

150-
package.extract(f, file, output_path)
162+
package.extract(f, file, output_path)
151163

152164

153165
@app.command(help="Pack directory into a Remedy Package")
@@ -195,21 +207,19 @@ def pack(
195207
bin_path = output_dir.with_suffix(".bin")
196208
rmdp_path = output_dir.with_suffix(".rmdp")
197209

198-
progress = Progress(
199-
SpinnerColumn(finished_text="\u2713"),
210+
package = Package()
211+
package.endianness = Endianness[endianness.name.upper()]
212+
package.version = PackageVersion(int(version))
213+
214+
with Progress(
215+
SpinnerColumn(finished_text=":white_check_mark:"),
200216
TextColumn("[progress.description]{task.description}"),
201217
BarColumn(),
202218
MofNCompleteColumn(),
203219
TaskProgressColumn(),
204220
TimeElapsedColumn(),
205221
TimeRemainingColumn(),
206-
)
207-
208-
package = Package()
209-
package.endianness = Endianness[endianness.name.upper()]
210-
package.version = PackageVersion(int(version))
211-
212-
with progress:
222+
) as progress:
213223
with rmdp_path.open("wb") as rmdp_file:
214224
for path in progress.track(
215225
sorted(input_dir.rglob("*")),

src/northlighttools/string_table/__init__.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
from typing import Annotated
33

44
import typer
5+
from rich import print
56

67
from northlighttools.string_table.enumerators.data_format import DataFormat
78
from northlighttools.string_table.enumerators.missing_string_behaviour import (
@@ -51,7 +52,7 @@ def cmd_export(
5152
table = StringTable(input_file=input_path)
5253
table.export(output_path, output_type)
5354

54-
typer.echo(f"Successfully exported string table to {output_path}!")
55+
print(f"Successfully exported string table to {output_path}!")
5556

5657

5758
@app.command(name="import", help="Generate string_table.bin from input file")
@@ -92,7 +93,7 @@ def cmd_import(
9293
table.load_from(input_path, missing_strings=missing_strings)
9394
table.save(output_path)
9495

95-
typer.echo(f"Successfully imported string table to {output_path}!")
96+
print(f"Successfully imported string table to {output_path}!")
9697

9798

9899
if __name__ == "__main__":

0 commit comments

Comments
 (0)