Skip to content

Commit 0d40b91

Browse files
committed
Add additional text style attributes
- Dim - Overline - Double underline - Curvy underline - Blink - Blink fast
1 parent 3cec4c9 commit 0d40b91

File tree

3 files changed

+62
-2
lines changed

3 files changed

+62
-2
lines changed

Diff for: src/prompt_toolkit/output/vt100.py

+17-2
Original file line numberDiff line numberDiff line change
@@ -280,31 +280,46 @@ def __missing__(self, attrs: Attrs) -> str:
280280
fgcolor,
281281
bgcolor,
282282
bold,
283+
dim,
283284
underline,
285+
doubleunderline,
286+
curvyunderline,
284287
strike,
285288
italic,
286289
blink,
290+
blinkfast,
287291
reverse,
288292
hidden,
293+
overline,
289294
) = attrs
290295
parts: List[str] = []
291296

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

294299
if bold:
295300
parts.append("1")
301+
if dim:
302+
parts.append("2")
296303
if italic:
297304
parts.append("3")
298-
if blink:
299-
parts.append("5")
300305
if underline:
301306
parts.append("4")
307+
if doubleunderline:
308+
parts.append("4:2")
309+
if curvyunderline:
310+
parts.append("4:3")
311+
if blink:
312+
parts.append("5")
313+
if blinkfast:
314+
parts.append("6")
302315
if reverse:
303316
parts.append("7")
304317
if hidden:
305318
parts.append("8")
306319
if strike:
307320
parts.append("9")
321+
if overline:
322+
parts.append("53")
308323

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

Diff for: src/prompt_toolkit/styles/base.py

+15
Original file line numberDiff line numberDiff line change
@@ -20,37 +20,52 @@ class Attrs(NamedTuple):
2020
color: Optional[str]
2121
bgcolor: Optional[str]
2222
bold: Optional[bool]
23+
dim: Optional[bool]
2324
underline: Optional[bool]
25+
doubleunderline: Optional[bool]
26+
curvyunderline: Optional[bool]
2427
strike: Optional[bool]
2528
italic: Optional[bool]
2629
blink: Optional[bool]
30+
blinkfast: Optional[bool]
2731
reverse: Optional[bool]
2832
hidden: Optional[bool]
33+
overline: Optional[bool]
2934

3035

3136
"""
3237
:param color: Hexadecimal string. E.g. '000000' or Ansi color name: e.g. 'ansiblue'
3338
:param bgcolor: Hexadecimal string. E.g. 'ffffff' or Ansi color name: e.g. 'ansired'
3439
:param bold: Boolean
40+
:param dim: Boolean
3541
:param underline: Boolean
42+
:param doubleunderline: Boolean
43+
:param curvyunderline: Boolean
3644
:param strike: Boolean
3745
:param italic: Boolean
3846
:param blink: Boolean
47+
:param blinkfast: Boolean
3948
:param reverse: Boolean
4049
:param hidden: Boolean
50+
:param overline: Boolean
4151
"""
4252

4353
#: The default `Attrs`.
4454
DEFAULT_ATTRS = Attrs(
4555
color="",
4656
bgcolor="",
4757
bold=False,
58+
dim=False,
4859
underline=False,
60+
doubleunderline=False,
61+
curvyunderline=False,
4962
strike=False,
5063
italic=False,
5164
blink=False,
65+
blinkfast=False,
5266
reverse=False,
5367
hidden=False,
68+
overline=False,
5469
)
5570

5671

Diff for: src/prompt_toolkit/styles/style.py

+30
Original file line numberDiff line numberDiff line change
@@ -80,12 +80,17 @@ def parse_color(text: str) -> str:
8080
color=None,
8181
bgcolor=None,
8282
bold=None,
83+
dim=None,
8384
underline=None,
85+
doubleunderline=None,
86+
curvyunderline=None,
8487
strike=None,
8588
italic=None,
8689
blink=None,
90+
blinkfast=None,
8791
reverse=None,
8892
hidden=None,
93+
overline=None,
8994
)
9095

9196

@@ -141,6 +146,10 @@ def _parse_style_str(style_str: str) -> Attrs:
141146
attrs = attrs._replace(blink=True)
142147
elif part == "noblink":
143148
attrs = attrs._replace(blink=False)
149+
elif part == "blinkfast":
150+
attrs = attrs._replace(blinkfast=True)
151+
elif part == "noblinkfast":
152+
attrs = attrs._replace(blinkfast=False)
144153
elif part == "reverse":
145154
attrs = attrs._replace(reverse=True)
146155
elif part == "noreverse":
@@ -149,6 +158,22 @@ def _parse_style_str(style_str: str) -> Attrs:
149158
attrs = attrs._replace(hidden=True)
150159
elif part == "nohidden":
151160
attrs = attrs._replace(hidden=False)
161+
elif part == "dim":
162+
attrs = attrs._replace(dim=True)
163+
elif part == "nodim":
164+
attrs = attrs._replace(dim=False)
165+
elif part == "doubleunderline":
166+
attrs = attrs._replace(doubleunderline=True)
167+
elif part == "nodoubleunderline":
168+
attrs = attrs._replace(doubleunderline=False)
169+
elif part == "curvyunderline":
170+
attrs = attrs._replace(curvyunderline=True)
171+
elif part == "nocurvyunderline":
172+
attrs = attrs._replace(curvyunderline=False)
173+
elif part == "overline":
174+
attrs = attrs._replace(overline=True)
175+
elif part == "nooverline":
176+
attrs = attrs._replace(overline=False)
152177

153178
# Pygments properties that we ignore.
154179
elif part in ("roman", "sans", "mono"):
@@ -337,12 +362,17 @@ def _or(*values: _T) -> _T:
337362
color=_or("", *[a.color for a in list_of_attrs]),
338363
bgcolor=_or("", *[a.bgcolor for a in list_of_attrs]),
339364
bold=_or(False, *[a.bold for a in list_of_attrs]),
365+
dim=_or(False, *[a.dim for a in list_of_attrs]),
340366
underline=_or(False, *[a.underline for a in list_of_attrs]),
367+
doubleunderline=_or(False, *[a.doubleunderline for a in list_of_attrs]),
368+
curvyunderline=_or(False, *[a.curvyunderline for a in list_of_attrs]),
341369
strike=_or(False, *[a.strike for a in list_of_attrs]),
342370
italic=_or(False, *[a.italic for a in list_of_attrs]),
343371
blink=_or(False, *[a.blink for a in list_of_attrs]),
372+
blinkfast=_or(False, *[a.blinkfast for a in list_of_attrs]),
344373
reverse=_or(False, *[a.reverse for a in list_of_attrs]),
345374
hidden=_or(False, *[a.hidden for a in list_of_attrs]),
375+
overline=_or(False, *[a.overline for a in list_of_attrs]),
346376
)
347377

348378

0 commit comments

Comments
 (0)