Summary
cmd2 now has a dependency on rich for rich text and pretty formatting in the terminal. Previously, cmd2 had a large amount of custom code for this purpose that predated the existence of rich. This opens the door to even more beautiful cmd2 applications. To get the most out of the new capabilities, we encourage you to spend a little bit of time reading the rich documentation.
Details
-
Breaking Changes
- Refactored and modernized styling and utility modules:
- Removed the legacy
table_creator.pymodule in favor ofrichtables (see the rich_tables.py example for more info) - Moved all string-related functions from
utils.pyto a newstring_utils.pymodule- Removed redundant
stringfrom some of the names soquote_stringis now justquoteandquote_string_if_neededis nowquote_if_needed
- Removed redundant
- Consolidated all string styling functions from
ansi.pyintostring_utils.py - Replaced all text style enums from
ansi.pywith modernrichstyles - Renamed
ansi.pytoterminal_utils.pyto better reflect its purpose
- Removed the legacy
- Dropped support for Python 3.9.
cmd2now requires Python 3.10 or later - Replaced
Settable.get_value()andSettable.set_value()methods with a more Pythonicvalueproperty - Removed redundant setting of a parser's
progvalue in thewith_argparser()decorator, as this is now handled centrally inCmd._build_parser() - The
auto_load_commandsargument tocmd2.Cmd.__init__now defaults toFalse argparse_custommodule breaking changes:descriptive_header: strreplaced withdescriptive_headers: Sequence[str | rich.Column]- Applies to parameter name when adding an argument to a parser as well as
set_descriptive_headersandget_descriptive_headers
- Applies to parameter name when adding an argument to a parser as well as
CompletionItem.description: strchanged to
CompletionItem.descriptive_data: Sequence[str | rich.Column]
decoratorsmodule breaking changes:_set_parser_progrenamed toset_parser_prog(without the leading underscore) and moved toargparse_custommodule
- Renamed history
--output_fileto--output-fileto follow common command-line practices
- Refactored and modernized styling and utility modules:
-
Enhancements
- Enhanced all print methods (
poutput(),perror(),ppaged(), etc.) to natively renderrichobjects, enabling beautiful and complex output - Simplified the process for setting a custom parser for
cmd2's built-in commands. See the custom_parser.py example for an updated guide - Introduced
Cmd.macro_arg_complete()for tab-completing macro arguments, with default path completion that can be easily customized - Added
colors.pyandstyles.pyto provide easy access torichcolor names and managecmd2-specific style definitions usingStrEnum(see the colors.py example for a demonstration of all colors available to yourcmd2application) - Added ability to create a custom theme for a
cmd2application usingrich_utils.set_theme(see the rich_theme.py example for more info) - Consolidated multiple redundant examples into a few more comprehensive ones, see:
- Optimized performance of terminal fixup during command finalization by replacing
stty sanewithtermios.tcsetattr
- Enhanced all print methods (
-
Bug Fixes
- Fixed a redirection bug where
cmd2could unintentionally overwrite an application'ssys.stdout
- Fixed a redirection bug where
-
Migration Aids - these will help you iteratively migrate to
cmd23.x in stages- Published new cmd2-ansi module which is a backport of the
cmd2.ansimodule present incmd22.7.0 - Published new cmd2-table module which is a backport of the
cmd2.table_creatormodule present incmd22.7.0
- Published new cmd2-ansi module which is a backport of the