Skip to content
This repository has been archived by the owner on Jun 4, 2024. It is now read-only.

Commit

Permalink
feat: add debug mode
Browse files Browse the repository at this point in the history
  • Loading branch information
zyf722 committed Apr 1, 2024
1 parent 51671d1 commit 6979b76
Showing 1 changed file with 42 additions and 4 deletions.
46 changes: 42 additions & 4 deletions examples/bf1chs/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@

from flamethrower.localization import Histogram, StringsBinary

VERSION = "v0.5.0"
VERSION = "v0.5.1"
PROJECT_ID = 8862
REPO_NAME = "flamethrower"
REPO_OWNER_GITHUB = "zyf722"
Expand Down Expand Up @@ -419,11 +419,13 @@ def _rich_progress(
return None

@staticmethod
def _rich_confirm(message: str, default=True, **kwargs):
def _rich_confirm(message: str, default=True, desc: Optional[str] = None, **kwargs):
"""
Helper function to show confirm in rich format.
"""
console.print("[dark-gray](输入 y/n 或者回车键直接确认)")
if desc is not None:
console.print(f"[dark-gray]({desc})")
return inquirer.confirm(
message=message,
default=default,
Expand All @@ -434,11 +436,15 @@ def _rich_confirm(message: str, default=True, **kwargs):
).execute()

@staticmethod
def _rich_integer(message: str, default: int = 0, **kwargs):
def _rich_integer(
message: str, default: int = 0, desc: Optional[str] = None, **kwargs
):
"""
Helper function to show integer in rich format.
"""
console.print("[dark-gray](使用方向键上下增减 / 数字键输入数字 / 回车键确认)")
if desc is not None:
console.print(f"[dark-gray]({desc})")
result = inquirer.number(
message=message,
default=default,
Expand All @@ -448,11 +454,15 @@ def _rich_integer(message: str, default: int = 0, **kwargs):
return int(result)

@staticmethod
def _rich_text(message: str, default: str = "", **kwargs):
def _rich_text(
message: str, default: str = "", desc: Optional[str] = None, **kwargs
):
"""
Helper function to show text in rich format.
"""
console.print("[dark-gray](输入文本 / 回车键确认)")
if desc is not None:
console.print(f"[dark-gray]({desc})")
result = inquirer.text(
message=message,
default=default,
Expand All @@ -466,6 +476,7 @@ def _rich_fuzzy_select_file(
directory: str,
types: Union[str, List[str]],
message: str = "选择文件",
desc: Optional[str] = None,
**kwargs,
):
"""
Expand All @@ -490,6 +501,8 @@ def validator(types: Union[str, List[str]], file: str):
console.print(
"[dark-gray](使用方向键上下移动 / 回车键确认 / 输入关键词进行模糊搜索)"
)
if desc is not None:
console.print(f"[dark-gray]({desc})")
result = inquirer.fuzzy(
message=f"{message} ({types_repr})",
choices=choices,
Expand Down Expand Up @@ -846,6 +859,13 @@ def _create_strings_binary_runner(

self._rich_show_object(strings_binary)

debug_mode = self._rich_confirm(
message="是否启用调试模式?",
default=False,
desc="调试模式下,所有词条前将被添加对应键作为注释。",
)
console.print()

# Load new strings json file
with open(
os.path.join(processed_path, "strings-zht.csv.json"),
Expand Down Expand Up @@ -879,6 +899,9 @@ def _create_strings_binary_runner(
)

def _import_strings_wrapper():
if debug_mode:
for key, value in new_dict.items():
new_dict[key] = f"{key:08X} {value}"
strings_binary.import_strings(new_dict) # type: ignore
return True

Expand Down Expand Up @@ -1090,6 +1113,13 @@ def _update_twinkle(self):
return
console.print()

debug_mode = self._rich_confirm(
message="是否启用调试模式?",
default=False,
desc="调试模式下,所有词条前将被添加对应键作为注释。",
)
console.print()

def _twinkle_runner(
progress: Progress,
task: TaskID,
Expand All @@ -1101,6 +1131,12 @@ def _twinkle_runner(
entry_dict[item["original"]] = item["translation"]
elif entry_dict[item["original"]] != item["translation"]:
conflict_count += 1

if debug_mode:
entry_dict[item["original"]] = (
f"{item['key']} {item['translation']}"
)

progress.advance(task)

with open(
Expand Down Expand Up @@ -1451,3 +1487,5 @@ def run(self):
BF1ChsToolbox().run()
except BF1ChsToolbox.ExitException:
pass
except BF1ChsToolbox.ExitException:
pass

0 comments on commit 6979b76

Please sign in to comment.