Skip to content
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

Add support for specifying the Growl alert title #153

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 25 additions & 2 deletions VT100Screen.m
Original file line number Diff line number Diff line change
Expand Up @@ -2349,10 +2349,33 @@ - (void)terminalPopCurrentTitleForWindow:(BOOL)isWindow {

- (BOOL)terminalPostGrowlNotification:(NSString *)message {
if (postGrowlNotifications_) {
NSString *description = [NSString stringWithFormat:@"Session %@ #%d: %@",
// If there's any newlines in the message string, treat the first line as
// the alert title and the remainder as the actual message. Ignore cases
// where there's really only a single line that begins and/or ends with newlines.
// Various things between the client and here can and will expand \n to \r\n, so
// use -getLineStart:end:contentsEnd:forRange: to reliably do what the user would
// expect here and not leave unintended dangling control characters for growl.
NSString *description = message;
NSString *title = nil;
NSUInteger endIndex, contentsIndex;
[message getLineStart:NULL
end:&endIndex
contentsEnd:&contentsIndex
forRange:NSMakeRange(0, 0)];
if (endIndex < [message length]-1 &&
contentsIndex > 0) {
title = [message substringToIndex:contentsIndex];
description = [message substringFromIndex:endIndex];
} else {
title = NSLocalizedStringFromTableInBundle(@"Alert",
@"iTerm",
[NSBundle bundleForClass:[self class]],
@"Growl Alerts");
}
description = [NSString stringWithFormat:@"Session %@ #%d: %@",
[delegate_ screenName],
[delegate_ screenNumber],
message];
description];
BOOL sent = [[iTermGrowlDelegate sharedInstance]
growlNotify:@"Alert"
withDescription:description
Expand Down
41 changes: 41 additions & 0 deletions tests/growl.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#!/bin/bash
#
# This file tests the growl OSC escapes handling. Newlines embedded in the
# argument indicate the first component should be used as a custom alert
# title, unless the title or message would be empty, in which case the
# argument is used as the message text as before. Other newlines are left
# as-is in the message text.

# Alert
# Session Shell #1: Line0
echo -en "\033]9;Line0\007"

# Alert
# Session Shell #1: Line0
echo -en "\033]9;Line0\n\007"

# Alert
# Session Shell #1:
# Line1
echo -en "\033]9;\nLine1\007"

# Alert
# Session Shell #1:
# Line1
# Line2
echo -en "\033]9;\nLine1\nLine2\007"

# Custom Title
# Session Shell #1: Line0
echo -en "\033]9;Custom Title\nLine0\007"

# Custom Title
# Session Shell #1: Line0
# Line1
echo -en "\033]9;Custom Title\nLine0\nLine1\007"

# Custom Title
# Session Shell #1:
# Line1
# Line2
echo -en "\033]9;Custom Title\n\nLine1\nLine2\007"