Skip to content

Commit 44948e5

Browse files
authored
Updated comments.
1 parent c8a8935 commit 44948e5

File tree

1 file changed

+5
-7
lines changed

1 file changed

+5
-7
lines changed

cmd2/rich_utils.py

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -188,10 +188,8 @@ def rich_text_to_string(text: Text) -> str:
188188
def string_to_rich_text(text: str) -> Text:
189189
r"""Create a Text object from a string which can contain ANSI escape codes.
190190
191-
This wraps rich.Text.from_ansi() to handle a discarded newline issue.
192-
193-
Text.from_ansi() currently removes the ending line break from string.
194-
e.g. "Hello\n" becomes "Hello"
191+
This wraps rich.Text.from_ansi() to handle an issue where it removes the
192+
trailing line break from a string (e.g. "Hello\n" becomes "Hello").
195193
196194
There is currently a pull request to fix this.
197195
https://github.com/Textualize/rich/pull/3793
@@ -201,8 +199,9 @@ def string_to_rich_text(text: str) -> Text:
201199
"""
202200
result = Text.from_ansi(text)
203201

204-
# If 'text' ends with a line break character, restore the missing newline to 'result'.
205-
# Note: '\r\n' is handled as its last character is '\n'.
202+
# If the original string ends with a recognized line break character,
203+
# then restore the missing newline. We use "\n" because Text.from_ansi()
204+
# converts all line breaks into newlines.
206205
# Source: https://docs.python.org/3/library/stdtypes.html#str.splitlines
207206
line_break_chars = {
208207
"\n", # Line Feed
@@ -217,7 +216,6 @@ def string_to_rich_text(text: str) -> Text:
217216
"\u2029", # Paragraph Separator
218217
}
219218
if text and text[-1] in line_break_chars:
220-
# We use "\n" because Text.from_ansi() converts all line breaks chars into newlines.
221219
result.append("\n")
222220

223221
return result

0 commit comments

Comments
 (0)