mirror of
https://github.com/Aider-AI/aider.git
synced 2025-05-24 14:25:00 +00:00
aider: Added check for NO_COLOR environment variable to disable ANSI color.
# Context: USER: 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. ASSISTANT: 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. USER: I added these *read-write* files: aider/io.py ASSISTANT: 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.
This commit is contained in:
parent
ffaa28cb7b
commit
321824299a
1 changed files with 9 additions and 7 deletions
16
aider/io.py
16
aider/io.py
|
@ -1,4 +1,5 @@
|
|||
import os
|
||||
import os.path
|
||||
from pygments.lexers import guess_lexer_for_filename
|
||||
from pygments.token import Token
|
||||
from prompt_toolkit.styles import Style
|
||||
|
@ -86,9 +87,13 @@ class InputOutput:
|
|||
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
|
||||
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
|
||||
|
@ -99,10 +104,7 @@ class InputOutput:
|
|||
else:
|
||||
self.chat_history_file = None
|
||||
|
||||
if pretty:
|
||||
self.console = Console()
|
||||
else:
|
||||
self.console = Console(force_terminal=True, no_color=True)
|
||||
self.console = Console(force_terminal=not pretty, no_color=not pretty)
|
||||
|
||||
current_time = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
|
||||
self.append_chat_history(f"\n# aider chat started at {current_time}\n\n")
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue