Skip to content

Fix curses frame display corruption issue#3

Open
morria wants to merge 2 commits into
mainfrom
claude/fix-curses-frame-mangling-01C8MdhRxPvk3ny8PgPATMC1
Open

Fix curses frame display corruption issue#3
morria wants to merge 2 commits into
mainfrom
claude/fix-curses-frame-mangling-01C8MdhRxPvk3ny8PgPATMC1

Conversation

@morria

@morria morria commented Nov 15, 2025

Copy link
Copy Markdown
Owner

The original curses implementation had height accounting problems where the waterfall would overflow and mangle the display when it hit the bottom of the window. This manifested as:

  • Top of waterfall getting pushed above the screen
  • Debug output wrapping incorrectly at the bottom

This migration to Textual fixes these issues through:

  • Proper CSS-based layout system with 'height: 1fr' for waterfall
  • Automatic height management in WaterfallWidget.render()
  • Explicit trimming of time_series to available widget height
  • Better separation of concerns with dedicated widget classes
  • Improved border accounting (available_height = height - 2)

The Textual framework provides better abstractions for TUI layout and automatically handles window resizing, eliminating manual height calculation errors.

All original features preserved:

  • Real-time spectrum graph with sub-character resolution
  • Scrolling waterfall display
  • Peak hold mode
  • Pause/resume
  • Dynamic sensitivity adjustment
  • Help overlay
  • Keyboard shortcuts

The original curses implementation had height accounting problems where
the waterfall would overflow and mangle the display when it hit the
bottom of the window. This manifested as:
- Top of waterfall getting pushed above the screen
- Debug output wrapping incorrectly at the bottom

This migration to Textual fixes these issues through:
- Proper CSS-based layout system with 'height: 1fr' for waterfall
- Automatic height management in WaterfallWidget.render()
- Explicit trimming of time_series to available widget height
- Better separation of concerns with dedicated widget classes
- Improved border accounting (available_height = height - 2)

The Textual framework provides better abstractions for TUI layout and
automatically handles window resizing, eliminating manual height
calculation errors.

All original features preserved:
- Real-time spectrum graph with sub-character resolution
- Scrolling waterfall display
- Peak hold mode
- Pause/resume
- Dynamic sensitivity adjustment
- Help overlay
- Keyboard shortcuts
When running with piped input (hackrf_sweep | ./spectrum_analyzer.py),
there were several issues:

1. Race condition: Data thread started in __init__ before app mounted
   - Moved thread start to on_mount() method
   - Prevents call_from_thread() before event loop ready

2. Poor exception handling in data worker thread
   - Added specific KeyboardInterrupt handler
   - Added try/except around call_from_thread()
   - Proper cleanup in finally block
   - Better logging with exc_info

3. Missing /dev/tty accessibility check
   - Added check to verify /dev/tty is accessible
   - Provides clear error message if running non-interactively
   - Textual auto-detects and uses /dev/tty when stdin is piped

4. Unhandled exceptions in run_spectrum_analyzer
   - Wrapped app.run() with proper exception handling
   - Graceful KeyboardInterrupt handling

These fixes ensure the app:
- Properly handles stdin as data pipe while using /dev/tty for UI
- Doesn't crash on Ctrl+C
- Exits cleanly when data stream ends
- Provides helpful error messages for configuration issues
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.

2 participants