Skip to content

feat: implement bufhidden=hide for native terminal toggle #39

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 13, 2025

Conversation

ThomasK33
Copy link
Member

Summary

Implements the core mechanism to preserve terminal processes when hiding windows in the native terminal provider, partially addressing #16.

Key Changes:

  • Add bufhidden=hide setting before window close to prevent job termination
  • Implement helper functions for hiding/showing terminal windows
  • Add buffer visibility detection logic
  • Update toggle behavior to preserve processes during window operations
  • Add comprehensive test suite with realistic mocking

Technical Details

The native terminal provider now uses Neovim's bufhidden=hide option to preserve terminal jobs when windows are closed. This prevents the automatic cleanup that normally occurs when terminal windows are destroyed.

Core Implementation:

  • hide_terminal(): Sets bufhidden=hide before closing window
  • show_hidden_terminal(): Creates new window for existing buffer
  • is_terminal_visible(): Detects if buffer is displayed in any window

Testing

  • All existing tests continue to pass (263 successes)
  • New test suite verifies process preservation behavior (5 additional tests)
  • Tests use realistic mocking to simulate actual Neovim buffer/window lifecycle

Progress on #16

This PR implements the foundational mechanism for process preservation. A follow-up PR will complete the toggle behavior consistency by addressing the different toggling behaviors between providers.

Related: #16

Partially addresses #16 by implementing the core mechanism to preserve
terminal processes when hiding windows. The native terminal provider now
sets bufhidden=hide before closing windows, preventing Neovim from
killing the terminal job when the window is closed.

- Add hide_terminal() helper that sets bufhidden=hide before window close
- Add show_hidden_terminal() to create windows for existing buffers
- Add is_terminal_visible() for buffer visibility detection
- Update toggle() logic to use hide/show instead of close/create
- Add comprehensive test suite for toggle behavior verification
- Optimize logger usage with module-level require

This change enables process preservation during window hiding, laying
the groundwork for full toggle behavior consistency with snacks provider.

Change-Id: I334c00663dc2058eff2c362057e76499700b5e9e
Signed-off-by: Thomas Kosiewski <tk@coder.com>
@ThomasK33 ThomasK33 merged commit 21f984b into main Jun 13, 2025
3 checks passed
@ThomasK33 ThomasK33 deleted the feat/native-terminal-bufhidden-fix branch June 13, 2025 13: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