code: def has_focus(value: FocusableElement) -> Condition:
      """
      Enable when this buffer has the focus.
      """
      from prompt_toolkit.buffer import Buffer
      from prompt_toolkit.layout import walk
      from prompt_toolkit.layout.containers import (
          Container,
          Window,
          to_container,
      )
      from prompt_toolkit.layout.controls import UIControl
  
      if isinstance(value, str):
  
          def test() -> bool:
              return get_app().current_buffer.name == value
  
      elif isinstance(value, Buffer):
  
          def test() -> bool:
              return get_app().current_buffer == value
  
      elif isinstance(value, UIControl):
  
          def test() -> bool:
              return get_app().layout.current_control == value
  
      else:
          value = to_container(value)
  
          if isinstance(value, Window):
  
              def test() -> bool:
                  return get_app().layout.current_window == value
  
          else:
  
              def test() -> bool:
                  # Consider focused when any window inside this container is
                  # focused.
                  current_window = get_app().layout.current_window
  
                  for c in walk(cast(Container, value)):
                      if isinstance(c, Window) and c == current_window:
                          return True
                  return False
  
      @Condition
      def has_focus_filter() -> bool:
          return test()
  
      return has_focus_filter
  
imports: from __future__ import annotations
  from typing import TYPE_CHECKING, cast
  from prompt_toolkit.application.current import get_app
  from prompt_toolkit.cache import memoized
  from prompt_toolkit.enums import EditingMode
  from .base import Condition
label_desc: Use image node_id 1 for calling a global function with example usage: has_focus(value) and returns: has_focus_filter, test, unknown, unknown, unknown, unknown, False, True