Skip to content

Commit 1280bb9

Browse files
committed
[Settable] description argument can now be rich text
1 parent b4d6cbb commit 1280bb9

4 files changed

Lines changed: 15 additions & 7 deletions

File tree

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
## (TBA)
2+
3+
- Enhancements
4+
- Added possibility to use rich Text objects to set the description argument of a `Settanble`
5+
16
## 4.1.1 (July 9, 2026)
27

38
- Bug Fixes

cmd2/cmd2.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1382,7 +1382,7 @@ def allow_style_type(value: str) -> ru.AllowStyle:
13821382
Settable(
13831383
"allow_style",
13841384
allow_style_type,
1385-
ru.rich_text_to_string(settable_description),
1385+
settable_description,
13861386
self,
13871387
choices_provider=get_allow_style_choices,
13881388
)
@@ -1399,7 +1399,7 @@ def allow_style_type(value: str) -> ru.AllowStyle:
13991399
Settable(
14001400
"editor",
14011401
str,
1402-
ru.rich_text_to_string(editor_description),
1402+
editor_description,
14031403
self,
14041404
)
14051405
)
@@ -1434,7 +1434,7 @@ def allow_style_type(value: str) -> ru.AllowStyle:
14341434
Settable(
14351435
"traceback_width",
14361436
utils.optional_int,
1437-
ru.rich_text_to_string(traceback_width_description),
1437+
traceback_width_description,
14381438
self,
14391439
)
14401440
)

cmd2/utils.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,10 @@
2525
cast,
2626
)
2727

28+
from rich.text import Text
29+
2830
from . import constants
31+
from . import rich_utils as ru
2932
from . import string_utils as su
3033
from .types import (
3134
CmdOrSet,
@@ -88,7 +91,7 @@ def __init__(
8891
self,
8992
name: str,
9093
val_type: type[Any] | Callable[[Any], Any],
91-
description: str,
94+
description: str | Text,
9295
settable_object: object,
9396
*,
9497
settable_attrib_name: str | None = None,
@@ -108,7 +111,8 @@ def __init__(
108111
input is a valid integer. Specifying bool automatically provides
109112
completion for 'true' and 'false' and uses a built-in function
110113
for conversion and validation.
111-
:param description: A concise string that describes the purpose of this setting.
114+
:param description: A concise string or rich Text object that describes the purpose of
115+
this setting.
112116
:param settable_object: The object that owns the attribute being made settable (e.g. self).
113117
:param settable_attrib_name: The name of the attribute on the settable_object that
114118
will be modified. This defaults to the value of the name
@@ -142,7 +146,7 @@ def get_bool_choices(_cmd2_self: CmdOrSet) -> Choices:
142146

143147
self.name = name
144148
self.val_type = val_type
145-
self.description = description
149+
self.description = ru.rich_text_to_string(description) if isinstance(description, Text) else description
146150
self.settable_obj = settable_object
147151
self.settable_attrib_name = settable_attrib_name if settable_attrib_name is not None else name
148152
self.onchange_cb = onchange_cb

tests/test_cmd2.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4304,7 +4304,6 @@ def test_completekey_empty_string() -> None:
43044304

43054305

43064306
def test_create_main_session_exception(monkeypatch):
4307-
43084307
# Mock PromptSession to raise ValueError on first call, then succeed
43094308
valid_session_mock = mock.MagicMock(spec=PromptSession)
43104309
mock_session = mock.MagicMock(side_effect=[ValueError, valid_session_mock])

0 commit comments

Comments
 (0)