|
15 | 15 |
|
16 | 16 | from . import cmd2 |
17 | 17 | from . import utils |
18 | | -from .ansi import ansi_safe_wcswidth, style_error |
| 18 | +from .ansi import ansi_aware_write, ansi_safe_wcswidth, style_error |
19 | 19 | from .argparse_custom import ATTR_CHOICES_CALLABLE, INFINITY, generate_range_error |
20 | 20 | from .argparse_custom import ATTR_SUPPRESS_TAB_HINT, ATTR_DESCRIPTIVE_COMPLETION_HEADER, ATTR_NARGS_RANGE |
21 | 21 | from .argparse_custom import ChoicesCallable, CompletionError, CompletionItem |
@@ -583,7 +583,8 @@ def _complete_for_arg(self, arg_action: argparse.Action, |
583 | 583 | @staticmethod |
584 | 584 | def _print_message(msg: str) -> None: |
585 | 585 | """Print a message instead of tab completions and redraw the prompt and input line""" |
586 | | - print(msg) |
| 586 | + import sys |
| 587 | + ansi_aware_write(sys.stdout, msg + '\n') |
587 | 588 | rl_force_redisplay() |
588 | 589 |
|
589 | 590 | def _print_arg_hint(self, arg_action: argparse.Action) -> None: |
@@ -621,9 +622,6 @@ def _print_completion_error(self, arg_action: argparse.Action, completion_error: |
621 | 622 | :param arg_action: action being tab completed |
622 | 623 | :param completion_error: error that occurred |
623 | 624 | """ |
624 | | - formatter = self._parser._get_formatter() |
625 | | - formatter.start_section("Error tab completing {}".format(argparse._get_action_name(arg_action))) |
626 | | - formatter.add_text(str(completion_error)) |
627 | | - formatter.end_section() |
628 | | - error = style_error(formatter.format_help()) |
629 | | - self._print_message('\n' + error) |
| 625 | + error = ("\nError tab completing {}:\n" |
| 626 | + " {}\n".format(argparse._get_action_name(arg_action), str(completion_error))) |
| 627 | + self._print_message(style_error('{}'.format(error))) |
0 commit comments