aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/python/prompt-toolkit/py3/prompt_toolkit/formatted_text
diff options
context:
space:
mode:
authorarcadia-devtools <arcadia-devtools@yandex-team.ru>2022-02-08 15:26:58 +0300
committerarcadia-devtools <arcadia-devtools@yandex-team.ru>2022-02-08 15:26:58 +0300
commit2efaaefec2cb2a55d55c01753d1eed2a3296adb5 (patch)
tree27ec5258b325565c3963b91b36d64e84084fdb04 /contrib/python/prompt-toolkit/py3/prompt_toolkit/formatted_text
parent23793c5d0827a08b5ff9242d2123eff92b681912 (diff)
downloadydb-2efaaefec2cb2a55d55c01753d1eed2a3296adb5.tar.gz
intermediate changes
ref:0bfa27bb6c38df8c510497e54e4ebf0b4fb84503
Diffstat (limited to 'contrib/python/prompt-toolkit/py3/prompt_toolkit/formatted_text')
-rw-r--r--contrib/python/prompt-toolkit/py3/prompt_toolkit/formatted_text/__init__.py2
-rw-r--r--contrib/python/prompt-toolkit/py3/prompt_toolkit/formatted_text/ansi.py34
-rw-r--r--contrib/python/prompt-toolkit/py3/prompt_toolkit/formatted_text/utils.py15
3 files changed, 47 insertions, 4 deletions
diff --git a/contrib/python/prompt-toolkit/py3/prompt_toolkit/formatted_text/__init__.py b/contrib/python/prompt-toolkit/py3/prompt_toolkit/formatted_text/__init__.py
index 1cb56bb653..f0c92c96f9 100644
--- a/contrib/python/prompt-toolkit/py3/prompt_toolkit/formatted_text/__init__.py
+++ b/contrib/python/prompt-toolkit/py3/prompt_toolkit/formatted_text/__init__.py
@@ -27,6 +27,7 @@ from .utils import (
fragment_list_to_text,
fragment_list_width,
split_lines,
+ to_plain_text,
)
__all__ = [
@@ -49,4 +50,5 @@ __all__ = [
"fragment_list_width",
"fragment_list_to_text",
"split_lines",
+ "to_plain_text",
]
diff --git a/contrib/python/prompt-toolkit/py3/prompt_toolkit/formatted_text/ansi.py b/contrib/python/prompt-toolkit/py3/prompt_toolkit/formatted_text/ansi.py
index 374cb32575..3d57063357 100644
--- a/contrib/python/prompt-toolkit/py3/prompt_toolkit/formatted_text/ansi.py
+++ b/contrib/python/prompt-toolkit/py3/prompt_toolkit/formatted_text/ansi.py
@@ -55,7 +55,11 @@ class ANSI:
formatted_text = self._formatted_text
while True:
+ # NOTE: CSI is a special token within a stream of characters that
+ # introduces an ANSI control sequence used to set the
+ # style attributes of the following characters.
csi = False
+
c = yield
# Everything between \001 and \002 should become a ZeroWidthEscape.
@@ -70,6 +74,7 @@ class ANSI:
else:
escaped_text += c
+ # Check for CSI
if c == "\x1b":
# Start of color escape sequence.
square_bracket = yield
@@ -84,19 +89,37 @@ class ANSI:
# Got a CSI sequence. Color codes are following.
current = ""
params = []
+
while True:
char = yield
+
+ # Construct number
if char.isdigit():
current += char
+
+ # Eval number
else:
+ # Limit and save number value
params.append(min(int(current or 0), 9999))
+
+ # Get delimiter token if present
if char == ";":
current = ""
+
+ # Check and evaluate color codes
elif char == "m":
# Set attributes and token.
self._select_graphic_rendition(params)
style = self._create_style_string()
break
+
+ # Check and evaluate cursor forward
+ elif char == "C":
+ for i in range(params[0]):
+ # add <SPACE> using current style
+ formatted_text.append((style, " "))
+ break
+
else:
# Ignore unsupported sequence.
break
@@ -127,14 +150,16 @@ class ANSI:
self._bgcolor = _bg_colors[attr]
elif attr == 1:
self._bold = True
+ # elif attr == 2:
+ # self._faint = True
elif attr == 3:
self._italic = True
elif attr == 4:
self._underline = True
elif attr == 5:
- self._blink = True
+ self._blink = True # Slow blink
elif attr == 6:
- self._blink = True # Fast blink.
+ self._blink = True # Fast blink
elif attr == 7:
self._reverse = True
elif attr == 8:
@@ -142,7 +167,7 @@ class ANSI:
elif attr == 9:
self._strike = True
elif attr == 22:
- self._bold = False
+ self._bold = False # Normal intensity
elif attr == 23:
self._italic = False
elif attr == 24:
@@ -151,9 +176,12 @@ class ANSI:
self._blink = False
elif attr == 27:
self._reverse = False
+ elif attr == 28:
+ self._hidden = False
elif attr == 29:
self._strike = False
elif not attr:
+ # Reset all style attributes
self._color = None
self._bgcolor = None
self._bold = False
diff --git a/contrib/python/prompt-toolkit/py3/prompt_toolkit/formatted_text/utils.py b/contrib/python/prompt-toolkit/py3/prompt_toolkit/formatted_text/utils.py
index 7d48762db4..cda4233e06 100644
--- a/contrib/python/prompt-toolkit/py3/prompt_toolkit/formatted_text/utils.py
+++ b/contrib/python/prompt-toolkit/py3/prompt_toolkit/formatted_text/utils.py
@@ -8,9 +8,15 @@ from typing import Iterable, cast
from prompt_toolkit.utils import get_cwidth
-from .base import OneStyleAndTextTuple, StyleAndTextTuples
+from .base import (
+ AnyFormattedText,
+ OneStyleAndTextTuple,
+ StyleAndTextTuples,
+ to_formatted_text,
+)
__all__ = [
+ "to_plain_text",
"fragment_list_len",
"fragment_list_width",
"fragment_list_to_text",
@@ -18,6 +24,13 @@ __all__ = [
]
+def to_plain_text(value: AnyFormattedText) -> str:
+ """
+ Turn any kind of formatted text back into plain text.
+ """
+ return fragment_list_to_text(to_formatted_text(value))
+
+
def fragment_list_len(fragments: StyleAndTextTuples) -> int:
"""
Return the amount of characters in this text fragment list.