diff --git a/aider/io.py b/aider/io.py index 1d275716e..ff3cab386 100644 --- a/aider/io.py +++ b/aider/io.py @@ -100,6 +100,7 @@ class InputOutput: user_input_color="blue", tool_output_color=None, tool_error_color="red", + encoding="utf-8", ): no_color = os.environ.get("NO_COLOR") if no_color is not None and no_color != "": @@ -124,6 +125,8 @@ class InputOutput: else: self.chat_history_file = None + self.encoding = encoding + if pretty: self.console = Console() else: @@ -132,6 +135,14 @@ class InputOutput: 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") + def read_text(self, filename): + try: + with open(filename, "r", encoding=self.encoding) as f: + return f.read() + except (FileNotFoundError, UnicodeError) as e: + self.tool_error(str(e)) + return None + def get_input(self, root, rel_fnames, addable_rel_fnames, commands): if self.pretty: style = dict(style=self.user_input_color) if self.user_input_color else dict() diff --git a/aider/main.py b/aider/main.py index decf1514f..cb2039351 100644 --- a/aider/main.py +++ b/aider/main.py @@ -185,6 +185,11 @@ def main(args=None, input=None, output=None): dest="dirty_commits", help="Disable commits when repo is found dirty", ) + parser.add_argument( + "--encoding", + default="utf-8", + help="Specify the encoding to use when reading files (default: utf-8)", + ) parser.add_argument( "--openai-api-key", metavar="OPENAI_API_KEY",