cli_footer_split.py 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. """Root container of the classic CLI footer: clips a late row instead of giving up.
  2. prompt_toolkit renders a non-full-screen layout into exactly the height it measured a moment
  3. earlier (``Renderer.render`` → ``HSplit.preferred_height``), then ``HSplit._divide_heights``
  4. measures every child again while painting. Each footer row here has a callable height that the
  5. agent thread flips mid-turn (``_agent_running`` → spacer, ``_spinner_text`` → spinner,
  6. ``_command_running`` → hint), so a row appearing between the two passes makes the summed minimum
  7. exceed the budget by one and stock ``HSplit`` replaces the WHOLE footer with its
  8. " Window too small... " placeholder (#57393) — on any terminal size, including a maximised 200×50
  9. pane. Hermes's throttled ``_invalidate`` can then drop the healing repaint for the length of a
  10. tool call, so the placeholder sits there looking like a geometry error.
  11. """
  12. from __future__ import annotations
  13. from prompt_toolkit.application import get_app
  14. from prompt_toolkit.layout import HSplit
  15. class FooterSplit(HSplit):
  16. """``HSplit`` whose overflow path keeps the composer on screen and repaints right away.
  17. When the base class would paint the placeholder, allocate the children's minimum heights
  18. bottom-up (composer, rules and status bar first) so only the row that appeared late — always
  19. above them — loses its row for this one frame, and schedule an unthrottled redraw so the
  20. next frame measures and paints against the same state.
  21. """
  22. def _divide_heights(self, write_position) -> list[int] | None:
  23. sizes = super()._divide_heights(write_position)
  24. if sizes is not None:
  25. return sizes
  26. budget = write_position.height
  27. clipped: list[int] = []
  28. for child in reversed(self._all_children):
  29. rows = min(child.preferred_height(write_position.width, budget).min, budget)
  30. budget -= rows
  31. clipped.append(rows)
  32. get_app().invalidate()
  33. return clipped[::-1]