Skip to content

Commit e8733bc

Browse files
committed
Removed extra newlines when printing exceptions during completion.
1 parent 04e96c2 commit e8733bc

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

cmd2/cmd2.py

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1488,7 +1488,7 @@ def format_exception(self, exception: BaseException) -> str:
14881488
)
14891489
final_msg.append(help_msg)
14901490

1491-
console.print(final_msg, end="")
1491+
console.print(final_msg)
14921492

14931493
return capture.get()
14941494

@@ -1506,7 +1506,7 @@ def pexcept(
15061506
method and still call `super()` without encountering unexpected keyword argument errors.
15071507
"""
15081508
formatted_exception = self.format_exception(exception)
1509-
self.print_to(sys.stderr, formatted_exception + "\n")
1509+
self.print_to(sys.stderr, formatted_exception)
15101510

15111511
def pfeedback(
15121512
self,
@@ -2519,11 +2519,14 @@ def complete(
25192519

25202520
# Don't display anything if the error is blank (e.g. _NoResultsError for an argument which supresses hints)
25212521
if err_str:
2522+
# _NoResultsError completion hints already include a trailing "\n".
2523+
end = "" if isinstance(ex, argparse_completer._NoResultsError) else "\n"
2524+
25222525
console = ru.Cmd2GeneralConsole()
25232526
with console.capture() as capture:
25242527
console.print(
25252528
Text(err_str, style=Cmd2Style.ERROR if ex.apply_style else ""),
2526-
end="",
2529+
end=end,
25272530
)
25282531
completion_error = capture.get()
25292532
return Completions(completion_error=completion_error)

cmd2/pt_utils.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ def get_completions(self, document: Document, _complete_event: object) -> Iterab
6363
)
6464

6565
if completions.completion_error:
66-
print_formatted_text(ANSI(completions.completion_error + "\n"))
66+
print_formatted_text(ANSI(completions.completion_error))
6767
return
6868

6969
# Print completion table if present

0 commit comments

Comments
 (0)