mirror of
https://github.com/Aider-AI/aider.git
synced 2025-05-30 17:24:59 +00:00
refactor: conditionally initialize and use PromptSession based on pretty flag
This commit is contained in:
parent
ed866d33e4
commit
79a424bc10
1 changed files with 27 additions and 19 deletions
46
aider/io.py
46
aider/io.py
|
@ -219,16 +219,18 @@ class InputOutput:
|
||||||
current_time = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
|
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")
|
self.append_chat_history(f"\n# aider chat started at {current_time}\n\n")
|
||||||
|
|
||||||
# Initialize PromptSession
|
self.prompt_session = None
|
||||||
session_kwargs = {
|
if self.pretty:
|
||||||
"input": self.input,
|
# Initialize PromptSession
|
||||||
"output": self.output,
|
session_kwargs = {
|
||||||
"lexer": PygmentsLexer(MarkdownLexer),
|
"input": self.input,
|
||||||
"editing_mode": self.editingmode,
|
"output": self.output,
|
||||||
}
|
"lexer": PygmentsLexer(MarkdownLexer),
|
||||||
if self.input_history_file is not None:
|
"editing_mode": self.editingmode,
|
||||||
session_kwargs["history"] = FileHistory(self.input_history_file)
|
}
|
||||||
self.prompt_session = PromptSession(**session_kwargs)
|
if self.input_history_file is not None:
|
||||||
|
session_kwargs["history"] = FileHistory(self.input_history_file)
|
||||||
|
self.prompt_session = PromptSession(**session_kwargs)
|
||||||
|
|
||||||
def read_image(self, filename):
|
def read_image(self, filename):
|
||||||
try:
|
try:
|
||||||
|
@ -339,14 +341,17 @@ class InputOutput:
|
||||||
show = ". "
|
show = ". "
|
||||||
|
|
||||||
try:
|
try:
|
||||||
line = self.prompt_session.prompt(
|
if self.prompt_session:
|
||||||
show,
|
line = self.prompt_session.prompt(
|
||||||
completer=completer_instance,
|
show,
|
||||||
reserve_space_for_menu=4,
|
completer=completer_instance,
|
||||||
complete_style=CompleteStyle.MULTI_COLUMN,
|
reserve_space_for_menu=4,
|
||||||
style=style,
|
complete_style=CompleteStyle.MULTI_COLUMN,
|
||||||
key_bindings=kb,
|
style=style,
|
||||||
)
|
key_bindings=kb,
|
||||||
|
)
|
||||||
|
else:
|
||||||
|
line = input(show)
|
||||||
except UnicodeEncodeError as err:
|
except UnicodeEncodeError as err:
|
||||||
self.tool_error(str(err))
|
self.tool_error(str(err))
|
||||||
return ""
|
return ""
|
||||||
|
@ -519,7 +524,10 @@ class InputOutput:
|
||||||
elif self.yes is False:
|
elif self.yes is False:
|
||||||
res = "no"
|
res = "no"
|
||||||
else:
|
else:
|
||||||
res = self.prompt_session.prompt(question + " ", default=default, style=style)
|
if self.prompt_session:
|
||||||
|
res = self.prompt_session.prompt(question + " ", default=default, style=style)
|
||||||
|
else:
|
||||||
|
res = input(question + " ")
|
||||||
|
|
||||||
hist = f"{question.strip()} {res.strip()}"
|
hist = f"{question.strip()} {res.strip()}"
|
||||||
self.append_chat_history(hist, linebreak=True, blockquote=True)
|
self.append_chat_history(hist, linebreak=True, blockquote=True)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue