aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/python/prompt-toolkit/py3/prompt_toolkit/buffer.py
diff options
context:
space:
mode:
authorrobot-piglet <robot-piglet@yandex-team.com>2024-06-14 17:46:04 +0300
committerrobot-piglet <robot-piglet@yandex-team.com>2024-06-14 18:00:06 +0300
commit85f6451860166545196ffa2950aa68be2363733b (patch)
tree4443b7b2465bda4bdc3589314f258329ecaedb38 /contrib/python/prompt-toolkit/py3/prompt_toolkit/buffer.py
parentfa297dd4855aef4bd79faebb48120708d2f9249d (diff)
downloadydb-85f6451860166545196ffa2950aa68be2363733b.tar.gz
Intermediate changes
Diffstat (limited to 'contrib/python/prompt-toolkit/py3/prompt_toolkit/buffer.py')
-rw-r--r--contrib/python/prompt-toolkit/py3/prompt_toolkit/buffer.py29
1 files changed, 16 insertions, 13 deletions
diff --git a/contrib/python/prompt-toolkit/py3/prompt_toolkit/buffer.py b/contrib/python/prompt-toolkit/py3/prompt_toolkit/buffer.py
index 100ca78d7b..f5847d4ab9 100644
--- a/contrib/python/prompt-toolkit/py3/prompt_toolkit/buffer.py
+++ b/contrib/python/prompt-toolkit/py3/prompt_toolkit/buffer.py
@@ -2,6 +2,7 @@
Data structures for the Buffer.
It holds the text, cursor position, history, etc...
"""
+
from __future__ import annotations
import asyncio
@@ -85,12 +86,7 @@ class CompletionState:
self.complete_index = complete_index # Position in the `_completions` array.
def __repr__(self) -> str:
- return "{}({!r}, <{!r}> completions, index={!r})".format(
- self.__class__.__name__,
- self.original_document,
- len(self.completions),
- self.complete_index,
- )
+ return f"{self.__class__.__name__}({self.original_document!r}, <{len(self.completions)!r}> completions, index={self.complete_index!r})"
def go_to_index(self, index: int | None) -> None:
"""
@@ -149,12 +145,7 @@ class YankNthArgState:
self.n = n
def __repr__(self) -> str:
- return "{}(history_position={!r}, n={!r}, previous_inserted_word={!r})".format(
- self.__class__.__name__,
- self.history_position,
- self.n,
- self.previous_inserted_word,
- )
+ return f"{self.__class__.__name__}(history_position={self.history_position!r}, n={self.n!r}, previous_inserted_word={self.previous_inserted_word!r})"
BufferEventHandler = Callable[["Buffer"], None]
@@ -188,6 +179,9 @@ class Buffer:
In case of a `PromptSession` for instance, we want to keep the text,
because we will exit the application, and only reset it during the next
run.
+ :param max_number_of_completions: Never display more than this number of
+ completions, even when the completer can produce more (limited by
+ default to 10k for performance).
Events:
@@ -234,12 +228,13 @@ class Buffer:
accept_handler: BufferAcceptHandler | None = None,
read_only: FilterOrBool = False,
multiline: FilterOrBool = True,
+ max_number_of_completions: int = 10000,
on_text_changed: BufferEventHandler | None = None,
on_text_insert: BufferEventHandler | None = None,
on_cursor_position_changed: BufferEventHandler | None = None,
on_completions_changed: BufferEventHandler | None = None,
on_suggestion_set: BufferEventHandler | None = None,
- ):
+ ) -> None:
# Accept both filters and booleans as input.
enable_history_search = to_filter(enable_history_search)
complete_while_typing = to_filter(complete_while_typing)
@@ -261,6 +256,7 @@ class Buffer:
self.enable_history_search = enable_history_search
self.read_only = read_only
self.multiline = multiline
+ self.max_number_of_completions = max_number_of_completions
# Text width. (For wrapping, used by the Vi 'gq' operator.)
self.text_width = 0
@@ -1748,6 +1744,13 @@ class Buffer:
# If the input text changes, abort.
if not proceed():
break
+
+ # Always stop at 10k completions.
+ if (
+ len(complete_state.completions)
+ >= self.max_number_of_completions
+ ):
+ break
finally:
refresh_task.cancel()