dummy.py 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. from __future__ import annotations
  2. from typing import Callable
  3. from prompt_toolkit.eventloop import InputHook
  4. from prompt_toolkit.formatted_text import AnyFormattedText
  5. from prompt_toolkit.input import DummyInput
  6. from prompt_toolkit.output import DummyOutput
  7. from .application import Application
  8. __all__ = [
  9. "DummyApplication",
  10. ]
  11. class DummyApplication(Application[None]):
  12. """
  13. When no :class:`.Application` is running,
  14. :func:`.get_app` will run an instance of this :class:`.DummyApplication` instead.
  15. """
  16. def __init__(self) -> None:
  17. super().__init__(output=DummyOutput(), input=DummyInput())
  18. def run(
  19. self,
  20. pre_run: Callable[[], None] | None = None,
  21. set_exception_handler: bool = True,
  22. handle_sigint: bool = True,
  23. in_thread: bool = False,
  24. inputhook: InputHook | None = None,
  25. ) -> None:
  26. raise NotImplementedError("A DummyApplication is not supposed to run.")
  27. async def run_async(
  28. self,
  29. pre_run: Callable[[], None] | None = None,
  30. set_exception_handler: bool = True,
  31. handle_sigint: bool = True,
  32. slow_callback_duration: float = 0.5,
  33. ) -> None:
  34. raise NotImplementedError("A DummyApplication is not supposed to run.")
  35. async def run_system_command(
  36. self,
  37. command: str,
  38. wait_for_enter: bool = True,
  39. display_before_text: AnyFormattedText = "",
  40. wait_text: str = "",
  41. ) -> None:
  42. raise NotImplementedError
  43. def suspend_to_background(self, suspend_group: bool = True) -> None:
  44. raise NotImplementedError