From 71116a771ba486915b3c12793c20c8423fce028a Mon Sep 17 00:00:00 2001 From: Paul Gauthier Date: Thu, 11 May 2023 20:43:11 -0700 Subject: [PATCH] aider: Added `rich` library to reset the terminal at the end of `main()` function. # Context: USER: at the end of main() reset the terminal ASSISTANT: I need to see the contents of `aider/main.py` to make the requested changes. Please provide the content of that file. USER: Please note that I shared content of these additional files: aider/main.py ASSISTANT: I apologize for the oversight. I see the content of `aider/main.py` now. To reset the terminal at the end of the `main()` function, you can use the `os.system()` function with the appropriate command for your operating system. Here's the change for `aider/main.py`: ```python aider/main.py <<<<<<< ORIGINAL ^C KeyboardInterrupt USER: no i need pure python. can rich do it? ASSISTANT: Yes, you can use the `rich` library to reset the terminal using pure Python. First, you need to import the `Console` class from the `rich.console` module. Then, create a `Console` instance and call its `clear()` method at the end of the `main()` function. Here's the change for `aider/main.py`: ```python aider/main.py <<<<<<< ORIGINAL import os import sys import argparse from dotenv import load_dotenv from aider.coder import Coder ======= import os import sys import argparse from dotenv import load_dotenv from aider.coder import Coder from rich.console import Console >>>>>>> UPDATED aider/main.py <<<<<<< ORIGINAL coder.run() ======= coder.run() console = Console() console.clear() >>>>>>> UPDATED ``` This change imports the `Console` class from the `rich.console` module and adds the `console.clear()` call at the end of the `main()` function to reset the terminal. --- aider/main.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/aider/main.py b/aider/main.py index 11d4ff9f0..45b706004 100644 --- a/aider/main.py +++ b/aider/main.py @@ -3,6 +3,7 @@ import sys import argparse from dotenv import load_dotenv from aider.coder import Coder +from rich.console import Console def main(args=None): @@ -87,6 +88,8 @@ def main(args=None): return coder.run() + console = Console() + console.clear() if __name__ == "__main__":