chat: improved history printing
This commit is contained in:
parent
d80c3962bd
commit
ba56caf013
@ -145,27 +145,24 @@ class Chat:
|
|||||||
"""
|
"""
|
||||||
return sum(m.tokens() for m in self.messages)
|
return sum(m.tokens() for m in self.messages)
|
||||||
|
|
||||||
def print(self, dump: bool = False, source_code_only: bool = False,
|
def print(self, source_code_only: bool = False,
|
||||||
with_tags: bool = False, with_file: bool = False,
|
with_tags: bool = False, with_files: bool = False,
|
||||||
paged: bool = True) -> None:
|
paged: bool = True) -> None:
|
||||||
if dump:
|
|
||||||
pp(self)
|
|
||||||
return
|
|
||||||
output: list[str] = []
|
output: list[str] = []
|
||||||
for message in self.messages:
|
for message in self.messages:
|
||||||
if source_code_only:
|
if source_code_only:
|
||||||
output.extend(source_code(message.question, include_delims=True))
|
output.extend(source_code(message.question, include_delims=True))
|
||||||
continue
|
continue
|
||||||
output.append('-' * terminal_width())
|
output.append('-' * terminal_width())
|
||||||
|
if with_tags:
|
||||||
|
output.append(message.tags_str())
|
||||||
|
if with_files:
|
||||||
|
output.append('FILE: ' + str(message.file_path))
|
||||||
output.append(Question.txt_header)
|
output.append(Question.txt_header)
|
||||||
output.append(message.question)
|
output.append(message.question)
|
||||||
if message.answer:
|
if message.answer:
|
||||||
output.append(Answer.txt_header)
|
output.append(Answer.txt_header)
|
||||||
output.append(message.answer)
|
output.append(message.answer)
|
||||||
if with_tags:
|
|
||||||
output.append(message.tags_str())
|
|
||||||
if with_file:
|
|
||||||
output.append('FILE: ' + str(message.file_path))
|
|
||||||
if paged:
|
if paged:
|
||||||
print_paged('\n'.join(output))
|
print_paged('\n'.join(output))
|
||||||
else:
|
else:
|
||||||
|
|||||||
@ -82,21 +82,21 @@ Answer 2
|
|||||||
@patch('sys.stdout', new_callable=StringIO)
|
@patch('sys.stdout', new_callable=StringIO)
|
||||||
def test_print_with_tags_and_file(self, mock_stdout: StringIO) -> None:
|
def test_print_with_tags_and_file(self, mock_stdout: StringIO) -> None:
|
||||||
self.chat.add_msgs([self.message1, self.message2])
|
self.chat.add_msgs([self.message1, self.message2])
|
||||||
self.chat.print(paged=False, with_tags=True, with_file=True)
|
self.chat.print(paged=False, with_tags=True, with_files=True)
|
||||||
expected_output = f"""{'-'*terminal_width()}
|
expected_output = f"""{'-'*terminal_width()}
|
||||||
|
{TagLine.prefix} atag1 btag2
|
||||||
|
FILE: 0001.txt
|
||||||
{Question.txt_header}
|
{Question.txt_header}
|
||||||
Question 1
|
Question 1
|
||||||
{Answer.txt_header}
|
{Answer.txt_header}
|
||||||
Answer 1
|
Answer 1
|
||||||
{TagLine.prefix} atag1 btag2
|
|
||||||
FILE: 0001.txt
|
|
||||||
{'-'*terminal_width()}
|
{'-'*terminal_width()}
|
||||||
|
{TagLine.prefix} btag2
|
||||||
|
FILE: 0002.txt
|
||||||
{Question.txt_header}
|
{Question.txt_header}
|
||||||
Question 2
|
Question 2
|
||||||
{Answer.txt_header}
|
{Answer.txt_header}
|
||||||
Answer 2
|
Answer 2
|
||||||
{TagLine.prefix} btag2
|
|
||||||
FILE: 0002.txt
|
|
||||||
"""
|
"""
|
||||||
self.assertEqual(mock_stdout.getvalue(), expected_output)
|
self.assertEqual(mock_stdout.getvalue(), expected_output)
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user