fix: prevent Ctrl+C from killing bat when paging without -K
          #3447
        
          
      
  Add this suggestion to a batch that can be applied as a single commit.
  This suggestion is invalid because no changes were made to the code.
  Suggestions cannot be applied while the pull request is closed.
  Suggestions cannot be applied while viewing a subset of changes.
  Only one suggestion per line can be applied in a batch.
  Add this suggestion to a batch that can be applied as a single commit.
  Applying suggestions on deleted lines is not supported.
  You must change the existing code in this line in order to create a valid suggestion.
  Outdated suggestions cannot be applied.
  This suggestion has been applied or marked resolved.
  Suggestions cannot be applied from pending reviews.
  Suggestions cannot be applied on multi-line comments.
  Suggestions cannot be applied while the pull request is queued to merge.
  Suggestion cannot be applied right now. Please check back later.
  
    
  
    
--quit-on-intr#3444Bug
When
BAT_PAGER='less -R'is set (without-K), pressing Ctrl-C still exitslessimmediately instead of canceling the current operation and staying open. This happens because bat receives SIGINT and begins teardown, which causeslessto lose access to the TTY and exit with EIO.Solution
Use
signal-hookto temporarily ignore SIGINT in bat while the pager is active. This allowslessto handle Ctrl-C independently. When the pager exits, the signal handler is automatically restored via RAII.Specifically I registered a dummy flag that's never checked. This prevents the default SIGINT handler from terminating the process, effectively ignoring the signal.
Changes
IgnoreSigintRAII guard that ignores SIGINT while aliveChildinPagerProcstruct to carry the signal guardNow Ctrl-C behaves correctly in
less:-K: cancels search/operation, stays open-K: exits immediately (existing behavior preserved)Demo
Before: Ctrl C closes the pager but neither does the terminal fully regain control. You have to press Ctrl + C again
After: Ctrl + C sends SIGINT and bat actively ignores it, hence does not kill the pager process via teardown
Status