From b48b39daa78d7e4734192e75e374cc0985a536f1 Mon Sep 17 00:00:00 2001 From: Kyla Levin <62115756+ravenblood000@users.noreply.github.com> Date: Wed, 13 Nov 2024 06:57:34 +0000 Subject: [PATCH] rearrange --- src/chatdbg/chatdbg_gdb.py | 10 ++-------- src/chatdbg/chatdbg_lldb.py | 8 ++++---- src/chatdbg/chatdbg_pdb.py | 7 ++----- src/chatdbg/native_util/dbg_dialog.py | 5 ----- src/chatdbg/util/exit_message.py | 3 +++ 5 files changed, 11 insertions(+), 22 deletions(-) create mode 100644 src/chatdbg/util/exit_message.py diff --git a/src/chatdbg/chatdbg_gdb.py b/src/chatdbg/chatdbg_gdb.py index 18cb233..bf2deae 100644 --- a/src/chatdbg/chatdbg_gdb.py +++ b/src/chatdbg/chatdbg_gdb.py @@ -14,6 +14,7 @@ ) from chatdbg.util.config import chatdbg_config from chatdbg.native_util.safety import command_is_safe +from chatdbg.util.exit_message import print_exit_message # The file produced by the panic handler if the Rust program is using the chatdbg crate. RUST_PANIC_LOG_FILENAME = "panic_log.txt" @@ -39,15 +40,8 @@ def stop_handler(event): gdb.events.stop.connect(stop_handler) - -def on_exit(event): - print( - f"Thank you for using ChatDBG!\nIf you've enjoyed your experience, feel free to share your success stories here: https://github.com/plasma-umass/ChatDBG/issues/53" - ) - - # Register the exit event handler -gdb.events.exited.connect(on_exit) +gdb.events.exited.connect(print_exit_message) class Code(gdb.Command): diff --git a/src/chatdbg/chatdbg_lldb.py b/src/chatdbg/chatdbg_lldb.py index 67a8c6b..116a349 100644 --- a/src/chatdbg/chatdbg_lldb.py +++ b/src/chatdbg/chatdbg_lldb.py @@ -13,6 +13,7 @@ _SkippedFramesEntry, ) from chatdbg.util.config import chatdbg_config +from chatdbg.util.exit_message import print_exit_message from chatdbg.native_util.safety import command_is_safe # The file produced by the panic handler if the Rust program is using the chatdbg crate. @@ -78,10 +79,9 @@ def __init__(self, prompt, debugger) -> None: super().__init__(prompt) self._debugger = debugger - def _exit_message(self): - print( - f"Thank you for using ChatDBG!\nIf you've enjoyed your experience, feel free to share your success stories here: https://github.com/plasma-umass/ChatDBG/issues/53" - ) + def dialog(self, user_text): + super().dialog(user_text) + print_exit_message() def _message_is_a_bad_command_error(self, message): return message.strip().endswith("is not a valid command.") diff --git a/src/chatdbg/chatdbg_pdb.py b/src/chatdbg/chatdbg_pdb.py index 0d8664f..572c752 100644 --- a/src/chatdbg/chatdbg_pdb.py +++ b/src/chatdbg/chatdbg_pdb.py @@ -29,6 +29,7 @@ from chatdbg.util.config import chatdbg_config from chatdbg.util.log import ChatDBGLog from chatdbg.util.history import CommandHistory +from chatdbg.util.exit_message import print_exit_message def load_ipython_extension(ipython): @@ -79,11 +80,7 @@ def __init__(self, *args, **kwargs): self._text_width = 120 self._assistant = None atexit.register(lambda: self._close_assistant()) - atexit.register( - lambda: print( - f"Thank you for using ChatDBG!\nIf you've enjoyed your experience, feel free to share your success stories here: https://github.com/plasma-umass/ChatDBG/issues/53" - ) - ) + atexit.register(print_exit_message) self._history = CommandHistory(self.prompt) self._error_message = "" diff --git a/src/chatdbg/native_util/dbg_dialog.py b/src/chatdbg/native_util/dbg_dialog.py index d32fea3..442ccb0 100644 --- a/src/chatdbg/native_util/dbg_dialog.py +++ b/src/chatdbg/native_util/dbg_dialog.py @@ -74,11 +74,6 @@ def dialog(self, user_text): break assistant.close() - # Only implemented in LLDB - self._exit_message() - - def _exit_message(self): - pass # Return string for valid command. None if the command is not valid. def _run_one_command(self, command): diff --git a/src/chatdbg/util/exit_message.py b/src/chatdbg/util/exit_message.py new file mode 100644 index 0000000..e4bf1c6 --- /dev/null +++ b/src/chatdbg/util/exit_message.py @@ -0,0 +1,3 @@ +def print_exit_message(event=None) -> str: + print("Thank you for using ChatDBG!") + print("Share your success stories here: github.com/plasma-umass/ChatDBG/issues/53")