Chat byte budget rides the input line and can no longer vanish

The counter was its own last body line, and the pinned day-divider
header reserves the top viewport row without relaxing the bottom scroll
clamp - so exactly when the transcript filled the screen, the counter
fell off the bottom. The budget now trails the compose text inline
(wrapping along with it, costing no row), and the frame slides the
window down a row when a sticky header is pinned at the very bottom,
so the last body line always wins over the duplicate heading.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This commit is contained in:
Jean-Pierre MartineauandClaude Fable 5 committed 2026-07-11 18:44:39 -04:00
1 parent 872156b388
commit 21c5017706
3 files changed
+29 -13

No files matched your search

+12 -9
View File
@@ -200,11 +200,15 @@ class ChatScreen(Screen):
lines = self._render_grouped(width)
limit = self._byte_limit()
used = self._used_bytes()
# The byte budget rides the input line itself (no row of its own): it trails
# the cursor and wraps along with a long compose, so it is exactly as visible
# as the input — never the one line a full transcript pushes off the bottom.
input_line = self._editor.render(overflow_at=self._overflow_at(limit))
input_line.append(" ")
input_line.append_text(self._byte_counter(limit))
footer_parts: list[RenderableType] = [
Text("─" * width, style="muted"),
self._editor.render(overflow_at=self._overflow_at(limit)),
self._byte_counter(width, used, limit),
input_line,
]
if self._is_channel and self._selected is not None:
footer_parts.append(self._reply_banner())
@@ -245,18 +249,17 @@ class ChatScreen(Screen):
return i
return None
def _byte_counter(self, width: int, used: int, limit: int) -> Text:
"""Right-aligned ``used/limit`` budget; only ``used`` is colored by how much is left.
def _byte_counter(self, limit: int) -> Text:
"""The inline ``used/limit`` budget; only ``used`` is colored by how much is left.
Green with room to spare, yellow within :data:`_BYTES_TIGHT` bytes, orange within
:data:`_BYTES_LOW`, and red once the limit is met or exceeded — so the number reads as
a fuel gauge while the ``/limit`` suffix stays muted (it never changes).
"""
tail = f"/{limit}"
pad = max(0, width - len(str(used)) - len(tail))
counter = Text(" " * pad)
used = self._used_bytes()
counter = Text()
counter.append(str(used), style=self._byte_style(limit - used))
counter.append(tail, style="muted")
counter.append(f"/{limit}", style="muted")
return counter
@staticmethod
+9 -2
View File
@@ -66,8 +66,15 @@ def _visible_slice(screen: Screen, lines: list[str], viewport: int) -> tuple[lis
if sticky is not None:
cap = max(1, viewport - 1)
visible = [sticky] + lines[scroll : scroll + cap]
more_below = scroll + cap < total
start = scroll
if scroll >= total - viewport and total > cap:
# Scrolled fully to the bottom: the pinned header's reserved row must not
# cost the *last* body line (a chat's input row would vanish exactly when
# the transcript fills the screen). Slide the window down one instead —
# the dropped row is at the top, right under the pin, where it's stale.
start = min(scroll + 1, total - cap)
visible = [sticky] + lines[start : start + cap]
more_below = start + cap < total
visible = visible + [""] * (viewport - len(visible))
return visible, True, more_below
+8 -2
View File
@@ -551,15 +551,21 @@ async def test_direct_send_spins_until_the_ack_resolves(monkeypatch) -> None:
def test_byte_counter_shows_used_over_limit_and_colors_only_used() -> None:
"""The compose bar shows ``used/limit`` with only the used count styled (the max is muted)."""
"""The inline budget shows ``used/limit`` with only the used count styled (the max is muted)."""
from rich.text import Text
screen = _screen(_StubSession(), send=None)
for ch in "hello":
screen.handle("text", ch)
counter = screen._byte_counter(80, screen._used_bytes(), screen._byte_limit())
counter = screen._byte_counter(screen._byte_limit())
assert isinstance(counter, Text)
assert counter.plain.strip() == "5/150" # 5 bytes used of the 150-byte direct-message cap
# The budget rides the input line itself, right after the compose text, so it can
# never be the one row a full transcript pushes off the bottom of the viewport.
import re
body = re.sub(r"\x1b\[[0-9;]*m", "", "\n".join(screen.render_body(80)))
assert re.search(r"› hello.*5/150", body)
# Only the "5" carries a color; the "/150" tail stays muted (it never changes).
used_at = counter.plain.index("5")
slash_at = counter.plain.index("/")