From 4b8fff69cbcad495618e1d65d06a26a9482b1663 Mon Sep 17 00:00:00 2001 From: Paul Gauthier Date: Sat, 27 May 2023 18:01:58 -0700 Subject: [PATCH] copy --- README.md | 2 +- aider/prompts.py | 2 +- examples/no-color.md | 105 +++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 107 insertions(+), 2 deletions(-) create mode 100644 examples/no-color.md diff --git a/README.md b/README.md index 6f1a8aa78..f1ad004fb 100644 --- a/README.md +++ b/README.md @@ -22,7 +22,7 @@ Here are some example transcripts that show how you can chat with `aider` to wri * [**Create a Black Box Test Case**](https://aider.chat/examples/add-test.html): GPT creates a "black box" test case without access to the source of the method being tested, using only a [high level map of the repository based on ctags](https://aider.chat/docs/ctags.html). -* [**Download, analyze and plot US Census data**](https://aider.chat/examples/census.html): GPT-4 downloads census data, suggests some hypotheses to test, tests one and then summarizes and plots a graph of the results. +* [**Honor the NO_COLOR env var**](https://aider.chat/examples/no-color.html): The user pastes the NO_COLOR spec from no-color.org, and GPT-4 modifies the application to conform. You can find more chat transcripts on the [examples page](https://aider.chat/examples/). diff --git a/aider/prompts.py b/aider/prompts.py index b1eab6151..07374e140 100644 --- a/aider/prompts.py +++ b/aider/prompts.py @@ -8,7 +8,7 @@ Take requests for changes to the supplied code. If the request is ambiguous, ask questions. Once you understand the request you MUST: -1. List the files you need to modify. If they are *read-only* ask the user to make them *read-write* using the file's full path name. +1. List the files you need to modify. If they are *read-only* you *MUST* ask the user to make them *read-write* using the file's full path name. 2. Think step-by-step and explain the needed changes. 3. Describe each change with an *edit block* per the example below. """ diff --git a/examples/no-color.md b/examples/no-color.md new file mode 100644 index 000000000..283ea45d0 --- /dev/null +++ b/examples/no-color.md @@ -0,0 +1,105 @@ + +# Honor the NO_COLOR environment variable + +The user pastes the specification of the NO_COLOR environment variable protocol +from [no-color.org](https://no-color.org) into the chat with GPT-4. + +GPT figures out which files need to be edited, and asks permission to make changes. +It then disables all the color and pretty-printing functions if NO_COLOR is +set, so the tool conforms to the specification. + +## Chat transcript +> $ aider +> Using git repo: .git +> Use /help to see in-chat commands. + +#### Command-line software which adds ANSI color to its output by default should check for a NO_COLOR environment variable that, when present and not an empty string (regardless of its value), prevents the addition of ANSI color. + +To implement this feature, we need to modify the `aider/io.py` file. Please make it *read-write* so I can provide the necessary changes. + +> aider/io.py +> Add these files to the chat? y + +Great! Now, I will make the necessary changes to check for the `NO_COLOR` environment variable and disable ANSI color when it is present and not an empty string. + +```python +aider/io.py +<<<<<<< ORIGINAL +import os +======= +import os +import os.path +>>>>>>> UPDATED +``` + +```python +aider/io.py +<<<<<<< ORIGINAL + def __init__( + self, + pretty=True, + yes=False, + input_history_file=None, + chat_history_file=None, + input=None, + output=None, + user_input_color="blue", + tool_output_color=None, + tool_error_color="red", + ): + self.user_input_color = user_input_color + self.tool_output_color = tool_output_color + self.tool_error_color = tool_error_color + self.input = input + self.output = output + self.pretty = pretty + self.yes = yes + self.input_history_file = input_history_file + if chat_history_file is not None: + self.chat_history_file = Path(chat_history_file) + else: + self.chat_history_file = None + + if pretty: + self.console = Console() + else: + self.console = Console(force_terminal=True, no_color=True) +======= + def __init__( + self, + pretty=True, + yes=False, + input_history_file=None, + chat_history_file=None, + input=None, + output=None, + user_input_color="blue", + tool_output_color=None, + tool_error_color="red", + ): + no_color = os.environ.get("NO_COLOR") + if no_color is not None and no_color != "": + pretty = False + + self.user_input_color = user_input_color if pretty else None + self.tool_output_color = tool_output_color if pretty else None + self.tool_error_color = tool_error_color if pretty else None + self.input = input + self.output = output + self.pretty = pretty + self.yes = yes + self.input_history_file = input_history_file + if chat_history_file is not None: + self.chat_history_file = Path(chat_history_file) + else: + self.chat_history_file = None + + self.console = Console(force_terminal=not pretty, no_color=not pretty) +>>>>>>> UPDATED +``` + +These changes will make the software check for the `NO_COLOR` environment variable and disable ANSI color when it is present and not an empty string. + +> Applied edit to aider/io.py +> Applied edit to aider/io.py +> Commit 3218242 aider: Added check for NO_COLOR environment variable to disable ANSI color.