MCPcopy Index your code
hub / github.com/bpython/bpython / _combined_events

Function _combined_events

bpython/curtsies.py:255–282  ·  view source on GitHub ↗

Combines consecutive keypress events into paste events.

(
    event_provider: SupportsEventGeneration, paste_threshold: int
)

Source from the content-addressed store, hash-verified

253
254
255def _combined_events(
256 event_provider: SupportsEventGeneration, paste_threshold: int
257) -> Generator[str | curtsies.events.Event | None, float | None, None]:
258 """Combines consecutive keypress events into paste events."""
259 timeout = yield "nonsense_event" # so send can be used immediately
260 queue: collections.deque = collections.deque()
261 while True:
262 e = event_provider.send(timeout)
263 if isinstance(e, curtsies.events.Event):
264 timeout = yield e
265 continue
266 elif e is None:
267 timeout = yield None
268 continue
269 else:
270 queue.append(e)
271 e = event_provider.send(0)
272 while not (e is None or isinstance(e, curtsies.events.Event)):
273 queue.append(e)
274 e = event_provider.send(0)
275 if len(queue) >= paste_threshold:
276 paste = curtsies.events.PasteEvent()
277 paste.events.extend(queue)
278 queue.clear()
279 timeout = yield paste
280 else:
281 while len(queue):
282 timeout = yield queue.popleft()
283
284
285def combined_events(

Callers 1

combined_eventsFunction · 0.85

Calls 3

appendMethod · 0.80
sendMethod · 0.45
clearMethod · 0.45

Tested by

no test coverage detected