From 0fe5e43f6b87af5606be4c8b7541851ef3d2b833 Mon Sep 17 00:00:00 2001 From: Harshit Verma Date: Wed, 11 Jun 2025 15:35:27 +0530 Subject: [PATCH 01/10] Add 'Run and Debug' icon to main toolbar Introduced a new debug-icon.svg Integrated the icon into the main toolbar for triggering debug functionality --- icons/debug-icon.svg | 9 +++++++++ pippy_app.py | 11 +++++++++++ 2 files changed, 20 insertions(+) create mode 100644 icons/debug-icon.svg diff --git a/icons/debug-icon.svg b/icons/debug-icon.svg new file mode 100644 index 0000000..2e1ae3c --- /dev/null +++ b/icons/debug-icon.svg @@ -0,0 +1,9 @@ + + + + + + + + + \ No newline at end of file diff --git a/pippy_app.py b/pippy_app.py index 1cc3111..19ec4c4 100644 --- a/pippy_app.py +++ b/pippy_app.py @@ -289,6 +289,17 @@ def initialize_display(self): actions_toolbar.insert(button, -1) button.show() + icon_bw = Gtk.Image() + icon_bw.set_from_file(os.path.join(icons_path, 'debug-icon.svg')) + icon_bw.show() + button = ToolButton(label=_('Run and Debug')) + button.props.accelerator = _('d') + button.set_icon_widget(icon_bw) + button.set_tooltip(_('Run and Debug')) + button.connect('clicked', self._debug_button_cb) + actions_toolbar.insert(button, -1) + button.show() + icon_bw = Gtk.Image() icon_bw.set_from_file(os.path.join(icons_path, 'stopit_bw.svg')) icon_bw.show() From 5d36cfdc3edf2a341891481b033635eb9071db3f Mon Sep 17 00:00:00 2001 From: Harshit Verma Date: Wed, 11 Jun 2025 15:37:52 +0530 Subject: [PATCH 02/10] Implement logic to extract the current source code for debugging Added _get_current_code() method to read code from active tab's file Integrated code extraction into _debug_button_cb to support debugging workflow --- pippy_app.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/pippy_app.py b/pippy_app.py index 19ec4c4..fdda4ce 100644 --- a/pippy_app.py +++ b/pippy_app.py @@ -770,6 +770,31 @@ def _go_button_cb(self, button): GLib.SpawnFlags.DO_NOT_REAP_CHILD, None, None,) + + # To extract the source code + def _get_current_code(self): + pippy_tmp_dir = '%s/tmp/' % self.get_activity_root() + current_file = os.path.join( + pippy_tmp_dir, + self._source_tabs.get_current_file_name() + ) + + try: + with open(current_file, 'r') as f: + return f.read() + except Exception as e: + print(f"Error reading file {current_file}: {e}") + return None + + def _debug_button_cb(self, button): + # Run the code + self._go_button_cb(button) + + code = self._get_current_code() + if code: + print(f"Run and Debug!\n{code}") + else: + print("No code found to debug.") def _stop_button_cb(self, button): try: From 6602c45e0af1af727cb376a207617a7c21de22dc Mon Sep 17 00:00:00 2001 From: Harshit Verma Date: Wed, 11 Jun 2025 15:51:03 +0530 Subject: [PATCH 03/10] Add API call to send code for debugging Sends POST request to /debug endpoint with code payload --- pippy_app.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/pippy_app.py b/pippy_app.py index fdda4ce..8a5b62b 100644 --- a/pippy_app.py +++ b/pippy_app.py @@ -33,6 +33,7 @@ import locale import json import sys +import requests from shutil import copy2 from signal import SIGTERM from gettext import gettext as _ @@ -793,6 +794,18 @@ def _debug_button_cb(self, button): code = self._get_current_code() if code: print(f"Run and Debug!\n{code}") + + try: + response = requests.post( + "http://192.168.64.1:8000/debug", + json={"code": code}, + timeout=50 + ) + print(f"API Response: {response.status_code} - {response.text}") + + except requests.RequestException as e: + print(f"Failed to send debug request: {e}") + else: print("No code found to debug.") From eea0c9750daa9d6d3db45848abfdcc08e3138818 Mon Sep 17 00:00:00 2001 From: Harshit Verma Date: Wed, 25 Jun 2025 07:23:12 +0530 Subject: [PATCH 04/10] Add dedicated debug terminal alongside main output terminal Created separate VTE terminal for displaying debug output Added color theming for debug terminals Introduced UI with buttons to toggle between output and debug terminals Implemented logic to feed LLM-generated debug responses into debug terminal --- pippy_app.py | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 58 insertions(+), 2 deletions(-) diff --git a/pippy_app.py b/pippy_app.py index 8a5b62b..085ec6d 100644 --- a/pippy_app.py +++ b/pippy_app.py @@ -34,6 +34,7 @@ import json import sys import requests +import threading from shutil import copy2 from signal import SIGTERM from gettext import gettext as _ @@ -438,15 +439,41 @@ def initialize_display(self): self._vte.set_size(30, 5) self._vte.set_scrollback_lines(-1) + self._debug_vte = Vte.Terminal() + self._debug_vte.set_encoding('utf-8') + self._debug_vte.set_size(30,5) + self._debug_vte.set_scrollback_lines(-1) + self._vte_set_colors('#000000', '#E7E7E7') + self._vte_set_debug_colors('#1E1E2E', '#D9E0EE') self._child_exited_handler = None self._vte.connect('child_exited', self._child_exited_cb) self._vte.connect('drag_data_received', self._vte_drop_cb) - self._outbox.pack_start(self._vte, True, True, 0) + self._debug_vte.connect('child_exited', self._child_exited_cb) + + self._debug_vte.feed(_("Please start a debugging session\n").encode()) + + btn_output = Gtk.Button(label="Terminal") + btn_debug = Gtk.Button(label="Debug Terminal") + btn_output.connect("clicked", lambda w: self._terminal_stack.set_visible_child_name("output")) + btn_debug.connect("clicked", lambda w: self._terminal_stack.set_visible_child_name("debug")) + + switch_box = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=6) + switch_box.pack_start(btn_output, False, False, 0) + switch_box.pack_start(btn_debug, False, False, 0) + + self._terminal_stack = Gtk.Stack() + self._terminal_stack.set_transition_type(Gtk.StackTransitionType.SLIDE_LEFT_RIGHT) + self._terminal_stack.add_named(self._vte, "output") + self._terminal_stack.add_named(self._debug_vte, "debug") + + self._outbox.pack_start(switch_box, False, False, 0) + self._outbox.pack_start(self._terminal_stack, True, True, 0) outsb = Gtk.Scrollbar(orientation=Gtk.Orientation.VERTICAL) outsb.set_adjustment(self._vte.get_vadjustment()) + outsb.set_adjustment(self._debug_vte.get_vadjustment()) outsb.show() self._outbox.pack_start(outsb, False, False, 0) @@ -470,6 +497,16 @@ def _vte_set_colors(self, bg, fg): self._vte.set_colors(foreground, background, []) + def _vte_set_debug_colors(self, bg, fg): + if _has_new_vte_api(): + foreground = Gdk.RGBA(); foreground.parse(bg) + background = Gdk.RGBA(); background.parse(fg) + else: + foreground = Gdk.color_parse(bg) + background = Gdk.color_parse(fg) + + self._debug_vte.set_colors(foreground, background, []) + def after_init(self): self._outbox.hide() @@ -477,6 +514,8 @@ def _font_size_changed_cb(self, widget, size): self._source_tabs.set_font_size(size) self._vte.set_font( Pango.FontDescription('Monospace {}'.format(size))) + self._debug_vte.set_font( + Pango.FontDescription('Monospace {}'.format(size))) def _store_config(self): font_size = self._source_tabs.get_font_size() @@ -703,6 +742,10 @@ def _reset_vte(self): self._vte.grab_focus() self._vte.feed(b'\x1B[H\x1B[J\x1B[0;39m') + def _reset_debug_vte(self): + self._debug_vte.grab_focus() + self._debug_vte.feed(b'\x1B[H\x1B[J\x1B[0;39m') + def __undobutton_cb(self, button): text_buffer = self._source_tabs.get_text_buffer() if text_buffer.can_undo(): @@ -795,16 +838,29 @@ def _debug_button_cb(self, button): if code: print(f"Run and Debug!\n{code}") + self._reset_debug_vte() + self._debug_vte.feed(_("Analyzing code... Please wait while we generate debugging suggestions.\r\n").encode()) + try: response = requests.post( "http://192.168.64.1:8000/debug", json={"code": code}, timeout=50 ) - print(f"API Response: {response.status_code} - {response.text}") + + if response.status_code == 200: + tips = response.json().get("debug_tips", "") + print(tips) + data = response.text + self._debug_vte.feed(_(data).encode()) + + else: + print(f"Error {response.status_code}: {response.text}") except requests.RequestException as e: print(f"Failed to send debug request: {e}") + msg = f"Failed to send debug request: {e}\r\n" + self._debug_vte.feed(_(msg).encode()) else: print("No code found to debug.") From 2346111c6297dafe4b975c62b12113856a605554 Mon Sep 17 00:00:00 2001 From: Harshit Verma Date: Wed, 25 Jun 2025 07:33:37 +0530 Subject: [PATCH 05/10] Fix UI not responding during debug request by moving network call to background thread Wrapped blocking `requests.post` call in a separate thread to avoid freezing GTK main loop Used `GLib.idle_add` to safely update VTE terminal from background thread Format debug tips by stripping markdown and adjusting newlines --- pippy_app.py | 38 +++++++++++++++++++++++--------------- 1 file changed, 23 insertions(+), 15 deletions(-) diff --git a/pippy_app.py b/pippy_app.py index 085ec6d..30be734 100644 --- a/pippy_app.py +++ b/pippy_app.py @@ -835,35 +835,43 @@ def _debug_button_cb(self, button): self._go_button_cb(button) code = self._get_current_code() - if code: - print(f"Run and Debug!\n{code}") + if not code: + print("No code found to debug.") + return - self._reset_debug_vte() - self._debug_vte.feed(_("Analyzing code... Please wait while we generate debugging suggestions.\r\n").encode()) + print(f"Run and Debug!\n{code}") + self._reset_debug_vte() + self._debug_vte.feed(_("Analyzing code... Please wait while we generate debugging suggestions.\r\n").encode()) + def debug_task(): try: response = requests.post( "http://192.168.64.1:8000/debug", json={"code": code}, - timeout=50 + timeout=200 ) if response.status_code == 200: - tips = response.json().get("debug_tips", "") + data = response.json() + tips = data["debug_tips"].replace('\n', '\r\n')\ + .replace('**', '') \ + .replace('###', '')\ + .replace('```python', '\n--- Code ---\n') \ + .replace('```', '\n--- End Code ---\n') print(tips) - data = response.text - self._debug_vte.feed(_(data).encode()) - + self._reset_debug_vte() + GLib.idle_add(self._debug_vte.feed, _(tips).encode()) else: - print(f"Error {response.status_code}: {response.text}") + error_msg = f"Error {response.status_code}: {response.text}" + print(error_msg) + GLib.idle_add(self._debug_vte.feed, _(error_msg + "\r\n").encode()) except requests.RequestException as e: - print(f"Failed to send debug request: {e}") - msg = f"Failed to send debug request: {e}\r\n" - self._debug_vte.feed(_(msg).encode()) + error_msg = f"Failed to send debug request: {e}" + print(error_msg) + GLib.idle_add(self._debug_vte.feed, _(error_msg + "\r\n").encode()) - else: - print("No code found to debug.") + threading.Thread(target=debug_task, daemon=True).start() def _stop_button_cb(self, button): try: From 624bef3821b5c5df3e1f810162a84a02394ac048 Mon Sep 17 00:00:00 2001 From: Harshit Verma Date: Fri, 27 Jun 2025 17:10:48 +0530 Subject: [PATCH 06/10] Add icons for output and debug terminals Introduced 'output-terminal.svg' and 'debug-terminal.svg' icons. Set those icons for btn_output and btn_debug. Applied custom CSS to style the switch_box. --- icons/debug-terminal.svg | 16 ++++++++++++++++ icons/output-terminal.svg | 12 ++++++++++++ pippy_app.py | 32 +++++++++++++++++++++++++++++--- 3 files changed, 57 insertions(+), 3 deletions(-) create mode 100644 icons/debug-terminal.svg create mode 100644 icons/output-terminal.svg diff --git a/icons/debug-terminal.svg b/icons/debug-terminal.svg new file mode 100644 index 0000000..ddbd871 --- /dev/null +++ b/icons/debug-terminal.svg @@ -0,0 +1,16 @@ + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/icons/output-terminal.svg b/icons/output-terminal.svg new file mode 100644 index 0000000..80fd4c0 --- /dev/null +++ b/icons/output-terminal.svg @@ -0,0 +1,12 @@ + + + + + + + + + + + + \ No newline at end of file diff --git a/pippy_app.py b/pippy_app.py index 30be734..f5502e6 100644 --- a/pippy_app.py +++ b/pippy_app.py @@ -453,13 +453,39 @@ def initialize_display(self): self._debug_vte.connect('child_exited', self._child_exited_cb) self._debug_vte.feed(_("Please start a debugging session\n").encode()) - - btn_output = Gtk.Button(label="Terminal") - btn_debug = Gtk.Button(label="Debug Terminal") + + icon_bw = Gtk.Image() + icon_bw.set_from_file(os.path.join(icons_path, 'output-terminal.svg')) + icon_bw.show() + btn_output = ToolButton(label=_("Terminal")) + btn_output.props.accelerator = _('r') + btn_output.set_icon_widget(icon_bw) + btn_output.set_tooltip(_("Terminal")) btn_output.connect("clicked", lambda w: self._terminal_stack.set_visible_child_name("output")) + + icon_bw = Gtk.Image() + icon_bw.set_from_file(os.path.join(icons_path, 'debug-terminal.svg')) + icon_bw.show() + btn_debug = ToolButton(label=_("Debug Terminal")) + btn_debug.props.accelerator = _('d') + btn_debug.set_icon_widget(icon_bw) + btn_debug.set_tooltip(_("Debug Terminal")) btn_debug.connect("clicked", lambda w: self._terminal_stack.set_visible_child_name("debug")) + style_provider = Gtk.CssProvider() + style_provider.load_from_data(b""" + .colored-box { + background-color: #282828; + } + """) + Gtk.StyleContext.add_provider_for_screen( + Gdk.Screen.get_default(), + style_provider, + Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION + ) + switch_box = Gtk.Box(orientation=Gtk.Orientation.VERTICAL, spacing=6) + switch_box.get_style_context().add_class("colored-box") switch_box.pack_start(btn_output, False, False, 0) switch_box.pack_start(btn_debug, False, False, 0) From 8517b50370befaf689b2bf4cf83443a6cb14e580 Mon Sep 17 00:00:00 2001 From: Harshit Verma Date: Wed, 23 Jul 2025 17:14:15 +0530 Subject: [PATCH 07/10] Add custom Markdown parser for styling LLM response in terminal - Parses headings, lists, code blocks, and inline formatting. - Converts Markdown to ANSI-colored terminal output. - Integrated parser output into debug terminal via feed. - Change text color of debug terminal. --- pippy_app.py | 54 +++++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 45 insertions(+), 9 deletions(-) diff --git a/pippy_app.py b/pippy_app.py index f5502e6..66e88b7 100644 --- a/pippy_app.py +++ b/pippy_app.py @@ -445,7 +445,7 @@ def initialize_display(self): self._debug_vte.set_scrollback_lines(-1) self._vte_set_colors('#000000', '#E7E7E7') - self._vte_set_debug_colors('#1E1E2E', '#D9E0EE') + self._vte_set_debug_colors('#000000', "#D9E0EE") self._child_exited_handler = None self._vte.connect('child_exited', self._child_exited_cb) @@ -855,7 +855,46 @@ def _get_current_code(self): except Exception as e: print(f"Error reading file {current_file}: {e}") return None - + + def markdown_parser(self, md: str): + lines = md.splitlines() + output = [] + in_code_block = False + + for line in lines: + stripped = line.strip() + + if stripped.startswith("```"): + in_code_block = not in_code_block + continue + + if in_code_block: + output.append("\033[1m" + line + "\033[0m\r\n") + continue + + if stripped.startswith("### "): + output.append("\033[1;34;4m" + stripped[4:] + "\033[0m\r\n") + continue + elif stripped.startswith("## "): + output.append("\033[1;34;4m" + stripped[3:] + "\033[0m\r\n") + continue + elif stripped.startswith("# "): + output.append("\033[1;34m;" + stripped[2:] + "\033[0m\r\n") + continue + + if stripped.startswith("- "): + line = "• " + stripped[2:] + + line = re.sub(r"`([^`]*)`", r"\033[1m\1\033[0m", line) + + line = re.sub(r"\*\*(.*?)\*\*", r"\033[2m\1\033[0m", line) + + line = re.sub(r"(? Date: Wed, 23 Jul 2025 17:40:35 +0530 Subject: [PATCH 08/10] Add debug terminal callback to fetch and display code context - Implements _debug_terminal_cb to send code to /context endpoint. - Parses response using markdown_parser and renders in debug terminal. - Uses threading to avoid blocking UI during network call. --- pippy_app.py | 42 ++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 40 insertions(+), 2 deletions(-) diff --git a/pippy_app.py b/pippy_app.py index 66e88b7..fc9dbbc 100644 --- a/pippy_app.py +++ b/pippy_app.py @@ -452,8 +452,6 @@ def initialize_display(self): self._vte.connect('drag_data_received', self._vte_drop_cb) self._debug_vte.connect('child_exited', self._child_exited_cb) - self._debug_vte.feed(_("Please start a debugging session\n").encode()) - icon_bw = Gtk.Image() icon_bw.set_from_file(os.path.join(icons_path, 'output-terminal.svg')) icon_bw.show() @@ -470,6 +468,7 @@ def initialize_display(self): btn_debug.props.accelerator = _('d') btn_debug.set_icon_widget(icon_bw) btn_debug.set_tooltip(_("Debug Terminal")) + btn_debug.connect('clicked', self._debug_terminal_cb) btn_debug.connect("clicked", lambda w: self._terminal_stack.set_visible_child_name("debug")) style_provider = Gtk.CssProvider() @@ -935,6 +934,45 @@ def debug_task(): threading.Thread(target=debug_task, daemon=True).start() + def _debug_terminal_cb(self, button): + + code = self._get_current_code() + if not code: + print("No code found to get context.") + return + + print(f"Context of \n{code}") + + self._reset_debug_vte() + self._debug_vte.feed(_("Getting the context....\r\n").encode()) + + def context_task(): + try: + response = requests.post( + "http://192.168.64.1:8000/context", + json={"code": code}, + timeout=200 + ) + + if response.status_code == 200: + data = response.json() + context = data["code_context"] + print(context) + self._reset_debug_vte() + ansi_output = self.markdown_parser(context) + GLib.idle_add(self._debug_vte.feed, ansi_output.encode()) + else: + error_msg = f"Error {response.status_code}: {response.text}" + print(error_msg) + GLib.idle_add(self._debug_vte.feed, _(error_msg + "\r\n").encode()) + + except requests.RequestException as e: + error_msg = f"Failed to send context request: {e}" + print(error_msg) + GLib.idle_add(self._debug_vte.feed, _(error_msg + "\r\n").encode()) + + threading.Thread(target=context_task, daemon=True).start() + def _stop_button_cb(self, button): try: if self._pid is not None: From cfeb4c100e7aba5f89ddf7fe01a2290772cc5d97 Mon Sep 17 00:00:00 2001 From: Harshit Verma Date: Sat, 6 Sep 2025 16:23:38 +0530 Subject: [PATCH 09/10] Add API config constants and improve debug/context handling - Added API_URL and X_API_KEY constants for easier configuration - Updated debug and context requests to use shared API settings - Improved markdown_parser with better heading and list handling - Filtered out shebang/coding lines when reading files - Replaced print statements with VTE output for consistency --- pippy_app.py | 85 ++++++++++++++++++++++++++++------------------------ 1 file changed, 46 insertions(+), 39 deletions(-) diff --git a/pippy_app.py b/pippy_app.py index fc9dbbc..a1c638a 100644 --- a/pippy_app.py +++ b/pippy_app.py @@ -124,6 +124,8 @@ ) """ # This is .format()'ed with the list of the file names. +API_URL = "http://192.168.64.1:8000/debug" +X_API_KEY = "" def _has_new_vte_api(): try: @@ -850,13 +852,22 @@ def _get_current_code(self): try: with open(current_file, 'r') as f: - return f.read() + lines = f.readlines() + filtered_lines = [ + line for line in lines + if not ( + line.strip().startswith('#!') or + 'coding' in line.lower() + ) + ] + return ''.join(filtered_lines) + except Exception as e: print(f"Error reading file {current_file}: {e}") return None - def markdown_parser(self, md: str): - lines = md.splitlines() + def markdown_parser(self, answer): + lines = answer.splitlines() output = [] in_code_block = False @@ -871,17 +882,20 @@ def markdown_parser(self, md: str): output.append("\033[1m" + line + "\033[0m\r\n") continue - if stripped.startswith("### "): - output.append("\033[1;34;4m" + stripped[4:] + "\033[0m\r\n") + if stripped.startswith("#### "): + output.append("\033[1;34m" + stripped[5:] + "\033[0m\r\n") + continue + elif stripped.startswith("### "): + output.append("\033[1;34m" + stripped[4:] + "\033[0m\r\n") continue elif stripped.startswith("## "): - output.append("\033[1;34;4m" + stripped[3:] + "\033[0m\r\n") + output.append("\033[1;34m" + stripped[3:] + "\033[0m\r\n") continue elif stripped.startswith("# "): - output.append("\033[1;34m;" + stripped[2:] + "\033[0m\r\n") + output.append("\033[1;32;4m" + stripped[2:] + "\033[0m\r\n") continue - if stripped.startswith("- "): + if stripped.startswith("- " or "* "): line = "• " + stripped[2:] line = re.sub(r"`([^`]*)`", r"\033[1m\1\033[0m", line) @@ -895,80 +909,73 @@ def markdown_parser(self, md: str): return ''.join(output) def _debug_button_cb(self, button): - # Run the code - self._go_button_cb(button) - + self._reset_debug_vte() code = self._get_current_code() if not code: - print("No code found to debug.") + self._debug_vte.feed(_("No code found to debug.\r\n").encode()) return - print(f"Run and Debug!\n{code}") - self._reset_debug_vte() - self._debug_vte.feed(_("Analyzing code... Please wait while we generate debugging suggestions.\r\n").encode()) + self._debug_vte.feed(_("Analyzing code....\r\n").encode()) def debug_task(): try: response = requests.post( - "http://192.168.64.1:8000/debug", - json={"code": code}, - timeout=200 + API_URL, + params = { + "code": code, + "context": False + }, + headers = {"X-API-Key": X_API_KEY}, ) if response.status_code == 200: data = response.json() - debug_tips = data["debug_tips"] - print(debug_tips) + answer = data["answer"] self._reset_debug_vte() - output = self.markdown_parser(debug_tips) - GLib.idle_add(self._debug_vte.feed, output.encode()) + parsed_answer = self.markdown_parser(answer) + GLib.idle_add(self._debug_vte.feed, _(parsed_answer).encode()) else: error_msg = f"Error {response.status_code}: {response.text}" - print(error_msg) GLib.idle_add(self._debug_vte.feed, _(error_msg + "\r\n").encode()) except requests.RequestException as e: error_msg = f"Failed to send debug request: {e}" - print(error_msg) GLib.idle_add(self._debug_vte.feed, _(error_msg + "\r\n").encode()) threading.Thread(target=debug_task, daemon=True).start() def _debug_terminal_cb(self, button): - + self._reset_debug_vte() code = self._get_current_code() if not code: - print("No code found to get context.") + self._debug_vte.feed(_("No code found to get context.\r\n").encode()) return - print(f"Context of \n{code}") - - self._reset_debug_vte() - self._debug_vte.feed(_("Getting the context....\r\n").encode()) + self._debug_vte.feed(_("Analyzing code....\r\n").encode()) def context_task(): try: response = requests.post( - "http://192.168.64.1:8000/context", - json={"code": code}, - timeout=200 + API_URL, + params = { + "code": code, + "context": True + }, + headers = {"X-API-Key": X_API_KEY}, ) if response.status_code == 200: data = response.json() - context = data["code_context"] - print(context) + answer = data["answer"] self._reset_debug_vte() - ansi_output = self.markdown_parser(context) - GLib.idle_add(self._debug_vte.feed, ansi_output.encode()) + parsed_answer = self.markdown_parser(answer) + GLib.idle_add(self._debug_vte.feed, _(parsed_answer).encode()) else: error_msg = f"Error {response.status_code}: {response.text}" - print(error_msg) GLib.idle_add(self._debug_vte.feed, _(error_msg + "\r\n").encode()) except requests.RequestException as e: error_msg = f"Failed to send context request: {e}" - print(error_msg) GLib.idle_add(self._debug_vte.feed, _(error_msg + "\r\n").encode()) threading.Thread(target=context_task, daemon=True).start() From f63b2d988d942028ad93f484381fb96c8d059df7 Mon Sep 17 00:00:00 2001 From: Harshit Verma Date: Mon, 15 Sep 2025 18:54:29 +0530 Subject: [PATCH 10/10] Add comments and align code style - Added detailed comments to markdown parser for clarity. - Reformatted code to match existing style guidelines. - Updated `_reset_debug_vte` to clear screen consistently. - Extended inverted color toggle to also update debug terminal colors. --- pippy_app.py | 37 ++++++++++++++++++++++++------------- 1 file changed, 24 insertions(+), 13 deletions(-) diff --git a/pippy_app.py b/pippy_app.py index a1c638a..a2504c0 100644 --- a/pippy_app.py +++ b/pippy_app.py @@ -526,8 +526,10 @@ def _vte_set_colors(self, bg, fg): def _vte_set_debug_colors(self, bg, fg): if _has_new_vte_api(): - foreground = Gdk.RGBA(); foreground.parse(bg) - background = Gdk.RGBA(); background.parse(fg) + foreground = Gdk.RGBA() + foreground.parse(bg) + background = Gdk.RGBA() + background.parse(fg) else: foreground = Gdk.color_parse(bg) background = Gdk.color_parse(fg) @@ -603,11 +605,13 @@ def _toggle_output_cb(self, button): def __inverted_colors_toggled_cb(self, button): if button.props.active: self._vte_set_colors('#E7E7E7', '#000000') + self._vte_set_debug_colors( '#D9E0EE', '#000000') self._source_tabs.set_dark() button.set_icon_name('light-theme') button.set_tooltip(_('Normal Colors')) else: self._vte_set_colors('#000000', '#E7E7E7') + self._vte_set_debug_colors('#000000', '#D9E0EE') self._source_tabs.set_light() button.set_icon_name('dark-theme') button.set_tooltip(_('Inverted Colors')) @@ -769,9 +773,10 @@ def _reset_vte(self): self._vte.grab_focus() self._vte.feed(b'\x1B[H\x1B[J\x1B[0;39m') + # Reset debugging terminal def _reset_debug_vte(self): self._debug_vte.grab_focus() - self._debug_vte.feed(b'\x1B[H\x1B[J\x1B[0;39m') + self._debug_vte.feed(b'\x1B[H\x1B[2J\x1B[3J\x1B[0;39m') def __undobutton_cb(self, button): text_buffer = self._source_tabs.get_text_buffer() @@ -877,31 +882,37 @@ def markdown_parser(self, answer): if stripped.startswith("```"): in_code_block = not in_code_block continue - + + # Inside code block → render the line in bold if in_code_block: output.append("\033[1m" + line + "\033[0m\r\n") continue - - if stripped.startswith("#### "): + + # Parse headings + if stripped.startswith("#### "): # H4 → Blue, bold output.append("\033[1;34m" + stripped[5:] + "\033[0m\r\n") continue - elif stripped.startswith("### "): + elif stripped.startswith("### "): # H3 → Blue, bold output.append("\033[1;34m" + stripped[4:] + "\033[0m\r\n") continue - elif stripped.startswith("## "): + elif stripped.startswith("## "): # H2 → Blue, bold output.append("\033[1;34m" + stripped[3:] + "\033[0m\r\n") continue - elif stripped.startswith("# "): + elif stripped.startswith("# "): # H1 → Green, bold + underlined output.append("\033[1;32;4m" + stripped[2:] + "\033[0m\r\n") continue - + + # Parse bullet points (- or *) → replace with • if stripped.startswith("- " or "* "): line = "• " + stripped[2:] - + + # Parse inline code: `...` → bold line = re.sub(r"`([^`]*)`", r"\033[1m\1\033[0m", line) - + + # Parse bold text: **...** → dim line = re.sub(r"\*\*(.*?)\*\*", r"\033[2m\1\033[0m", line) - + + # Parse italic text: *...* → dim (excluding bold markers) line = re.sub(r"(?