From c3952cb985a8d9273fbcbbfcd19d2bcf503a3363 Mon Sep 17 00:00:00 2001 From: Titusz Pan Date: Mon, 13 Jan 2025 17:51:02 +0100 Subject: [PATCH] feat: Add line endings configuration option for file writing --- aider/args.py | 6 ++++++ aider/io.py | 5 ++++- aider/main.py | 1 + 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/aider/args.py b/aider/args.py index 642858ec3..b880605a9 100644 --- a/aider/args.py +++ b/aider/args.py @@ -766,6 +766,12 @@ def get_parser(default_config_files, git_root): default="utf-8", help="Specify the encoding for input and output (default: utf-8)", ) + group.add_argument( + "--line-endings", + choices=["platform", "lf", "crlf"], + default="platform", + help="Line endings to use when writing files (default: platform)", + ) group.add_argument( "-c", "--config", diff --git a/aider/io.py b/aider/io.py index dc50b4178..b79b0e63c 100644 --- a/aider/io.py +++ b/aider/io.py @@ -198,6 +198,7 @@ class InputOutput: completion_menu_current_bg_color=None, code_theme="default", encoding="utf-8", + line_endings="platform", dry_run=False, llm_history_file=None, editingmode=EditingMode.EMACS, @@ -244,6 +245,8 @@ class InputOutput: self.chat_history_file = None self.encoding = encoding + self.newline = None if line_endings == "platform" \ + else "\n" if line_endings == "lf" else "\r\n" self.dry_run = dry_run current_time = datetime.now().strftime("%Y-%m-%d %H:%M:%S") @@ -375,7 +378,7 @@ class InputOutput: delay = initial_delay for attempt in range(max_retries): try: - with open(str(filename), "w", encoding=self.encoding) as f: + with open(str(filename), "w", encoding=self.encoding, newline=self.newline) as f: f.write(content) return # Successfully wrote the file except PermissionError as err: diff --git a/aider/main.py b/aider/main.py index 33b23c66d..943c74d21 100644 --- a/aider/main.py +++ b/aider/main.py @@ -552,6 +552,7 @@ def main(argv=None, input=None, output=None, force_git_root=None, return_coder=F code_theme=args.code_theme, dry_run=args.dry_run, encoding=args.encoding, + line_endings=args.line_endings, llm_history_file=args.llm_history_file, editingmode=editing_mode, fancy_input=args.fancy_input,