MCPcopy Index your code
hub / github.com/RustPython/RustPython / get_event

Method get_event

Lib/_pyrepl/windows_console.py:389–434  ·  view source on GitHub ↗

Return an Event instance. Returns None if |block| is false and there is no event pending, otherwise waits for the completion of an event.

(self, block: bool = True)

Source from the content-addressed store, hash-verified

387 return rec
388
389 def get_event(self, block: bool = True) -> Event | None:
390 """Return an Event instance. Returns None if |block| is false
391 and there is no event pending, otherwise waits for the
392 completion of an event."""
393 if self.event_queue:
394 return self.event_queue.pop()
395
396 while True:
397 rec = self._read_input(block)
398 if rec is None:
399 return None
400
401 if rec.EventType == WINDOW_BUFFER_SIZE_EVENT:
402 return Event("resize", "")
403
404 if rec.EventType != KEY_EVENT or not rec.Event.KeyEvent.bKeyDown:
405 # Only process keys and keydown events
406 if block:
407 continue
408 return None
409
410 key = rec.Event.KeyEvent.uChar.UnicodeChar
411
412 if rec.Event.KeyEvent.uChar.UnicodeChar == "\r":
413 # Make enter make unix-like
414 return Event(evt="key", data="\n", raw=b"\n")
415 elif rec.Event.KeyEvent.wVirtualKeyCode == 8:
416 # Turn backspace directly into the command
417 return Event(
418 evt="key",
419 data="backspace",
420 raw=rec.Event.KeyEvent.uChar.UnicodeChar,
421 )
422 elif rec.Event.KeyEvent.uChar.UnicodeChar == "\x00":
423 # Handle special keys like arrow keys and translate them into the appropriate command
424 code = VK_MAP.get(rec.Event.KeyEvent.wVirtualKeyCode)
425 if code:
426 return Event(
427 evt="key", data=code, raw=rec.Event.KeyEvent.uChar.UnicodeChar
428 )
429 if block:
430 continue
431
432 return None
433
434 return Event(evt="key", data=key, raw=rec.Event.KeyEvent.uChar.UnicodeChar)
435
436 def push_char(self, char: int | bytes) -> None:
437 """

Callers

nothing calls this directly

Calls 4

_read_inputMethod · 0.95
EventClass · 0.70
popMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected