mirror of
https://github.com/Aider-AI/aider.git
synced 2025-05-24 06:15:00 +00:00
aider: Added colorization to cmd_diff
method when self.pretty
is True.
# Context: USER: in cmd_diff, check self.pretty and colorize the diff if it's true ASSISTANT: To colorize the diff output in the `cmd_diff` method when `self.pretty` is True, we will use the `rich.syntax` module to highlight the diff. ```python aider/coder.py <<<<<<< ORIGINAL from rich.console import Console from rich.prompt import Confirm, Prompt from rich.live import Live from rich.text import Text from rich.markdown import Markdown ======= from rich.console import Console from rich.prompt import Confirm, Prompt from rich.live import Live from rich.text import Text from rich.markdown import Markdown from rich.syntax import Syntax >>>>>>> UPDATED aider/coder.py <<<<<<< ORIGINAL def cmd_diff(self, args): "Display the diff of the last aider commit" if not self.repo: self.console.print("[red]No git repository found.") return if not self.last_aider_commit_hash: self.console.print("[red]No previous aider commit found.") return diff = self.repo.git.diff(f"{self.last_aider_commit_hash}~1", self.last_aider_commit_hash) self.console.print(Text(diff)) ======= def cmd_diff(self, args): "Display the diff of the last aider commit" if not self.repo: self.console.print("[red]No git repository found.") return if not self.last_aider_commit_hash: self.console.print("[red]No previous aider commit found.") return diff = self.repo.git.diff(f"{self.last_aider_commit_hash}~1", self.last_aider_commit_hash) if self.pretty: syntax_diff = Syntax(diff, "diff", theme="monokai", line_numbers=False) self.console.print(syntax_diff) else: self.console.print(Text(diff)) >>>>>>> UPDATED ``` Now, the `cmd_diff` method will colorize the diff output when `self.pretty` is True.
This commit is contained in:
parent
143683c7fd
commit
ff62c39feb
1 changed files with 6 additions and 3 deletions
|
@ -7,10 +7,10 @@ import traceback
|
||||||
|
|
||||||
from rich.console import Console
|
from rich.console import Console
|
||||||
from rich.prompt import Confirm, Prompt
|
from rich.prompt import Confirm, Prompt
|
||||||
|
|
||||||
from rich.live import Live
|
from rich.live import Live
|
||||||
from rich.text import Text
|
from rich.text import Text
|
||||||
from rich.markdown import Markdown
|
from rich.markdown import Markdown
|
||||||
|
from rich.syntax import Syntax
|
||||||
|
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
|
@ -530,8 +530,11 @@ class Coder:
|
||||||
return
|
return
|
||||||
|
|
||||||
diff = self.repo.git.diff(f"{self.last_aider_commit_hash}~1", self.last_aider_commit_hash)
|
diff = self.repo.git.diff(f"{self.last_aider_commit_hash}~1", self.last_aider_commit_hash)
|
||||||
self.console.print(Text(diff))
|
if self.pretty:
|
||||||
|
syntax_diff = Syntax(diff, "diff", theme="monokai", line_numbers=False)
|
||||||
|
self.console.print(syntax_diff)
|
||||||
|
else:
|
||||||
|
self.console.print(Text(diff))
|
||||||
def cmd_add(self, args):
|
def cmd_add(self, args):
|
||||||
"Add matching files to the chat"
|
"Add matching files to the chat"
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue