mirror of
https://github.com/Aider-AI/aider.git
synced 2025-05-24 14:25:00 +00:00
Merge pull request #2856 from titusz/configurable-line-endings
feat: Add line endings configuration option for file writing - fixes #1102
This commit is contained in:
commit
a0e56c5282
3 changed files with 11 additions and 1 deletions
|
@ -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",
|
||||
|
|
|
@ -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:
|
||||
|
|
|
@ -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,
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue