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:
Paul Gauthier 2023-05-10 12:49:37 -07:00
parent 143683c7fd
commit ff62c39feb

View file

@ -7,10 +7,10 @@ import traceback
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
from pathlib import Path
@ -530,8 +530,11 @@ class Coder:
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))
def cmd_add(self, args):
"Add matching files to the chat"