Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion src/prompt_toolkit/formatted_text/ansi.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,8 @@ def _parse_corot(self) -> Generator[None, str, None]:

# Check and evaluate cursor forward
elif char == "C":
for i in range(params[0]):
# A missing or zero count defaults to one column.
for i in range(params[0] or 1):
# add <SPACE> using current style
formatted_text.append((style, " "))
break
Expand Down
15 changes: 15 additions & 0 deletions tests/test_formatted_text.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
from __future__ import annotations

import pytest

from prompt_toolkit.formatted_text import (
ANSI,
HTML,
Expand Down Expand Up @@ -145,6 +147,19 @@ def test_ansi_true_color():
]


@pytest.mark.parametrize("csi", ["\x1b[", "\x9b"])
@pytest.mark.parametrize(
"parameter, count", [("", 1), ("0", 1), ("00", 1), ("1", 1), ("3", 3)]
)
@pytest.mark.parametrize("color, style", [("", ""), ("31", "ansired")])
def test_ansi_cursor_forward_defaults(csi, parameter, count, color, style):
value = ANSI(f"{csi}{color}ma{csi}{parameter}Cb{csi}0mc")

assert to_formatted_text(value) == (
[(style, "a")] + [(style, " ")] * count + [(style, "b"), ("", "c")]
)


def test_ansi_interpolation():
# %-style interpolation.
value = ANSI("\x1b[1m%s\x1b[0m") % "hello\x1b"
Expand Down