mirror of
https://github.com/Aider-AI/aider.git
synced 2025-05-29 16:54:59 +00:00
aider: Made the two history files optional.
# Context: USER: make the two history files optional ASSISTANT: To make the two history files optional, we will modify the `__init__` method of the `InputOutput` class in the `aider/io.py` file. We will set the default values of `input_history_file` and `chat_history_file` to `None`. Then, we will add conditions to check if these variables are not `None` before using them. ```python aider/io.py <<<<<<< ORIGINAL def __init__(self, pretty, yes, input_history_file, chat_history_file, input=None, output=None): ======= def __init__(self, pretty, yes, input_history_file=None, chat_history_file=None, input=None, output=None): >>>>>>> UPDATED ``` ```python aider/io.py <<<<<<< ORIGINAL session = PromptSession( message=show, completer=completer_instance, history=FileHistory(self.input_history_file), style=style, reserve_space_for_menu=4, complete_style=CompleteStyle.MULTI_COLUMN, input=self.input, output=self.output, ) ======= session_kwargs = { "message": show, "completer": completer_instance, "style": style, "reserve_space_for_menu": 4, "complete_style": CompleteStyle.MULTI_COLUMN, "input": self.input, "output": self.output, } if self.input_history_file is not None: session_kwargs["history"] = FileHistory(self.input_history_file) session = PromptSession(**session_kwargs) >>>>>>> UPDATED ``` ```python aider/io.py <<<<<<< ORIGINAL self.chat_history_file = Path(chat_history_file) ======= if chat_history_file is not None: self.chat_history_file = Path(chat_history_file) else: self.chat_history_file = None >>>>>>> UPDATED ``` ```python aider/io.py <<<<<<< ORIGINAL with self.chat_history_file.open("a") as f: f.write(text) ======= if self.chat_history_file is not None: with self.chat_history_file.open("a") as f: f.write(text) >>>>>>> UPDATED ``` These changes will make the history files optional.
This commit is contained in:
parent
a33c1d3478
commit
aa8ead2f2e
1 changed files with 20 additions and 14 deletions
34
aider/io.py
34
aider/io.py
|
@ -51,13 +51,16 @@ class FileContentCompleter(Completer):
|
||||||
|
|
||||||
|
|
||||||
class InputOutput:
|
class InputOutput:
|
||||||
def __init__(self, pretty, yes, input_history_file, chat_history_file, input=None, output=None):
|
def __init__(self, pretty, yes, input_history_file=None, chat_history_file=None, input=None, output=None):
|
||||||
self.input = input
|
self.input = input
|
||||||
self.output = output
|
self.output = output
|
||||||
self.pretty = pretty
|
self.pretty = pretty
|
||||||
self.yes = yes
|
self.yes = yes
|
||||||
self.input_history_file = input_history_file
|
self.input_history_file = input_history_file
|
||||||
self.chat_history_file = Path(chat_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:
|
if pretty:
|
||||||
self.console = Console()
|
self.console = Console()
|
||||||
|
@ -99,16 +102,18 @@ class InputOutput:
|
||||||
if multiline_input:
|
if multiline_input:
|
||||||
show = ". "
|
show = ". "
|
||||||
|
|
||||||
session = PromptSession(
|
session_kwargs = {
|
||||||
message=show,
|
"message": show,
|
||||||
completer=completer_instance,
|
"completer": completer_instance,
|
||||||
history=FileHistory(self.input_history_file),
|
"style": style,
|
||||||
style=style,
|
"reserve_space_for_menu": 4,
|
||||||
reserve_space_for_menu=4,
|
"complete_style": CompleteStyle.MULTI_COLUMN,
|
||||||
complete_style=CompleteStyle.MULTI_COLUMN,
|
"input": self.input,
|
||||||
input=self.input,
|
"output": self.output,
|
||||||
output=self.output,
|
}
|
||||||
)
|
if self.input_history_file is not None:
|
||||||
|
session_kwargs["history"] = FileHistory(self.input_history_file)
|
||||||
|
session = PromptSession(**session_kwargs)
|
||||||
line = session.prompt()
|
line = session.prompt()
|
||||||
if line.strip() == "{" and not multiline_input:
|
if line.strip() == "{" and not multiline_input:
|
||||||
multiline_input = True
|
multiline_input = True
|
||||||
|
@ -194,5 +199,6 @@ class InputOutput:
|
||||||
text = text + " \n"
|
text = text + " \n"
|
||||||
if not text.endswith("\n"):
|
if not text.endswith("\n"):
|
||||||
text += "\n"
|
text += "\n"
|
||||||
with self.chat_history_file.open("a") as f:
|
if self.chat_history_file is not None:
|
||||||
f.write(text)
|
with self.chat_history_file.open("a") as f:
|
||||||
|
f.write(text)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue