From 796470d76300f291b1b654a69501285a85347943 Mon Sep 17 00:00:00 2001 From: Josiah Outram Halstead Date: Tue, 19 Apr 2022 21:34:18 +0100 Subject: [PATCH] Add additional text style attributes - Dim - Overline - Double underline - Curvy underline - Blink - Blink fast --- src/prompt_toolkit/output/vt100.py | 19 +++++++++++++++++-- src/prompt_toolkit/styles/base.py | 15 +++++++++++++++ src/prompt_toolkit/styles/style.py | 30 ++++++++++++++++++++++++++++++ 3 files changed, 62 insertions(+), 2 deletions(-) diff --git a/src/prompt_toolkit/output/vt100.py b/src/prompt_toolkit/output/vt100.py index 29743db21..ba8115dd1 100644 --- a/src/prompt_toolkit/output/vt100.py +++ b/src/prompt_toolkit/output/vt100.py @@ -270,12 +270,17 @@ def __missing__(self, attrs: Attrs) -> str: fgcolor, bgcolor, bold, + dim, underline, + doubleunderline, + curvyunderline, strike, italic, blink, + blinkfast, reverse, hidden, + overline, ) = attrs parts: list[str] = [] @@ -283,18 +288,28 @@ def __missing__(self, attrs: Attrs) -> str: 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" diff --git a/src/prompt_toolkit/styles/base.py b/src/prompt_toolkit/styles/base.py index b50f3b0ea..f27e50fc9 100644 --- a/src/prompt_toolkit/styles/base.py +++ b/src/prompt_toolkit/styles/base.py @@ -22,24 +22,34 @@ 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`. @@ -47,12 +57,17 @@ class Attrs(NamedTuple): 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, ) diff --git a/src/prompt_toolkit/styles/style.py b/src/prompt_toolkit/styles/style.py index 1abee0f53..203fe78f1 100644 --- a/src/prompt_toolkit/styles/style.py +++ b/src/prompt_toolkit/styles/style.py @@ -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, ) @@ -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": @@ -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"): @@ -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]), )