diff options
author | Kevin Van Brunt <kmvanbrunt@gmail.com> | 2019-07-19 12:57:31 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-07-19 12:57:31 -0400 |
commit | bd4bedd255a7a3ee6905f9a11b0d678a6ba1a714 (patch) | |
tree | 10d9056d6e220d37e2ccc0b572d22530bf394c94 | |
parent | 5ffe114085866800d5dca7f8b265329e54a8d64f (diff) | |
parent | cd821a49778c119992a21d48f869da6edc7ce2c8 (diff) | |
download | cmd2-git-bd4bedd255a7a3ee6905f9a11b0d678a6ba1a714.tar.gz |
Merge pull request #734 from python-cmd2/formatting_changes
Formatting changes
-rw-r--r-- | CHANGELOG.md | 2 | ||||
-rw-r--r-- | cmd2/cmd2.py | 20 |
2 files changed, 14 insertions, 8 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index 644f7f6c..33f5f354 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -23,7 +23,7 @@ * `ACArgumentParser` is now called `Cmd2ArgumentParser` * Moved `basic_complete` to utils.py * Made optional arguments on the following completer methods keyword-only: - `delimiter_complete`, `flag_based_complete`, `index_based_complete`. `path_complete`, `shell_cmd_complete` + `delimiter_complete`, `flag_based_complete`, `index_based_complete`, `path_complete`, `shell_cmd_complete` * Renamed history option from `--output-file` to `--output_file` * Renamed `matches_sort_key` to `default_sort_key`. This value determines the default sort ordering of string results like alias, command, category, macro, settable, and shortcut names. Unsorted tab-completion results diff --git a/cmd2/cmd2.py b/cmd2/cmd2.py index 6ab35790..788e0294 100644 --- a/cmd2/cmd2.py +++ b/cmd2/cmd2.py @@ -720,7 +720,7 @@ class Cmd(cmd.Cmd): pipe_proc = subprocess.Popen(pager, shell=True, stdin=subprocess.PIPE) pipe_proc.communicate(msg_str.encode('utf-8', 'replace')) else: - ansi.ansi_aware_write(self.stdout, msg_str) + self.poutput(msg_str, end='') except BrokenPipeError: # This occurs if a command's output is being piped to another process and that process closes before the # command is finished. If you would like your application to print a warning message, then set the @@ -2183,7 +2183,9 @@ class Cmd(cmd.Cmd): return self.do_shell(statement.command_and_args) else: err_msg = self.default_error.format(statement.command) - ansi.ansi_aware_write(sys.stderr, "{}\n".format(err_msg)) + + # Set apply_style to False so default_error's style is not overridden + self.perror(err_msg, apply_style=False) def _pseudo_raw_input(self, prompt: str) -> str: """Began life as a copy of cmd's cmdloop; like raw_input but @@ -2730,12 +2732,16 @@ class Cmd(cmd.Cmd): from .argparse_completer import AutoCompleter completer = AutoCompleter(getattr(func, 'argparser'), self) tokens = [args.command] + args.subcommand - self.poutput(completer.format_help(tokens)) + + # Set end to blank so the help output matches how it looks when "command -h" is used + self.poutput(completer.format_help(tokens), end='') # If there is no help information then print an error elif help_func is None and (func is None or not func.__doc__): err_msg = self.help_error.format(args.command) - ansi.ansi_aware_write(sys.stderr, "{}\n".format(err_msg)) + + # Set apply_style to False so help_error's style is not overridden + self.perror(err_msg, apply_style=False) # Otherwise delegate to cmd base class do_help() else: @@ -4012,15 +4018,15 @@ class Cmd(cmd.Cmd): self.disable_command(cmd_name, message_to_print) # noinspection PyUnusedLocal - @staticmethod - def _report_disabled_command_usage(*args, message_to_print: str, **kwargs) -> None: + def _report_disabled_command_usage(self, *args, message_to_print: str, **kwargs) -> None: """ Report when a disabled command has been run or had help called on it :param args: not used :param message_to_print: the message reporting that the command is disabled :param kwargs: not used """ - ansi.ansi_aware_write(sys.stderr, "{}\n".format(message_to_print)) + # Set apply_style to False so message_to_print's style is not overridden + self.perror(message_to_print, apply_style=False) def cmdloop(self, intro: Optional[str] = None) -> int: """This is an outer wrapper around _cmdloop() which deals with extra features provided by cmd2. |