diff --git a/pprobe/toggle/cli.py b/pprobe/toggle/cli.py index b159305..e0979f3 100644 --- a/pprobe/toggle/cli.py +++ b/pprobe/toggle/cli.py @@ -28,11 +28,11 @@ """ -@dataclass -class ToggleStatus: - name: str - status: str - default_status: str +# @dataclass +# class ToggleStatus: +# name: str +# status: str +# default_status: str class ToggleManager(): @@ -42,9 +42,6 @@ def __init__(self): self.default_toggle_path = self.get_path("hook.toggle.default") self.running_toggle_path = self.get_path("hook.toggle.running") self._init_toggles() - print(self.default_toggle) - print("===================") - print(self.running_toggle) def get_path(self, toggle_filename): with importlib.resources.path("pprobe.toggle", "__init__.py") as toggle_path: @@ -122,7 +119,6 @@ def _save_toggles_to_file(self, file_path, toggle_dict): print(f"Error writing to {file_path}: {e}") - # TODO def show_status(self): """ when printing: @@ -131,33 +127,22 @@ def show_status(self): """ print(HELLO_PPROBE) - + + def colorize(value): + """Return the value in green if True, in red if False.""" + if value in (True, "True"): + return f"\033[92m{value}\033[0m" # 绿色 + elif value in (False, "False"): + return f"\033[91m{value}\033[0m" # 红色 + return value + status_in_color = [] for name, value in self.running_toggle.items(): + status = colorize(value) default_value = self.default_toggle.get(name, "False") - status = ToggleStatus(name, value, default_value) - status_in_color.append(status) - - - # for entry in flag_data: - # status = entry.value - # if entry.value == "True": - # # True显示为绿色 - # status = f"\033[92m{entry.value}\033[0m" # 绿色 - # elif entry.value == "False": - # # False显示为红色 - # status = f"\033[91m{entry.value}\033[0m" # 红色 - - # default_status = entry.default_value - # if entry.default_value == "True": - # # True显示为绿色 - # default_status = f"\033[92m{entry.default_value}\033[0m" # 绿色 - # elif entry.default_value == "False": - # # False显示为红色 - # default_status = f"\033[91m{entry.default_value}\033[0m" # 红色 - - # status_in_color.append((entry.name, status, default_status)) + default_status = colorize(default_value) + status_in_color.append((name, status, default_status)) table = tabulate( status_in_color, @@ -166,6 +151,7 @@ def show_status(self): ) print(f"\n{table}\n") + def main(): parser = argparse.ArgumentParser(description="Enable and Disable Options") parser.add_argument( diff --git a/pprobe/toggle/hook.toggle.default b/pprobe/toggle/hook.toggle.default index 342f330..b3141c0 100644 --- a/pprobe/toggle/hook.toggle.default +++ b/pprobe/toggle/hook.toggle.default @@ -1,2 +1,2 @@ AAA=True -BBB=True \ No newline at end of file +BBB=False \ No newline at end of file diff --git a/pprobe/toggle/hook.toggle.running b/pprobe/toggle/hook.toggle.running deleted file mode 100644 index 342f330..0000000 --- a/pprobe/toggle/hook.toggle.running +++ /dev/null @@ -1,2 +0,0 @@ -AAA=True -BBB=True \ No newline at end of file diff --git a/setup.py b/setup.py index 312006f..a70251d 100644 --- a/setup.py +++ b/setup.py @@ -36,9 +36,10 @@ def copy_pth(self): def copy_toggle(self): src_file = 'pprobe/toggle/hook.toggle.default' dst_file = 'pprobe/toggle/hook.toggle.running' + dst_build_file = os.path.join(self.build_lib, dst_file) try: - shutil.copyfile(src_file, dst_file) - print(f"Copied {src_file} to {dst_file}") + shutil.copyfile(src_file, dst_build_file) + print(f"Copied {src_file} to {dst_build_file}") except FileNotFoundError: print(f"Source file {src_file} does not exist")