Skip to content

Commit

Permalink
Add additional text style attributes
Browse files Browse the repository at this point in the history
- Dim
- Overline
- Double underline
- Curvy underline
- Blink
- Blink fast
  • Loading branch information
joouha committed Jan 24, 2024
1 parent b76992e commit 030ce8e
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 2 deletions.
19 changes: 17 additions & 2 deletions src/prompt_toolkit/output/vt100.py
Original file line number Diff line number Diff line change
Expand Up @@ -270,31 +270,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"
Expand Down
15 changes: 15 additions & 0 deletions src/prompt_toolkit/styles/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,37 +22,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,
)


Expand Down
30 changes: 30 additions & 0 deletions src/prompt_toolkit/styles/style.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,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,
)


Expand Down Expand Up @@ -142,6 +147,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":
Expand All @@ -150,6 +159,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"):
Expand Down Expand Up @@ -338,12 +363,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]),
)


Expand Down

0 comments on commit 030ce8e

Please sign in to comment.