Skip to content

Commit d349023

Browse files
committed
Refactored cmd2 to better account for our use of Rich.
* Added string_utils.py which contains all string utility functions. This includes quoting and alignment functions from utils.py. This also includes style-related functions from ansi.py. * Added colors.py which contains all color names supported by Rich. * Added styles.py which contains the names of all cmd2-specific styles. * Moved string styling functionality from ansi.py to string_utils.py. * Removed all text style Enums from ansi.py since we use Rich. * Renamed ansi.py to terminal_utils.py to reflect the functions left in it. * Removed table_creation.py since we use Rich tables now.
1 parent db2654c commit d349023

33 files changed

+1098
-4680
lines changed

.github/CONTRIBUTING.md

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,10 @@ Nearly all project configuration, including for dependencies and quality tools i
6060

6161
See the `dependencies` list under the `[project]` heading in [pyproject.toml](../pyproject.toml).
6262

63-
| Prerequisite | Minimum Version | Purpose |
64-
| --------------------------------------------------- | --------------- | -------------------------------------- |
65-
| [python](https://www.python.org/downloads/) | `3.10` | Python programming language |
66-
| [pyperclip](https://github.com/asweigart/pyperclip) | `1.8` | Cross-platform clipboard functions |
67-
| [wcwidth](https://pypi.python.org/pypi/wcwidth) | `0.2.10` | Measure the displayed width of unicode |
63+
| Prerequisite | Minimum Version | Purpose |
64+
| --------------------------------------------------- | --------------- | ---------------------------------- |
65+
| [python](https://www.python.org/downloads/) | `3.10` | Python programming language |
66+
| [pyperclip](https://github.com/asweigart/pyperclip) | `1.8` | Cross-platform clipboard functions |
6867

6968
> `macOS` and `Windows` each have an extra dependency to ensure they have a viable alternative to
7069
> [readline](https://tiswww.case.edu/php/chet/readline/rltop.html) available.

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
- No longer setting parser's `prog` value in `with_argparser()` since it gets set in
66
`Cmd._build_parser()`. This code had previously been restored to support backward
77
compatibility in `cmd2` 2.0 family.
8+
- Removed `table_creator` module in favor of `Rich` tables.
89

910
- Enhancements
1011
- Simplified the process to set a custom parser for `cmd2's` built-in commands. See

cmd2/__init__.py

Lines changed: 9 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,11 @@
77
__version__ = importlib_metadata.version(__name__)
88

99
from . import (
10+
colors,
1011
plugin,
1112
rich_utils,
12-
)
13-
from .ansi import (
14-
Bg,
15-
Cursor,
16-
EightBitBg,
17-
EightBitFg,
18-
Fg,
19-
RgbBg,
20-
RgbFg,
21-
TextStyle,
22-
style,
13+
string_utils,
14+
styles,
2315
)
2416
from .argparse_completer import set_default_ap_completer_type
2517
from .argparse_custom import (
@@ -53,6 +45,7 @@
5345
)
5446
from .parsing import Statement
5547
from .py_bridge import CommandResult
48+
from .string_utils import stylize
5649
from .utils import (
5750
CompletionMode,
5851
CustomCompletionSettings,
@@ -63,16 +56,6 @@
6356
__all__: list[str] = [ # noqa: RUF022
6457
'COMMAND_NAME',
6558
'DEFAULT_SHORTCUTS',
66-
# ANSI Exports
67-
'Cursor',
68-
'Bg',
69-
'Fg',
70-
'EightBitBg',
71-
'EightBitFg',
72-
'RgbBg',
73-
'RgbFg',
74-
'TextStyle',
75-
'style',
7659
# Argparse Exports
7760
'Cmd2ArgumentParser',
7861
'Cmd2AttributeWrapper',
@@ -98,8 +81,13 @@
9881
'PassThroughException',
9982
'SkipPostcommandHooks',
10083
# modules
84+
'colors',
10185
'plugin',
10286
'rich_utils',
87+
'string_utils',
88+
'styles',
89+
# String Utils
90+
'stylize',
10391
# Utilities
10492
'categorize',
10593
'CompletionMode',

0 commit comments

Comments
 (0)