class_docstr: A container for a set of key bindings.
  
  Example usage::
  
      kb = KeyBindings()
  
      @kb.add('c-t')
      def _(event):
          print('Control-T pressed')
  
      @kb.add('c-a', 'c-b')
      def _(event):
          print('Control-A pressed, followed by Control-B')
  
      @kb.add('c-x', filter=is_searching)
      def _(event):
          print('Control-X pressed')  # Works only if we are searching.
docstr: Decorator for adding a key bindings.
  
  :param filter: :class:`~prompt_toolkit.filters.Filter` to determine
      when this key binding is active.
  :param eager: :class:`~prompt_toolkit.filters.Filter` or `bool`.
      When True, ignore potential longer matches when this key binding is
      hit. E.g. when there is an active eager key binding for Ctrl-X,
      execute the handler immediately and ignore the key binding for
      Ctrl-X Ctrl-E of which it is a prefix.
  :param is_global: When this key bindings is added to a `Container` or
      `Control`, make it a global (always active) binding.
  :param save_before: Callable that takes an `Event` and returns True if
      we should save the current buffer, before handling the event.
      (That's the default.)
  :param record_in_macro: Record these key bindings when a macro is
      being recorded. (True by default.)
docstr_tok: ["Decorator","for","adding","a","key","bindings",".",":","param","filter",":",":","class",":","`","~prompt_toolkit.filters.Filter","`","to","determine","when","this","key","binding","is","active",".",":","param","eager",":",":","class",":","`","~prompt_toolkit.filters.Filter","`","or","`","bool","`",".","When","True",",","ignore","potential","longer","matches","when","this","key","binding","is","hit",".","E.g",".","when","there","is","an","active","eager","key","binding","for","Ctrl-X",",","execute","the","handler","immediately","and","ignore","the","key","binding","for","Ctrl-X","Ctrl-E","of","which","it","is","a","prefix",".",":","param","is_global",":","When","this","key","bindings","is","added","to","a","`","Container","`","or","`","Control","`",",","make","it","a","global","(","always","active",")","binding",".",":","param","save_before",":","Callable","that","takes","an","`","Event","`","and","returns","True","if","we","should","save","the","current","buffer",",","before","handling","the","event",".","(","That","'s","the","default",".",")",":","param","record_in_macro",":","Record","these","key","bindings","when","a","macro","is","being","recorded",".","(","True","by","default",".",")"]
code: def add(
      self,
      *keys: Keys | str,
      filter: FilterOrBool = True,
      eager: FilterOrBool = False,
      is_global: FilterOrBool = False,
      save_before: Callable[[KeyPressEvent], bool] = (lambda e: True),
      record_in_macro: FilterOrBool = True,
  ) -> Callable[[T], T]:
      """
      Decorator for adding a key bindings.
  
      :param filter: :class:`~prompt_toolkit.filters.Filter` to determine
          when this key binding is active.
      :param eager: :class:`~prompt_toolkit.filters.Filter` or `bool`.
          When True, ignore potential longer matches when this key binding is
          hit. E.g. when there is an active eager key binding for Ctrl-X,
          execute the handler immediately and ignore the key binding for
          Ctrl-X Ctrl-E of which it is a prefix.
      :param is_global: When this key bindings is added to a `Container` or
          `Control`, make it a global (always active) binding.
      :param save_before: Callable that takes an `Event` and returns True if
          we should save the current buffer, before handling the event.
          (That's the default.)
      :param record_in_macro: Record these key bindings when a macro is
          being recorded. (True by default.)
      """
      assert keys
  
      keys = tuple(_parse_key(k) for k in keys)
  
      if isinstance(filter, Never):
          # When a filter is Never, it will always stay disabled, so in that
          # case don't bother putting it in the key bindings. It will slow
          # down every key press otherwise.
          def decorator(func: T) -> T:
              return func
  
      else:
  
          def decorator(func: T) -> T:
              if isinstance(func, Binding):
                  # We're adding an existing Binding object.
                  self.bindings.append(
                      Binding(
                          keys,
                          func.handler,
                          filter=func.filter & to_filter(filter),
                          eager=to_filter(eager) | func.eager,
                          is_global=to_filter(is_global)
                          | func.is_global,
                          save_before=func.save_before,
                          record_in_macro=func.record_in_macro,
                      )
                  )
              else:
                  self.bindings.append(
                      Binding(
                          keys,
                          cast(KeyHandlerCallable, func),
                          filter=filter,
                          eager=eager,
                          is_global=is_global,
                          save_before=save_before,
                          record_in_macro=record_in_macro,
                      )
                  )
              self._clear_cache()
  
              return func
  
      return decorator
  
imports: from __future__ import annotations
  from abc import ABCMeta, abstractmethod, abstractproperty
  from inspect import isawaitable
  from typing import TYPE_CHECKING, Any, Callable, Coroutine, Hashable, Sequence, Tuple, TypeVar, Union, cast
  from prompt_toolkit.cache import SimpleCache
  from prompt_toolkit.filters import FilterOrBool, Never, to_filter
  from prompt_toolkit.keys import KEY_ALIASES, Keys
label_desc: Use image node_id 5 for calling the KeyBindings obj's underlying member method code with example usage: obj.add() and returns: decorator, func, func