code: def load_mouse_bindings() -> KeyBindings:
      """
      Key bindings, required for mouse support.
      (Mouse events enter through the key binding system.)
      """
      key_bindings = KeyBindings()
  
      @key_bindings.add(Keys.Vt100MouseEvent)
      def _(event: E) -> NotImplementedOrNone:
          """
          Handling of incoming mouse event.
          """
          # TypicaL:   "eSC[MaB*"
          # Urxvt:     "Esc[96;14;13M"
          # Xterm SGR: "Esc[<64;85;12M"
  
          # Parse incoming packet.
          if event.data[2] == "M":
              # Typical.
              mouse_event, x, y = map(ord, event.data[3:])
  
              # TODO: Is it possible to add modifiers here?
              (
                  mouse_button,
                  mouse_event_type,
                  mouse_modifiers,
              ) = typical_mouse_events[mouse_event]
  
              # Handle situations where `PosixStdinReader` used surrogateescapes.
              if x >= 0xDC00:
                  x -= 0xDC00
              if y >= 0xDC00:
                  y -= 0xDC00
  
              x -= 32
              y -= 32
          else:
              # Urxvt and Xterm SGR.
              # When the '<' is not present, we are not using the Xterm SGR mode,
              # but Urxvt instead.
              data = event.data[2:]
              if data[:1] == "<":
                  sgr = True
                  data = data[1:]
              else:
                  sgr = False
  
              # Extract coordinates.
              mouse_event, x, y = map(int, data[:-1].split(";"))
              m = data[-1]
  
              # Parse event type.
              if sgr:
                  try:
                      (
                          mouse_button,
                          mouse_event_type,
                          mouse_modifiers,
                      ) = xterm_sgr_mouse_events[mouse_event, m]
                  except KeyError:
                      return NotImplemented
  
              else:
                  # Some other terminals, like urxvt, Hyper terminal, ...
                  (
                      mouse_button,
                      mouse_event_type,
                      mouse_modifiers,
                  ) = urxvt_mouse_events.get(
                      mouse_event,
                      (UNKNOWN_BUTTON, MOUSE_MOVE, UNKNOWN_MODIFIER),
                  )
  
          x -= 1
          y -= 1
  
          # Only handle mouse events when we know the window height.
          if (
              event.app.renderer.height_is_known
              and mouse_event_type is not None
          ):
              # Take region above the layout into account. The reported
              # coordinates are absolute to the visible part of the terminal.
              from prompt_toolkit.renderer import HeightIsUnknownError
  
              try:
                  y -= event.app.renderer.rows_above_layout
              except HeightIsUnknownError:
                  return NotImplemented
  
              # Call the mouse handler from the renderer.
  
              # Note: This can return `NotImplemented` if no mouse handler was
              #       found for this position, or if no repainting needs to
              #       happen. this way, we avoid excessive repaints during mouse
              #       movements.
              handler = (
                  event.app.renderer.mouse_handlers.mouse_handlers[y][x]
              )
              return handler(
                  MouseEvent(
                      position=Point(x=x, y=y),
                      event_type=mouse_event_type,
                      button=mouse_button,
                      modifiers=mouse_modifiers,
                  )
              )
  
          return NotImplemented
  
      @key_bindings.add(Keys.ScrollUp)
      def _scroll_up(event: E) -> None:
          """
          Scroll up event without cursor position.
          """
          # We don't receive a cursor position, so we don't know which window to
          # scroll. Just send an 'up' key press instead.
          event.key_processor.feed(KeyPress(Keys.Up), first=True)
  
      @key_bindings.add(Keys.ScrollDown)
      def _scroll_down(event: E) -> None:
          """
          Scroll down event without cursor position.
          """
          event.key_processor.feed(KeyPress(Keys.Down), first=True)
  
      @key_bindings.add(Keys.WindowsMouseEvent)
      def _mouse(event: E) -> NotImplementedOrNone:
          """
          Handling of mouse events for Windows.
          """
          # This key binding should only exist for Windows.
          if sys.platform == "win32":
              # Parse data.
              pieces = event.data.split(";")
  
              button = MouseButton(pieces[0])
              event_type = MouseEventType(pieces[1])
              x = int(pieces[2])
              y = int(pieces[3])
  
              # Make coordinates absolute to the visible part of the terminal.
              output = event.app.renderer.output
  
              from prompt_toolkit.output.win32 import Win32Output
              from prompt_toolkit.output.windows10 import (
                  Windows10_Output,
              )
  
              if isinstance(output, (Win32Output, Windows10_Output)):
                  screen_buffer_info = (
                      output.get_win32_screen_buffer_info()
                  )
                  rows_above_cursor = (
                      screen_buffer_info.dwCursorPosition.Y
                      - event.app.renderer._cursor_pos.y
                  )
                  y -= rows_above_cursor
  
                  # Call the mouse event handler.
                  # (Can return `NotImplemented`.)
                  handler = (
                      event.app.renderer.mouse_handlers.mouse_handlers[
                          y
                      ][x]
                  )
  
                  return handler(
                      MouseEvent(
                          position=Point(x=x, y=y),
                          event_type=event_type,
                          button=button,
                          modifiers=UNKNOWN_MODIFIER,
                      )
                  )
  
          # No mouse handler found. Return `NotImplemented` so that we don't
          # invalidate the UI.
          return NotImplemented
  
      return key_bindings
  
file_path: catboost/contrib/python/prompt-toolkit/py3/prompt_toolkit/key_binding/bindings/mouse.py
imports: from __future__ import annotations
  import sys
  from typing import TYPE_CHECKING
  from prompt_toolkit.data_structures import Point
  from prompt_toolkit.key_binding.key_processor import KeyPress, KeyPressEvent
  from prompt_toolkit.keys import Keys
  from prompt_toolkit.mouse_events import MouseButton, MouseEvent, MouseEventType, MouseModifier
  from ..key_bindings import KeyBindings
label_desc: Use image node_id 1 for calling a global function with example usage: load_mouse_bindings() and returns: key_bindings, NotImplemented, NotImplemented, handler, handler, NotImplemented, NotImplemented