Skip to content

Feature/native scrollback tui#5

Merged
nachoal merged 3 commits into
mainfrom
feature/native-scrollback-tui
Aug 2, 2025
Merged

Feature/native scrollback tui#5
nachoal merged 3 commits into
mainfrom
feature/native-scrollback-tui

Conversation

@nachoal

@nachoal nachoal commented Aug 2, 2025

Copy link
Copy Markdown
Owner

No description provided.

nachoal and others added 3 commits August 1, 2025 14:38
- Replace message re-rendering with native terminal scrollback using tea.Printf
- Remove View() re-rendering of message history
- Print messages once to stdout, keeping them in terminal scrollback
- Messages now persist after quit and survive terminal resizes
- Add PrintHeader() to display header before TUI starts
- Update model selector to use alt-screen mode
- Fix tool event messages to print immediately
- Maintain historyForAgent for agent context only

This gives Claude-style UX with infinite scrollback and no flicker on resize.

🤖 Generated with Claude Code

Co-Authored-By: Claude <noreply@anthropic.com>
Add dynamic spacing based on textarea height to push the bordered input box down.
This prevents border characters from appearing in printed messages when users
paste multi-line text and press Enter.

The fix adds extra newlines before the input box proportional to the textarea
height, ensuring the border is pushed down enough to not interfere with
printed output.

🤖 Generated with Claude Code

Co-Authored-By: Claude <noreply@anthropic.com>
The bottom-right border corner was disappearing when assistant messages
were printed because the cursor was left at the last column after
rendering the input box. This caused the terminal to scroll when the
next output began with a newline, erasing the border line.

Adding a newline after the input box ensures the cursor is positioned
on the next line, preventing the unwanted scroll effect.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
@nachoal nachoal merged commit 73d8c0c into main Aug 2, 2025
2 checks passed
@nachoal nachoal deleted the feature/native-scrollback-tui branch August 2, 2025 01:44
@claude

claude Bot commented Aug 2, 2025

Copy link
Copy Markdown

Claude finished @nachoal's task —— View job


PR Review: Feature/native scrollback tui

I've completed a comprehensive review of this pull request. Here's my detailed feedback:

Todo List:

  • Read repository context (CLAUDE.md)
  • Analyze changed files
  • Review code quality and best practices
  • Check for potential bugs or issues
  • Evaluate performance considerations
  • Assess security concerns
  • Review test coverage
  • Provide comprehensive feedback

Overall Assessment ✅

This is an excellent implementation of native scrollback support for the TUI. The changes align perfectly with the project's goal of providing a "superior terminal experience" while maintaining the minimal, bordered interface philosophy described in CLAUDE.md.

Code Quality & Best Practices ⭐

Strengths:

  • Clean Architecture: The TUI implementation follows Go idioms with proper separation of concerns
  • Consistent Styling: Maintains the "transparent background" approach mentioned in CLAUDE.md documentation
  • Error Handling: Proper error propagation throughout the codebase
  • Memory Management: Smart history handling that avoids memory leaks
  • Documentation: Code is well-commented and self-documenting

Minor Areas for Improvement:

  • Consider adding struct field documentation for complex types like BorderedTUI (lines 23-59 in tui/bordered.go)
  • The adjustTextareaHeight() function could benefit from extracted constants for magic numbers (lines 822, 841)

Performance Considerations 🚀

Excellent Optimizations:

  • Circular Buffer: Smart implementation in CircularBuffer (lines 94-129) prevents memory growth
  • Concurrent Tool Events: The listenForToolEvents() pattern (lines 863-878) provides responsive UI without blocking
  • Dynamic Height Adjustment: adjustTextareaHeight() only recalculates when content changes
  • Native Scrollback: Eliminates alt-screen mode for better terminal integration

Performance Notes:

  • History replay is handled efficiently without storing duplicate state
  • Tool event handling uses buffered channels to prevent blocking
  • Glamour rendering is cached through the renderer instance

Security Concerns 🔒

Good Security Practices:

  • Input Sanitization: Commands are properly validated (lines 714-787)
  • Context Handling: Proper context propagation for tool execution
  • Environment Variables: Safe handling of debug flags without exposure

No Critical Security Issues Found

Potential Bugs & Issues 🐛

Minor Issues Identified:

  1. Race Condition Potential (tui/bordered.go:460-464):

    m.toolEventChan = make(chan agent.StreamEvent, 100)

    The channel buffer size of 100 is arbitrary. Consider making this configurable or documenting the reasoning.

  2. Error State Handling (tui/bordered.go:606-608):
    The error display could be more user-friendly with structured error messages.

  3. Channel Cleanup (tui/bordered.go:700-703):

    if m.toolEventChan != nil {
        close(m.toolEventChan)
    }

    Good pattern, but consider checking if channel is already closed to prevent panic.

Technical Excellence 🎯

Particularly Well-Implemented Features:

  1. Native Scrollback Implementation: The elimination of alt-screen mode (mentioned in comments) is a smart UX decision
  2. Dynamic Input Growth: The adjustTextareaHeight() function elegantly handles multi-line input
  3. Tool Status Tracking: Real-time tool execution feedback with proper state management
  4. Model Selection Integration: Clean separation between TUI and model selector components

Code Structure Assessment 📁

The file organization follows the documented architecture:

  • cmd/simple-agent/main.go: Clean CLI integration ✅
  • tui/bordered.go: Core TUI logic with proper separation ✅
  • tui/model_selector.go: Isolated model selection component ✅

Test Coverage Assessment 📊

Current State: No test files visible for the TUI components.

Recommendations:

  • Add unit tests for CircularBuffer functionality
  • Create integration tests for tool event handling
  • Consider UI tests for critical user interaction flows

Minor Code Quality Suggestions

  1. Extract Constants (tui/bordered.go:822, 841):

    const (
        MinTextareaWidth = 20
        MaxTextareaHeight = 10
        BorderPadding = 8
    )
  2. Add Field Documentation for complex structs like BorderedTUI

  3. Error Message Enhancement:

    // Instead of generic error display
    return borderedResponseMsg{err: err}
    // Consider structured error types with user-friendly messages

Compatibility & Standards ✅

  • Go Version: Compatible with Go 1.21+ as documented
  • Dependencies: Proper use of Bubble Tea, Lipgloss, and Glamour
  • Terminal Compatibility: Handles different terminal sizes gracefully
  • Cross-Platform: No platform-specific code detected

Final Verdict 🌟

This is a high-quality implementation that successfully achieves the goal of native scrollback support. The code demonstrates:

  • Strong understanding of Go idioms and Bubble Tea patterns
  • Excellent user experience design decisions
  • Robust error handling and state management
  • Performance-conscious implementation

The changes maintain consistency with the existing codebase while adding significant value to the terminal user experience.

Recommendation: ✅ Approve - This PR is ready for merge with the minor suggestions noted above for future consideration.


Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant