Skip to content

Conversation

@ditahkk
Copy link

@ditahkk ditahkk commented Oct 8, 2025

This PR adds comprehensive dimension control and a robust layout system to the fuzzy finder, providing greater control over its appearance and fixing critical feature coordination issues.

Key Changes:

  • Customizable Border

    • Introduced WithBorder() and WithBorderChars() options to enable and style a window border.
    • The rendering logic was updated to draw the border and adjust UI element coordinates.
    • The default border style is ╭╮╰╯─│.
  • Configurable Height and Width

    • Added WithHeight() and WithWidth() options to set fixed dimensions.
    • The fuzzy finder now respects these dimensions, falling back to the terminal size if not specified.
    • Fixed: When WithHeight() is used, the finder now positions at the bottom of the terminal (like fzf), not centered.
  • Layout System Architecture (Major Refactor)

    • Created centralized Layout abstraction system with rect type for rectangular areas.
    • Implemented computeLayout() function as single source of truth for all UI component positions.
    • Refactored all drawing functions (_draw(), _drawPreview(), _drawBorder()) to use shared layout coordinates.
    • Fixed critical coordination issues:
      • Preview panel now respects height limits and border offsets correctly
      • All features (border, preview, height/width constraints) now coordinate properly
      • Eliminated independent coordinate calculations that caused conflicts
    • Added comprehensive test suite for layout validation and edge cases.
  • Code Quality Improvements

    • Removed unused listWidth() function.
    • Updated golden test files for new correct rendering behavior.
    • All code properly formatted with zero compiler warnings.
    • Added extensive unit and integration tests for layout system.
  • Dependency Management & Fixes

    • Added go-isatty and pflag dependencies for the example application.
    • Fixed unused parameter bug and removed unused variables.
  • Example and Documentation

    • Updated the example CLI to demonstrate custom border characters.
    • Added a "Development" section to README.md with build and test instructions.

Technical Details:

Before: Features calculated positions independently, causing conflicts:

  • Preview panel ignored height limits (used f.term.Size() directly)
  • Preview panel ignored border offsets (drew at absolute coordinates)
  • Height-constrained boxes were centered instead of bottom-aligned
  • 100+ lines of redundant offset calculations scattered across drawing functions

After: Clean architecture with single layout calculation:

  • All features use shared Layout struct with pre-calculated coordinates
  • Preview panel properly respects all constraints
  • Bottom-aligned positioning when height is constrained
  • Easy to add new features (footer, multi-column, etc.)
  • Fully testable layout logic in isolation

Testing:

All tests pass (1.6s runtime):

  • ✅ Unit tests for rect helper methods
  • ✅ Layout validation tests for edge cases
  • ✅ Integration tests for all option combinations
  • ✅ Updated golden files for correct rendering behavior
  • ✅ Zero warnings or errors

Breaking Changes:

None. While the internal architecture was significantly refactored, the public API remains unchanged and all existing tests pass.

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