Skip to content

Commit 030ce8e

Browse files
committed
Add additional text style attributes
- Dim - Overline - Double underline - Curvy underline - Blink - Blink fast
1 parent b76992e commit 030ce8e

File tree

3 files changed

+62
-2
lines changed

3 files changed

+62
-2
lines changed

src/prompt_toolkit/output/vt100.py

+17-2
Original file line numberDiff line numberDiff line change
@@ -270,31 +270,46 @@ def __missing__(self, attrs: Attrs) -> str:
270270
fgcolor,
271271
bgcolor,
272272
bold,
273+
dim,
273274
underline,
275+
doubleunderline,
276+
curvyunderline,
274277
strike,
275278
italic,
276279
blink,
280+
blinkfast,
277281
reverse,
278282
hidden,
283+
overline,
279284
) = attrs
280285
parts: list[str] = []
281286

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

284289
if bold:
285290
parts.append("1")
291+
if dim:
292+
parts.append("2")
286293
if italic:
287294
parts.append("3")
288-
if blink:
289-
parts.append("5")
290295
if underline:
291296
parts.append("4")
297+
if doubleunderline:
298+
parts.append("4:2")
299+
if curvyunderline:
300+
parts.append("4:3")
301+
if blink:
302+
parts.append("5")
303+
if blinkfast:
304+
parts.append("6")
292305
if reverse:
293306
parts.append("7")
294307
if hidden:
295308
parts.append("8")
296309
if strike:
297310
parts.append("9")
311+
if overline:
312+
parts.append("53")
298313

299314
if parts:
300315
result = "\x1b[0;" + ";".join(parts) + "m"

src/prompt_toolkit/styles/base.py

+15
Original file line numberDiff line numberDiff line change
@@ -22,37 +22,52 @@ class Attrs(NamedTuple):
2222
color: str | None
2323
bgcolor: str | None
2424
bold: bool | None
25+
dim: bool | None
2526
underline: bool | None
27+
doubleunderline: bool | None
28+
curvyunderline: bool | None
2629
strike: bool | None
2730
italic: bool | None
2831
blink: bool | None
32+
blinkfast: bool | None
2933
reverse: bool | None
3034
hidden: bool | None
35+
overline: bool | None
3136

3237

3338
"""
3439
:param color: Hexadecimal string. E.g. '000000' or Ansi color name: e.g. 'ansiblue'
3540
:param bgcolor: Hexadecimal string. E.g. 'ffffff' or Ansi color name: e.g. 'ansired'
3641
:param bold: Boolean
42+
:param dim: Boolean
3743
:param underline: Boolean
44+
:param doubleunderline: Boolean
45+
:param curvyunderline: Boolean
3846
:param strike: Boolean
3947
:param italic: Boolean
4048
:param blink: Boolean
49+
:param blinkfast: Boolean
4150
:param reverse: Boolean
4251
:param hidden: Boolean
52+
:param overline: Boolean
4353
"""
4454

4555
#: The default `Attrs`.
4656
DEFAULT_ATTRS = Attrs(
4757
color="",
4858
bgcolor="",
4959
bold=False,
60+
dim=False,
5061
underline=False,
62+
doubleunderline=False,
63+
curvyunderline=False,
5164
strike=False,
5265
italic=False,
5366
blink=False,
67+
blinkfast=False,
5468
reverse=False,
5569
hidden=False,
70+
overline=False,
5671
)
5772

5873

src/prompt_toolkit/styles/style.py

+30
Original file line numberDiff line numberDiff line change
@@ -81,12 +81,17 @@ def parse_color(text: str) -> str:
8181
color=None,
8282
bgcolor=None,
8383
bold=None,
84+
dim=None,
8485
underline=None,
86+
doubleunderline=None,
87+
curvyunderline=None,
8588
strike=None,
8689
italic=None,
8790
blink=None,
91+
blinkfast=None,
8892
reverse=None,
8993
hidden=None,
94+
overline=None,
9095
)
9196

9297

@@ -142,6 +147,10 @@ def _parse_style_str(style_str: str) -> Attrs:
142147
attrs = attrs._replace(blink=True)
143148
elif part == "noblink":
144149
attrs = attrs._replace(blink=False)
150+
elif part == "blinkfast":
151+
attrs = attrs._replace(blinkfast=True)
152+
elif part == "noblinkfast":
153+
attrs = attrs._replace(blinkfast=False)
145154
elif part == "reverse":
146155
attrs = attrs._replace(reverse=True)
147156
elif part == "noreverse":
@@ -150,6 +159,22 @@ def _parse_style_str(style_str: str) -> Attrs:
150159
attrs = attrs._replace(hidden=True)
151160
elif part == "nohidden":
152161
attrs = attrs._replace(hidden=False)
162+
elif part == "dim":
163+
attrs = attrs._replace(dim=True)
164+
elif part == "nodim":
165+
attrs = attrs._replace(dim=False)
166+
elif part == "doubleunderline":
167+
attrs = attrs._replace(doubleunderline=True)
168+
elif part == "nodoubleunderline":
169+
attrs = attrs._replace(doubleunderline=False)
170+
elif part == "curvyunderline":
171+
attrs = attrs._replace(curvyunderline=True)
172+
elif part == "nocurvyunderline":
173+
attrs = attrs._replace(curvyunderline=False)
174+
elif part == "overline":
175+
attrs = attrs._replace(overline=True)
176+
elif part == "nooverline":
177+
attrs = attrs._replace(overline=False)
153178

154179
# Pygments properties that we ignore.
155180
elif part in ("roman", "sans", "mono"):
@@ -338,12 +363,17 @@ def _or(*values: _T) -> _T:
338363
color=_or("", *[a.color for a in list_of_attrs]),
339364
bgcolor=_or("", *[a.bgcolor for a in list_of_attrs]),
340365
bold=_or(False, *[a.bold for a in list_of_attrs]),
366+
dim=_or(False, *[a.dim for a in list_of_attrs]),
341367
underline=_or(False, *[a.underline for a in list_of_attrs]),
368+
doubleunderline=_or(False, *[a.doubleunderline for a in list_of_attrs]),
369+
curvyunderline=_or(False, *[a.curvyunderline for a in list_of_attrs]),
342370
strike=_or(False, *[a.strike for a in list_of_attrs]),
343371
italic=_or(False, *[a.italic for a in list_of_attrs]),
344372
blink=_or(False, *[a.blink for a in list_of_attrs]),
373+
blinkfast=_or(False, *[a.blinkfast for a in list_of_attrs]),
345374
reverse=_or(False, *[a.reverse for a in list_of_attrs]),
346375
hidden=_or(False, *[a.hidden for a in list_of_attrs]),
376+
overline=_or(False, *[a.overline for a in list_of_attrs]),
347377
)
348378

349379

0 commit comments

Comments
 (0)