Skip to content

Add additional text styles (dim, overline, double underline, curvy underline, blink, & blink fast) #1630

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
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
19 changes: 17 additions & 2 deletions src/prompt_toolkit/output/vt100.py
Original file line number Diff line number Diff line change
@@ -271,31 +271,46 @@ def __missing__(self, attrs: Attrs) -> str:
fgcolor,
bgcolor,
bold,
dim,
underline,
doubleunderline,
curvyunderline,
strike,
italic,
blink,
blinkfast,
reverse,
hidden,
overline,
) = attrs
parts: list[str] = []

parts.extend(self._colors_to_code(fgcolor or "", bgcolor or ""))

if bold:
parts.append("1")
if dim:
parts.append("2")
if italic:
parts.append("3")
if blink:
parts.append("5")
if underline:
parts.append("4")
if doubleunderline:
parts.append("4:2")
if curvyunderline:
parts.append("4:3")
if blink:
parts.append("5")
if blinkfast:
parts.append("6")
if reverse:
parts.append("7")
if hidden:
parts.append("8")
if strike:
parts.append("9")
if overline:
parts.append("53")

if parts:
result = "\x1b[0;" + ";".join(parts) + "m"
15 changes: 15 additions & 0 deletions src/prompt_toolkit/styles/base.py
Original file line number Diff line number Diff line change
@@ -23,37 +23,52 @@ class Attrs(NamedTuple):
color: str | None
bgcolor: str | None
bold: bool | None
dim: bool | None
underline: bool | None
doubleunderline: bool | None
curvyunderline: bool | None
strike: bool | None
italic: bool | None
blink: bool | None
blinkfast: bool | None
reverse: bool | None
hidden: bool | None
overline: bool | None


"""
:param color: Hexadecimal string. E.g. '000000' or Ansi color name: e.g. 'ansiblue'
:param bgcolor: Hexadecimal string. E.g. 'ffffff' or Ansi color name: e.g. 'ansired'
:param bold: Boolean
:param dim: Boolean
:param underline: Boolean
:param doubleunderline: Boolean
:param curvyunderline: Boolean
:param strike: Boolean
:param italic: Boolean
:param blink: Boolean
:param blinkfast: Boolean
:param reverse: Boolean
:param hidden: Boolean
:param overline: Boolean
"""

#: The default `Attrs`.
DEFAULT_ATTRS = Attrs(
color="",
bgcolor="",
bold=False,
dim=False,
underline=False,
doubleunderline=False,
curvyunderline=False,
strike=False,
italic=False,
blink=False,
blinkfast=False,
reverse=False,
hidden=False,
overline=False,
)


30 changes: 30 additions & 0 deletions src/prompt_toolkit/styles/style.py
Original file line number Diff line number Diff line change
@@ -82,12 +82,17 @@ def parse_color(text: str) -> str:
color=None,
bgcolor=None,
bold=None,
dim=None,
underline=None,
doubleunderline=None,
curvyunderline=None,
strike=None,
italic=None,
blink=None,
blinkfast=None,
reverse=None,
hidden=None,
overline=None,
)


@@ -143,6 +148,10 @@ def _parse_style_str(style_str: str) -> Attrs:
attrs = attrs._replace(blink=True)
elif part == "noblink":
attrs = attrs._replace(blink=False)
elif part == "blinkfast":
attrs = attrs._replace(blinkfast=True)
elif part == "noblinkfast":
attrs = attrs._replace(blinkfast=False)
elif part == "reverse":
attrs = attrs._replace(reverse=True)
elif part == "noreverse":
@@ -151,6 +160,22 @@ def _parse_style_str(style_str: str) -> Attrs:
attrs = attrs._replace(hidden=True)
elif part == "nohidden":
attrs = attrs._replace(hidden=False)
elif part == "dim":
attrs = attrs._replace(dim=True)
elif part == "nodim":
attrs = attrs._replace(dim=False)
elif part == "doubleunderline":
attrs = attrs._replace(doubleunderline=True)
elif part == "nodoubleunderline":
attrs = attrs._replace(doubleunderline=False)
elif part == "curvyunderline":
attrs = attrs._replace(curvyunderline=True)
elif part == "nocurvyunderline":
attrs = attrs._replace(curvyunderline=False)
elif part == "overline":
attrs = attrs._replace(overline=True)
elif part == "nooverline":
attrs = attrs._replace(overline=False)

# Pygments properties that we ignore.
elif part in ("roman", "sans", "mono"):
@@ -339,12 +364,17 @@ def _or(*values: _T) -> _T:
color=_or("", *[a.color for a in list_of_attrs]),
bgcolor=_or("", *[a.bgcolor for a in list_of_attrs]),
bold=_or(False, *[a.bold for a in list_of_attrs]),
dim=_or(False, *[a.dim for a in list_of_attrs]),
underline=_or(False, *[a.underline for a in list_of_attrs]),
doubleunderline=_or(False, *[a.doubleunderline for a in list_of_attrs]),
curvyunderline=_or(False, *[a.curvyunderline for a in list_of_attrs]),
strike=_or(False, *[a.strike for a in list_of_attrs]),
italic=_or(False, *[a.italic for a in list_of_attrs]),
blink=_or(False, *[a.blink for a in list_of_attrs]),
blinkfast=_or(False, *[a.blinkfast for a in list_of_attrs]),
reverse=_or(False, *[a.reverse for a in list_of_attrs]),
hidden=_or(False, *[a.hidden for a in list_of_attrs]),
overline=_or(False, *[a.overline for a in list_of_attrs]),
)