code: def load_mouse_bindings():
      """
      Key bindings, required for mouse support.
      (Mouse events enter through the key binding system.)
      """
      registry = Registry()
  
      @registry.add_binding(Keys.Vt100MouseEvent)
      def _(event):
          """
          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:])
              mouse_event = {
                  32: MouseEventType.MOUSE_DOWN,
                  35: MouseEventType.MOUSE_UP,
                  96: MouseEventType.SCROLL_UP,
                  97: MouseEventType.SCROLL_DOWN,
              }.get(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:
                  mouse_event = {
                      (0, "M"): MouseEventType.MOUSE_DOWN,
                      (0, "m"): MouseEventType.MOUSE_UP,
                      (64, "M"): MouseEventType.SCROLL_UP,
                      (65, "M"): MouseEventType.SCROLL_DOWN,
                  }.get((mouse_event, m))
              else:
                  mouse_event = {
                      32: MouseEventType.MOUSE_DOWN,
                      35: MouseEventType.MOUSE_UP,
                      96: MouseEventType.SCROLL_UP,
                      97: MouseEventType.SCROLL_DOWN,
                  }.get(mouse_event)
  
          x -= 1
          y -= 1
  
          # Only handle mouse events when we know the window height.
          if (
              event.cli.renderer.height_is_known
              and mouse_event is not None
          ):
              # Take region above the layout into account. The reported
              # coordinates are absolute to the visible part of the terminal.
              try:
                  y -= event.cli.renderer.rows_above_layout
              except HeightIsUnknownError:
                  return
  
              # Call the mouse handler from the renderer.
              handler = (
                  event.cli.renderer.mouse_handlers.mouse_handlers[x, y]
              )
              handler(
                  event.cli,
                  MouseEvent(
                      position=Point(x=x, y=y), event_type=mouse_event
                  ),
              )
  
      @registry.add_binding(Keys.WindowsMouseEvent)
      def _(event):
          """
          Handling of mouse events for Windows.
          """
          assert (
              is_windows()
          )  # This key binding should only exist for Windows.
  
          # Parse data.
          event_type, x, y = event.data.split(";")
          x = int(x)
          y = int(y)
  
          # Make coordinates absolute to the visible part of the terminal.
          screen_buffer_info = (
              event.cli.renderer.output.get_win32_screen_buffer_info()
          )
          rows_above_cursor = (
              screen_buffer_info.dwCursorPosition.Y
              - event.cli.renderer._cursor_pos.y
          )
          y -= rows_above_cursor
  
          # Call the mouse event handler.
          handler = event.cli.renderer.mouse_handlers.mouse_handlers[
              x, y
          ]
          handler(
              event.cli,
              MouseEvent(
                  position=Point(x=x, y=y), event_type=event_type
              ),
          )
  
      return registry
  
file_path: catboost/contrib/python/prompt-toolkit/py2/prompt_toolkit/key_binding/bindings/basic.py
imports: from __future__ import unicode_literals
  from prompt_toolkit.enums import DEFAULT_BUFFER
  from prompt_toolkit.filters import HasSelection, Condition, EmacsInsertMode, ViInsertMode
  from prompt_toolkit.keys import Keys
  from prompt_toolkit.layout.screen import Point
  from prompt_toolkit.mouse_events import MouseEventType, MouseEvent
  from prompt_toolkit.renderer import HeightIsUnknownError
  from prompt_toolkit.utils import suspend_to_background_supported, is_windows
  from .named_commands import get_by_name
  from ..registry import Registry
label_desc: Use image node_id 3 for calling a global function with example usage: load_mouse_bindings() and returns: registry