Skip to content

Commit af62def

Browse files
committed
Add additional text style attributes
- Dim - Overline - Double underline - Curvy underline - Blink - Blink fast
1 parent e02b171 commit af62def

File tree

3 files changed

+62
-2
lines changed

3 files changed

+62
-2
lines changed

src/prompt_toolkit/output/vt100.py

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -271,31 +271,46 @@ def __missing__(self, attrs: Attrs) -> str:
271271
fgcolor,
272272
bgcolor,
273273
bold,
274+
dim,
274275
underline,
276+
doubleunderline,
277+
curvyunderline,
275278
strike,
276279
italic,
277280
blink,
281+
blinkfast,
278282
reverse,
279283
hidden,
284+
overline,
280285
) = attrs
281286
parts: list[str] = []
282287

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

285290
if bold:
286291
parts.append("1")
292+
if dim:
293+
parts.append("2")
287294
if italic:
288295
parts.append("3")
289-
if blink:
290-
parts.append("5")
291296
if underline:
292297
parts.append("4")
298+
if doubleunderline:
299+
parts.append("4:2")
300+
if curvyunderline:
301+
parts.append("4:3")
302+
if blink:
303+
parts.append("5")
304+
if blinkfast:
305+
parts.append("6")
293306
if reverse:
294307
parts.append("7")
295308
if hidden:
296309
parts.append("8")
297310
if strike:
298311
parts.append("9")
312+
if overline:
313+
parts.append("53")
299314

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

src/prompt_toolkit/styles/base.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,37 +23,52 @@ class Attrs(NamedTuple):
2323
color: str | None
2424
bgcolor: str | None
2525
bold: bool | None
26+
dim: bool | None
2627
underline: bool | None
28+
doubleunderline: bool | None
29+
curvyunderline: bool | None
2730
strike: bool | None
2831
italic: bool | None
2932
blink: bool | None
33+
blinkfast: bool | None
3034
reverse: bool | None
3135
hidden: bool | None
36+
overline: bool | None
3237

3338

3439
"""
3540
:param color: Hexadecimal string. E.g. '000000' or Ansi color name: e.g. 'ansiblue'
3641
:param bgcolor: Hexadecimal string. E.g. 'ffffff' or Ansi color name: e.g. 'ansired'
3742
:param bold: Boolean
43+
:param dim: Boolean
3844
:param underline: Boolean
45+
:param doubleunderline: Boolean
46+
:param curvyunderline: Boolean
3947
:param strike: Boolean
4048
:param italic: Boolean
4149
:param blink: Boolean
50+
:param blinkfast: Boolean
4251
:param reverse: Boolean
4352
:param hidden: Boolean
53+
:param overline: Boolean
4454
"""
4555

4656
#: The default `Attrs`.
4757
DEFAULT_ATTRS = Attrs(
4858
color="",
4959
bgcolor="",
5060
bold=False,
61+
dim=False,
5162
underline=False,
63+
doubleunderline=False,
64+
curvyunderline=False,
5265
strike=False,
5366
italic=False,
5467
blink=False,
68+
blinkfast=False,
5569
reverse=False,
5670
hidden=False,
71+
overline=False,
5772
)
5873

5974

src/prompt_toolkit/styles/style.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,12 +82,17 @@ def parse_color(text: str) -> str:
8282
color=None,
8383
bgcolor=None,
8484
bold=None,
85+
dim=None,
8586
underline=None,
87+
doubleunderline=None,
88+
curvyunderline=None,
8689
strike=None,
8790
italic=None,
8891
blink=None,
92+
blinkfast=None,
8993
reverse=None,
9094
hidden=None,
95+
overline=None,
9196
)
9297

9398

@@ -143,6 +148,10 @@ def _parse_style_str(style_str: str) -> Attrs:
143148
attrs = attrs._replace(blink=True)
144149
elif part == "noblink":
145150
attrs = attrs._replace(blink=False)
151+
elif part == "blinkfast":
152+
attrs = attrs._replace(blinkfast=True)
153+
elif part == "noblinkfast":
154+
attrs = attrs._replace(blinkfast=False)
146155
elif part == "reverse":
147156
attrs = attrs._replace(reverse=True)
148157
elif part == "noreverse":
@@ -151,6 +160,22 @@ def _parse_style_str(style_str: str) -> Attrs:
151160
attrs = attrs._replace(hidden=True)
152161
elif part == "nohidden":
153162
attrs = attrs._replace(hidden=False)
163+
elif part == "dim":
164+
attrs = attrs._replace(dim=True)
165+
elif part == "nodim":
166+
attrs = attrs._replace(dim=False)
167+
elif part == "doubleunderline":
168+
attrs = attrs._replace(doubleunderline=True)
169+
elif part == "nodoubleunderline":
170+
attrs = attrs._replace(doubleunderline=False)
171+
elif part == "curvyunderline":
172+
attrs = attrs._replace(curvyunderline=True)
173+
elif part == "nocurvyunderline":
174+
attrs = attrs._replace(curvyunderline=False)
175+
elif part == "overline":
176+
attrs = attrs._replace(overline=True)
177+
elif part == "nooverline":
178+
attrs = attrs._replace(overline=False)
154179

155180
# Pygments properties that we ignore.
156181
elif part in ("roman", "sans", "mono"):
@@ -339,12 +364,17 @@ def _or(*values: _T) -> _T:
339364
color=_or("", *[a.color for a in list_of_attrs]),
340365
bgcolor=_or("", *[a.bgcolor for a in list_of_attrs]),
341366
bold=_or(False, *[a.bold for a in list_of_attrs]),
367+
dim=_or(False, *[a.dim for a in list_of_attrs]),
342368
underline=_or(False, *[a.underline for a in list_of_attrs]),
369+
doubleunderline=_or(False, *[a.doubleunderline for a in list_of_attrs]),
370+
curvyunderline=_or(False, *[a.curvyunderline for a in list_of_attrs]),
343371
strike=_or(False, *[a.strike for a in list_of_attrs]),
344372
italic=_or(False, *[a.italic for a in list_of_attrs]),
345373
blink=_or(False, *[a.blink for a in list_of_attrs]),
374+
blinkfast=_or(False, *[a.blinkfast for a in list_of_attrs]),
346375
reverse=_or(False, *[a.reverse for a in list_of_attrs]),
347376
hidden=_or(False, *[a.hidden for a in list_of_attrs]),
377+
overline=_or(False, *[a.overline for a in list_of_attrs]),
348378
)
349379

350380

0 commit comments

Comments
 (0)