conemu.py 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. from __future__ import annotations
  2. import sys
  3. assert sys.platform == "win32"
  4. from typing import Any, TextIO
  5. from prompt_toolkit.data_structures import Size
  6. from .base import Output
  7. from .color_depth import ColorDepth
  8. from .vt100 import Vt100_Output
  9. from .win32 import Win32Output
  10. __all__ = [
  11. "ConEmuOutput",
  12. ]
  13. class ConEmuOutput:
  14. """
  15. ConEmu (Windows) output abstraction.
  16. ConEmu is a Windows console application, but it also supports ANSI escape
  17. sequences. This output class is actually a proxy to both `Win32Output` and
  18. `Vt100_Output`. It uses `Win32Output` for console sizing and scrolling, but
  19. all cursor movements and scrolling happens through the `Vt100_Output`.
  20. This way, we can have 256 colors in ConEmu and Cmder. Rendering will be
  21. even a little faster as well.
  22. http://conemu.github.io/
  23. http://gooseberrycreative.com/cmder/
  24. """
  25. def __init__(
  26. self, stdout: TextIO, default_color_depth: ColorDepth | None = None
  27. ) -> None:
  28. self.win32_output = Win32Output(stdout, default_color_depth=default_color_depth)
  29. self.vt100_output = Vt100_Output(
  30. stdout, lambda: Size(0, 0), default_color_depth=default_color_depth
  31. )
  32. @property
  33. def responds_to_cpr(self) -> bool:
  34. return False # We don't need this on Windows.
  35. def __getattr__(self, name: str) -> Any:
  36. if name in (
  37. "get_size",
  38. "get_rows_below_cursor_position",
  39. "enable_mouse_support",
  40. "disable_mouse_support",
  41. "scroll_buffer_to_prompt",
  42. "get_win32_screen_buffer_info",
  43. "enable_bracketed_paste",
  44. "disable_bracketed_paste",
  45. ):
  46. return getattr(self.win32_output, name)
  47. else:
  48. return getattr(self.vt100_output, name)
  49. Output.register(ConEmuOutput)