Skip to content

Commit

Permalink
If the bell is flashing but not audible, and it is ringing out of con…
Browse files Browse the repository at this point in the history
…trol, offer to suppress all output. Don't offer to silence an inaudible bell, which is kind of silly. Issue 4366
  • Loading branch information
gnachman committed Mar 1, 2016
1 parent 87359ec commit 816be04
Show file tree
Hide file tree
Showing 4 changed files with 77 additions and 42 deletions.
2 changes: 1 addition & 1 deletion iTerm2XCTests/VT100ScreenTest.m
Original file line number Diff line number Diff line change
Expand Up @@ -833,7 +833,7 @@ - (BOOL)screenShouldPostTerminalGeneratedAlert {
return NO;
}

- (BOOL)screenShouldIgnoreBell {
- (BOOL)screenShouldIgnoreBellWhichIsAudible:(BOOL)audible visible:(BOOL)visible {
return NO;
}

Expand Down
111 changes: 72 additions & 39 deletions sources/PTYSession.m
Original file line number Diff line number Diff line change
Expand Up @@ -6832,7 +6832,7 @@ - (void)resumeOutputIfNeeded {
}
}

- (BOOL)screenShouldIgnoreBell {
- (BOOL)screenShouldIgnoreBellWhichIsAudible:(BOOL)audible visible:(BOOL)visible {
NSTimeInterval now = [NSDate timeIntervalSinceReferenceDate];
if (now < _ignoreBellUntil) {
return YES;
Expand Down Expand Up @@ -6878,44 +6878,77 @@ - (BOOL)screenShouldIgnoreBell {
!existingAnnouncement &&
(now - _annoyingBellOfferDeclinedAt > kTimeToWaitAfterDecline) &&
![[NSUserDefaults standardUserDefaults] boolForKey:kSuppressAnnoyingBellOffer]) {
iTermAnnouncementViewController *announcement =
[iTermAnnouncementViewController announcementWithTitle:@"The bell is ringing a lot. Silence it?"
style:kiTermAnnouncementViewStyleQuestion
withActions:@[ @"Silence Bell Temporarily",
@"Suppress All Output",
@"Don't Offer Again",
@"Silence Automatically" ]
completion:^(int selection) {
// Release the moving average so the count will restart after the announcement goes away.
[_bellRate release];
_bellRate = nil;
switch (selection) {
case -2: // Dismiss programmatically
break;

case -1: // No
_annoyingBellOfferDeclinedAt = [NSDate timeIntervalSinceReferenceDate];
break;

case 0: // Suppress bell temporarily
_ignoreBellUntil = now + 60;
break;

case 1: // Suppress all output
_suppressAllOutput = YES;
break;

case 2: // Never offer again
[[NSUserDefaults standardUserDefaults] setBool:YES
forKey:kSuppressAnnoyingBellOffer];
break;

case 3: // Silence automatically
[[NSUserDefaults standardUserDefaults] setBool:YES
forKey:kSilenceAnnoyingBellAutomatically];
break;
}
}];
iTermAnnouncementViewController *announcement = nil;
if (audible || visible) {
announcement =
[iTermAnnouncementViewController announcementWithTitle:@"The bell is ringing a lot. Silence it?"
style:kiTermAnnouncementViewStyleQuestion
withActions:@[ @"Silence Bell Temporarily",
@"Suppress All Output",
@"Don't Offer Again",
@"Silence Automatically" ]
completion:^(int selection) {
// Release the moving average so the count will restart after the announcement goes away.
[_bellRate release];
_bellRate = nil;
switch (selection) {
case -2: // Dismiss programmatically
break;

case -1: // No
_annoyingBellOfferDeclinedAt = [NSDate timeIntervalSinceReferenceDate];
break;

case 0: // Suppress bell temporarily
_ignoreBellUntil = now + 60;
break;

case 1: // Suppress all output
_suppressAllOutput = YES;
break;

case 2: // Never offer again
[[NSUserDefaults standardUserDefaults] setBool:YES
forKey:kSuppressAnnoyingBellOffer];
break;

case 3: // Silence automatically
[[NSUserDefaults standardUserDefaults] setBool:YES
forKey:kSilenceAnnoyingBellAutomatically];
break;
}
}];
} else {
// Neither audible nor visible.
announcement =
[iTermAnnouncementViewController announcementWithTitle:@"The bell is ringing a lot. Want to suppress all output until things calm down?"
style:kiTermAnnouncementViewStyleQuestion
withActions:@[ @"Suppress All Output",
@"Don't Offer Again" ]
completion:^(int selection) {
// Release the moving average so the count will restart after the announcement goes away.
[_bellRate release];
_bellRate = nil;
switch (selection) {
case -2: // Dismiss programmatically
break;

case -1: // No
_annoyingBellOfferDeclinedAt = [NSDate timeIntervalSinceReferenceDate];
break;

case 0: // Suppress all output
_suppressAllOutput = YES;
break;

case 2: // Never offer again
[[NSUserDefaults standardUserDefaults] setBool:YES
forKey:kSuppressAnnoyingBellOffer];
break;
}
}];
}

// Set the auto-dismiss timeout.
announcement.timeout = 10;
[self queueAnnouncement:announcement identifier:identifier];
Expand Down
4 changes: 3 additions & 1 deletion sources/VT100Screen.m
Original file line number Diff line number Diff line change
Expand Up @@ -1115,7 +1115,9 @@ - (void)cursorToX:(int)x
}

- (void)activateBell {
if ([delegate_ screenShouldIgnoreBell]) return;
if ([delegate_ screenShouldIgnoreBellWhichIsAudible:audibleBell_ visible:flashBell_]) {
return;
}
if (audibleBell_) {
// Some bells or systems block on NSBeep so it's important to rate-limit it to prevent
// bells from blocking the terminal indefinitely. The small delay we insert between
Expand Down
2 changes: 1 addition & 1 deletion sources/VT100ScreenDelegate.h
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,7 @@
- (BOOL)screenShouldPostTerminalGeneratedAlert;

// Should this bell be ignored?
- (BOOL)screenShouldIgnoreBell;
- (BOOL)screenShouldIgnoreBellWhichIsAudible:(BOOL)audible visible:(BOOL)visible;

// PTYTextView deselect
- (void)screenRemoveSelection;
Expand Down

0 comments on commit 816be04

Please sign in to comment.