Skip to content

Add FloatingWindow class for overlay UI elements#184

Merged
shugo merged 4 commits intomainfrom
feature/floating-window
Feb 3, 2026
Merged

Add FloatingWindow class for overlay UI elements#184
shugo merged 4 commits intomainfrom
feature/floating-window

Conversation

@shugo
Copy link
Owner

@shugo shugo commented Jan 29, 2026

Implement FloatingWindow as a Window subclass using Curses::Pad for overlay rendering capabilities. This enables popup menus, tooltips, and other temporary UI elements without disrupting the window layout.

Features:

  • Window subclass with dedicated buffer per instance
  • Curses::Pad for overlay rendering on top of existing windows
  • Factory methods: at_cursor, centered
  • Face support for customizable colors and styling
  • Cursor position management (focus stays in editing window)
  • Auto-cleanup of generated buffers

Implementation:

  • lib/textbringer/floating_window.rb: Core FloatingWindow class (250 lines)
  • lib/textbringer/faces/basic.rb: Define :floating_window face
  • lib/textbringer/window.rb: Integrate floating window redisplay
  • lib/textbringer.rb: Add require for floating_window
  • test/textbringer/test_floating_window.rb: 24 tests, 68 assertions

Test results: 442 tests, 1946 assertions, 100% pass, 95.03% coverage

🤖 Generated with Claude Code

shugo and others added 3 commits January 28, 2026 23:14
Implement FloatingWindow as a Window subclass using Curses::Pad for
overlay rendering capabilities. This enables popup menus, tooltips,
and other temporary UI elements without disrupting the window layout.

Features:
- Window subclass with dedicated buffer per instance
- Curses::Pad for overlay rendering on top of existing windows
- Factory methods: at_cursor, centered
- Face support for customizable colors and styling
- Cursor position management (focus stays in editing window)
- Auto-cleanup of generated buffers

Implementation:
- lib/textbringer/floating_window.rb: Core FloatingWindow class (250 lines)
- lib/textbringer/faces/basic.rb: Define :floating_window face
- lib/textbringer/window.rb: Integrate floating window redisplay
- lib/textbringer.rb: Add require for floating_window
- test/textbringer/test_floating_window.rb: 24 tests, 68 assertions

Test results: 442 tests, 1946 assertions, 100% pass, 95.03% coverage

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

Co-Authored-By: Claude <noreply@anthropic.com>
Implement FakeCursesPad in test_helper.rb to enable proper testing
of FloatingWindow which uses Curses::Pad instead of Curses::Window.

FakeCursesPad provides:
- Basic pad methods: erase, setpos, addstr
- Attribute methods: attron, attroff, attrset
- Refresh method: noutrefresh (no-op for testing)
- method_missing for unimplemented methods

This follows the same pattern as FakeCursesWindow and ensures
FloatingWindow tests can run without requiring an actual terminal.

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

Co-Authored-By: Claude <noreply@anthropic.com>
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR introduces a FloatingWindow class that extends Window to support overlay UI elements like popup menus and tooltips. The implementation uses Curses::Pad for rendering on top of existing windows without disrupting the layout.

Changes:

  • New FloatingWindow class with factory methods for positioning (at_cursor, centered)
  • Face support for customizable styling
  • Window class integration for floating window redisplay
  • Comprehensive test suite with 24 tests and 68 assertions

Reviewed changes

Copilot reviewed 6 out of 6 changed files in this pull request and generated 6 comments.

Show a summary per file
File Description
lib/textbringer/floating_window.rb Core FloatingWindow class with overlay rendering via Curses::Pad
lib/textbringer/window.rb Integration for floating window redisplay and cursor exposure
lib/textbringer/faces/basic.rb Define default :floating_window face
lib/textbringer.rb Add require for floating_window module
test/textbringer/test_floating_window.rb Comprehensive test suite for FloatingWindow
test/test_helper.rb FakeCursesPad mock for testing

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.


# Prefer below cursor
space_below = Curses.lines - cursor_y - 2 # -2 for echo area
space_above = cursor_y - window.y
Copy link

Copilot AI Jan 30, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The calculation of space_above is incorrect. Currently it computes cursor_y - window.y which equals window.cursor.y, giving the cursor position within the window rather than the actual screen space above the cursor. It should be just cursor_y to get the screen space available above the cursor position.

Suggested change
space_above = cursor_y - window.y
space_above = cursor_y

Copilot uses AI. Check for mistakes.
- Add current_line_face parameter to highlight the line containing point
- Fix resource leak in resize method (close old_window)
- Fix space_above calculation in calculate_cursor_position

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@shugo shugo merged commit dbbeff0 into main Feb 3, 2026
7 checks passed
@shugo shugo deleted the feature/floating-window branch February 3, 2026 02:38
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