aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/python/prompt-toolkit/py3/prompt_toolkit/widgets/base.py
diff options
context:
space:
mode:
authorarcadia-devtools <arcadia-devtools@yandex-team.ru>2022-02-12 14:35:15 +0300
committerarcadia-devtools <arcadia-devtools@yandex-team.ru>2022-02-12 14:35:15 +0300
commit46a8b83899dd321edf511c0483f9c479ce2c1bc4 (patch)
treee5debc03beecbd10e7d1bf78c889c8d54e8c4523 /contrib/python/prompt-toolkit/py3/prompt_toolkit/widgets/base.py
parentb56bbcc9f63bf31991a8aa118555ce0c12875a74 (diff)
downloadydb-46a8b83899dd321edf511c0483f9c479ce2c1bc4.tar.gz
intermediate changes
ref:7c971b97c72bbbcbf889118d39017bd14f99365a
Diffstat (limited to 'contrib/python/prompt-toolkit/py3/prompt_toolkit/widgets/base.py')
-rw-r--r--contrib/python/prompt-toolkit/py3/prompt_toolkit/widgets/base.py45
1 files changed, 37 insertions, 8 deletions
diff --git a/contrib/python/prompt-toolkit/py3/prompt_toolkit/widgets/base.py b/contrib/python/prompt-toolkit/py3/prompt_toolkit/widgets/base.py
index 728190b54c..885d23a889 100644
--- a/contrib/python/prompt-toolkit/py3/prompt_toolkit/widgets/base.py
+++ b/contrib/python/prompt-toolkit/py3/prompt_toolkit/widgets/base.py
@@ -433,7 +433,7 @@ class Button:
width = self.width - (
get_cwidth(self.left_symbol) + get_cwidth(self.right_symbol)
)
- text = ("{{:^{}}}".format(width)).format(self.text)
+ text = (f"{{:^{width}}}").format(self.text)
def handler(mouse_event: MouseEvent) -> None:
if (
@@ -686,15 +686,32 @@ class _DialogList(Generic[_T]):
multiple_selection: bool = False
show_scrollbar: bool = True
- def __init__(self, values: Sequence[Tuple[_T, AnyFormattedText]]) -> None:
+ def __init__(
+ self,
+ values: Sequence[Tuple[_T, AnyFormattedText]],
+ default_values: Optional[Sequence[_T]] = None,
+ ) -> None:
assert len(values) > 0
+ default_values = default_values or []
self.values = values
# current_values will be used in multiple_selection,
# current_value will be used otherwise.
- self.current_values: List[_T] = []
- self.current_value: _T = values[0][0]
- self._selected_index = 0
+ keys: List[_T] = [value for (value, _) in values]
+ self.current_values: List[_T] = [
+ value for value in default_values if value in keys
+ ]
+ self.current_value: _T = (
+ default_values[0]
+ if len(default_values) and default_values[0] in keys
+ else values[0][0]
+ )
+
+ # Cursor index: take first selected item or first item otherwise.
+ if len(self.current_values) > 0:
+ self._selected_index = keys.index(self.current_values[0])
+ else:
+ self._selected_index = 0
# Key bindings.
kb = KeyBindings()
@@ -832,6 +849,18 @@ class RadioList(_DialogList[_T]):
checked_style = "class:radio-checked"
multiple_selection = False
+ def __init__(
+ self,
+ values: Sequence[Tuple[_T, AnyFormattedText]],
+ default: Optional[_T] = None,
+ ) -> None:
+ if default is None:
+ default_values = None
+ else:
+ default_values = [default]
+
+ super().__init__(values, default_values=default_values)
+
class CheckboxList(_DialogList[_T]):
"""
@@ -859,7 +888,7 @@ class Checkbox(CheckboxList[str]):
def __init__(self, text: AnyFormattedText = "", checked: bool = False) -> None:
values = [("value", text)]
- CheckboxList.__init__(self, values)
+ CheckboxList.__init__(self, values=values)
self.checked = checked
@property
@@ -874,7 +903,7 @@ class Checkbox(CheckboxList[str]):
self.current_values = []
-class VerticalLine(object):
+class VerticalLine:
"""
A simple vertical line with a width of 1.
"""
@@ -943,7 +972,7 @@ class ProgressBar:
@percentage.setter
def percentage(self, value: int) -> None:
self._percentage = value
- self.label.text = "{0}%".format(value)
+ self.label.text = f"{value}%"
def __pt_container__(self) -> Container:
return self.container