diff --git a/chatmastermind/chat.py b/chatmastermind/chat.py index eea78c6..1cc21ba 100644 --- a/chatmastermind/chat.py +++ b/chatmastermind/chat.py @@ -256,13 +256,16 @@ class Chat: def print(self, source_code_only: bool = False, with_metadata: bool = False, - paged: bool = True) -> None: + paged: bool = True, + tight: bool = False) -> None: output: list[str] = [] for message in self.messages: if source_code_only: output.append(message.to_str(source_code_only=True)) continue output.append(message.to_str(with_metadata)) + if not tight: + output.append('\n' + ('-' * terminal_width()) + '\n') if paged: print_paged('\n'.join(output)) else: diff --git a/chatmastermind/commands/hist.py b/chatmastermind/commands/hist.py index de7dd66..8e68320 100644 --- a/chatmastermind/commands/hist.py +++ b/chatmastermind/commands/hist.py @@ -57,7 +57,9 @@ def print_chat(args: argparse.Namespace, config: Config) -> None: Path(config.db), mfilter=mfilter) chat.print(args.source_code_only, - args.with_metadata) + args.with_metadata, + paged=not args.no_paging, + tight=args.tight) def hist_cmd(args: argparse.Namespace, config: Config) -> None: diff --git a/chatmastermind/main.py b/chatmastermind/main.py index 482806c..ff74d6c 100755 --- a/chatmastermind/main.py +++ b/chatmastermind/main.py @@ -85,6 +85,8 @@ def create_parser() -> argparse.ArgumentParser: action='store_true') hist_cmd_parser.add_argument('-A', '--answer', help='Print only answers with given substring', metavar='SUBSTRING') hist_cmd_parser.add_argument('-Q', '--question', help='Print only questions with given substring', metavar='SUBSTRING') + hist_cmd_parser.add_argument('-d', '--tight', help='Print without message separators', action='store_true') + hist_cmd_parser.add_argument('-P', '--no-paging', help='Print without paging', action='store_true') # 'tags' command parser tags_cmd_parser = cmdparser.add_parser('tags', diff --git a/tests/test_chat.py b/tests/test_chat.py index 7616dde..802616d 100644 --- a/tests/test_chat.py +++ b/tests/test_chat.py @@ -147,7 +147,7 @@ class TestChat(TestChatBase): @patch('sys.stdout', new_callable=StringIO) def test_print(self, mock_stdout: StringIO) -> None: self.chat.msg_add([self.message1, self.message2]) - self.chat.print(paged=False) + self.chat.print(paged=False, tight=True) expected_output = f"""{Question.txt_header} Question 1 {Answer.txt_header} @@ -162,7 +162,7 @@ Answer 2 @patch('sys.stdout', new_callable=StringIO) def test_print_with_metadata(self, mock_stdout: StringIO) -> None: self.chat.msg_add([self.message1, self.message2]) - self.chat.print(paged=False, with_metadata=True) + self.chat.print(paged=False, with_metadata=True, tight=True) expected_output = f"""{TagLine.prefix} atag1 btag2 FILE: 0001{msg_suffix} AI: FakeAI