From 0368c3fae91679d3eac7652bd8e81eb4007cc2db Mon Sep 17 00:00:00 2001 From: "Paul Gauthier (aider)" Date: Thu, 7 Nov 2024 10:26:33 -0800 Subject: [PATCH] refactor: extract URL opening functionality into dedicated io.offer_url method --- aider/coders/base_coder.py | 4 +--- aider/io.py | 9 +++++++++ 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/aider/coders/base_coder.py b/aider/coders/base_coder.py index 0e297902a..540828a43 100755 --- a/aider/coders/base_coder.py +++ b/aider/coders/base_coder.py @@ -829,9 +829,7 @@ class Coder: urls = list(set(url_pattern.findall(text))) # Use set to remove duplicates for url in urls: url = url.rstrip(".',\"") - #ai refactor this into a io.offer_url() function! - if self.io.confirm_ask("Open URL for more info?", subject=url): - webbrowser.open(url) + self.io.offer_url(url) return urls def check_for_urls(self, inp: str) -> List[str]: diff --git a/aider/io.py b/aider/io.py index a9a3a3edd..17d3e70b1 100644 --- a/aider/io.py +++ b/aider/io.py @@ -485,6 +485,15 @@ class InputOutput: hist = "\n" + content.strip() + "\n\n" self.append_chat_history(hist) + def offer_url(self, url, prompt="Open URL for more info?"): + """Offer to open a URL in the browser, returns True if opened.""" + if url.rstrip(".',\"") in self.never_prompts: + return False + if self.confirm_ask(prompt, subject=url, allow_never=True): + webbrowser.open(url) + return True + return False + def confirm_ask( self, question,