Fix output area to show content at bottom

- Use HSplit with filler + output to push content to bottom
- Output window uses dont_extend_height so it only takes needed space
- Empty filler expands to fill remaining space above

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
dullfig 2026-01-11 14:52:33 -08:00
parent d59dd4968d
commit ce37278dcd

View file

@ -106,8 +106,8 @@ class OutputBuffer:
self.lines = self.lines[-self.max_lines:] self.lines = self.lines[-self.max_lines:]
def get_formatted_text(self) -> FormattedText: def get_formatted_text(self) -> FormattedText:
"""Get formatted text for display - only show last N lines.""" """Get formatted text for display - show last N lines."""
# Only return the most recent lines that fit on screen # Only return the most recent lines
visible = self.lines[-self.visible_lines:] if len(self.lines) > self.visible_lines else self.lines visible = self.lines[-self.visible_lines:] if len(self.lines) > self.visible_lines else self.lines
result = [] result = []
for style, text in visible: for style, text in visible:
@ -188,24 +188,27 @@ class TUIConsole:
"""Handle Ctrl+L - clear output.""" """Handle Ctrl+L - clear output."""
self.output.clear() self.output.clear()
# Output area (scrolling) - use scroll_offsets to keep bottom visible # Output control
output_control = FormattedTextControl( output_control = FormattedTextControl(
text=lambda: self.output.get_formatted_text(), text=lambda: self.output.get_formatted_text(),
focusable=False, focusable=False,
) )
# Create window that always scrolls to bottom # Output window - don't extend height, just show what we have
from prompt_toolkit.layout.controls import UIContent
output_window = Window( output_window = Window(
content=output_control, content=output_control,
wrap_lines=True, wrap_lines=True,
right_margins=[ScrollbarMargin(display_arrows=True)], dont_extend_height=True, # Only take space needed
always_hide_cursor=True,
) )
# Store reference so we can scroll # Empty filler that expands to push output to bottom
self.output_window = output_window filler = Window(height=Dimension(weight=1))
# Upper area: filler on top, output at bottom
upper_area = HSplit([
filler,
output_window,
])
# Separator line with status # Separator line with status
def get_separator(): def get_separator():
@ -243,7 +246,7 @@ class TUIConsole:
# Main layout # Main layout
root = HSplit([ root = HSplit([
output_window, upper_area, # Filler + output (output at bottom)
separator, separator,
input_row, input_row,
]) ])