Skip to content

Commit

Permalink
Add 'stop processing triggers' trigger
Browse files Browse the repository at this point in the history
  • Loading branch information
gnachman committed May 15, 2015
1 parent 03bd5f6 commit 6e6e52d
Show file tree
Hide file tree
Showing 18 changed files with 105 additions and 38 deletions.
14 changes: 14 additions & 0 deletions iTerm2.xcodeproj/project.pbxproj
Expand Up @@ -131,6 +131,11 @@
1D468BC21B056CD600226083 /* iTermProfileSearchToken.m in Sources */ = {isa = PBXBuildFile; fileRef = 1D468BBF1B056CD600226083 /* iTermProfileSearchToken.m */; };
1D468BC31B056CD600226083 /* iTermProfileSearchToken.m in Sources */ = {isa = PBXBuildFile; fileRef = 1D468BBF1B056CD600226083 /* iTermProfileSearchToken.m */; };
1D468BC41B056CD600226083 /* iTermProfileSearchToken.m in Sources */ = {isa = PBXBuildFile; fileRef = 1D468BBF1B056CD600226083 /* iTermProfileSearchToken.m */; };
1D468F041B06A79000226083 /* StopTrigger.h in Headers */ = {isa = PBXBuildFile; fileRef = 1D468F021B06A79000226083 /* StopTrigger.h */; };
1D468F051B06A79000226083 /* StopTrigger.h in Headers */ = {isa = PBXBuildFile; fileRef = 1D468F021B06A79000226083 /* StopTrigger.h */; };
1D468F061B06A79000226083 /* StopTrigger.m in Sources */ = {isa = PBXBuildFile; fileRef = 1D468F031B06A79000226083 /* StopTrigger.m */; };
1D468F071B06A79000226083 /* StopTrigger.m in Sources */ = {isa = PBXBuildFile; fileRef = 1D468F031B06A79000226083 /* StopTrigger.m */; };
1D468F081B06A79000226083 /* StopTrigger.m in Sources */ = {isa = PBXBuildFile; fileRef = 1D468F031B06A79000226083 /* StopTrigger.m */; };
1D48B284165F362B000046EE /* TabClose_Front_Rollover@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 1D48B27E165F362B000046EE /* TabClose_Front_Rollover@2x.png */; };
1D48B285165F362B000046EE /* TabClose_Front_Pressed@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 1D48B27F165F362B000046EE /* TabClose_Front_Pressed@2x.png */; };
1D48B286165F362B000046EE /* TabClose_Front@2x.png in Resources */ = {isa = PBXBuildFile; fileRef = 1D48B280165F362B000046EE /* TabClose_Front@2x.png */; };
Expand Down Expand Up @@ -2178,6 +2183,8 @@
1D468BB81B0543E300226083 /* iTermKeyboardNavigatableTableView.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = iTermKeyboardNavigatableTableView.m; sourceTree = "<group>"; };
1D468BBE1B056CD600226083 /* iTermProfileSearchToken.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = iTermProfileSearchToken.h; sourceTree = "<group>"; };
1D468BBF1B056CD600226083 /* iTermProfileSearchToken.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = iTermProfileSearchToken.m; sourceTree = "<group>"; };
1D468F021B06A79000226083 /* StopTrigger.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = StopTrigger.h; sourceTree = "<group>"; };
1D468F031B06A79000226083 /* StopTrigger.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = StopTrigger.m; sourceTree = "<group>"; };
1D48B27E165F362B000046EE /* TabClose_Front_Rollover@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "TabClose_Front_Rollover@2x.png"; sourceTree = "<group>"; };
1D48B27F165F362B000046EE /* TabClose_Front_Pressed@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "TabClose_Front_Pressed@2x.png"; sourceTree = "<group>"; };
1D48B280165F362B000046EE /* TabClose_Front@2x.png */ = {isa = PBXFileReference; lastKnownFileType = image.png; path = "TabClose_Front@2x.png"; sourceTree = "<group>"; };
Expand Down Expand Up @@ -3775,6 +3782,8 @@
1D24C283142EF334006B246F /* SendTextTrigger.m */,
1D891E42190724DB0053C4BB /* MarkTrigger.m */,
1DABA03219253FEA00A228D8 /* PasswordTrigger.m */,
1D468F021B06A79000226083 /* StopTrigger.h */,
1D468F031B06A79000226083 /* StopTrigger.m */,
);
name = Triggers;
sourceTree = "<group>";
Expand Down Expand Up @@ -4505,6 +4514,7 @@
A6E77F821A23F484009B1CB6 /* iTermFindOnPageHelper.h in Headers */,
A6E525DE1A9C5730007B898E /* VT100StateMachine.h in Headers */,
1D6ED8C619AEA20D005A7799 /* UKNibOwner.h in Headers */,
1D468F051B06A79000226083 /* StopTrigger.h in Headers */,
1D6ED8C719AEA20D005A7799 /* VT100GridTest.h in Headers */,
1D6ED8C819AEA20D005A7799 /* CommandHistory.h in Headers */,
1D6ED8C919AEA20D005A7799 /* UKSystemInfo.h in Headers */,
Expand Down Expand Up @@ -4825,6 +4835,7 @@
1DF8006F18F34CAB00722B35 /* NSPopUpButton+iTerm.h in Headers */,
A69B4585196F8EA100F5444D /* iTermOpenQuicklyWindowController.h in Headers */,
A6C7DE52199F3087001E5C75 /* PTYWindow+Scripting.h in Headers */,
1D468F041B06A79000226083 /* StopTrigger.h in Headers */,
A66A1FA81A3A207900F4A3A7 /* iTermWindowShortcutLabelTitlebarAccessoryViewController.h in Headers */,
1DABA03319253FEA00A228D8 /* PasswordTrigger.h in Headers */,
A6E7138E18F26A91008D94DD /* AppearancePreferencesViewController.h in Headers */,
Expand Down Expand Up @@ -5915,6 +5926,7 @@
1D6EDAD319AEA20D005A7799 /* BackgroundThread.m in Sources */,
1D6EDAD419AEA20D005A7799 /* iTermFontPanel.m in Sources */,
1D6EDAD519AEA20D005A7799 /* PTYNoteView.m in Sources */,
1D468F081B06A79000226083 /* StopTrigger.m in Sources */,
1D6EDAD619AEA20D005A7799 /* PTYWindow+Scripting.m in Sources */,
1D6EDAD719AEA20D005A7799 /* CharacterRun.m in Sources */,
1D6EDAD819AEA20D005A7799 /* ProfilesTextPreferencesViewController.m in Sources */,
Expand Down Expand Up @@ -6201,6 +6213,7 @@
1D9A5550180FA82E00B42CE9 /* TmuxWindowsTable.m in Sources */,
1DD39B1E180B8415004E56D5 /* LineBuffer.m in Sources */,
1D9A55AF180FA8B700B42CE9 /* PSMTabDragAssistant.m in Sources */,
1D468F071B06A79000226083 /* StopTrigger.m in Sources */,
1DF8007118F34CAB00722B35 /* NSPopUpButton+iTerm.m in Sources */,
1D9A559F180FA87000B42CE9 /* SplitPanel.m in Sources */,
1D9A5572180FA85D00B42CE9 /* HighlightTrigger.m in Sources */,
Expand Down Expand Up @@ -6541,6 +6554,7 @@
1DA26AC115007507004B5792 /* BackgroundThread.m in Sources */,
1D2F3B3E1516BA470044C337 /* iTermFontPanel.m in Sources */,
A63F409B183B3AA7003A6A6D /* PTYNoteView.m in Sources */,
1D468F061B06A79000226083 /* StopTrigger.m in Sources */,
A6C7DE4F199F302C001E5C75 /* PTYWindow+Scripting.m in Sources */,
1D48B37A167E809D000046EE /* CharacterRun.m in Sources */,
A6A2697F18FE2BDE00437DA9 /* ProfilesTextPreferencesViewController.m in Sources */,
Expand Down
3 changes: 1 addition & 2 deletions sources/AlertTrigger.m
Expand Up @@ -27,8 +27,7 @@ - (BOOL)takesParameter
return YES;
}

- (BOOL)performActionWithValues:(NSArray *)values inSession:(PTYSession *)aSession onString:(NSString *)string atAbsoluteLineNumber:(long long)absoluteLineNumber
{
- (BOOL)performActionWithValues:(NSArray *)values inSession:(PTYSession *)aSession onString:(NSString *)string atAbsoluteLineNumber:(long long)absoluteLineNumber stop:(BOOL *)stop {
if (disabled_) {
return YES;
}
Expand Down
3 changes: 1 addition & 2 deletions sources/BellTrigger.m
Expand Up @@ -21,8 +21,7 @@ - (BOOL)takesParameter
return NO;
}

- (BOOL)performActionWithValues:(NSArray *)values inSession:(PTYSession *)aSession onString:(NSString *)string atAbsoluteLineNumber:(long long)absoluteLineNumber
{
- (BOOL)performActionWithValues:(NSArray *)values inSession:(PTYSession *)aSession onString:(NSString *)string atAbsoluteLineNumber:(long long)absoluteLineNumber stop:(BOOL *)stop {
[aSession.screen activateBell];
return YES;
}
Expand Down
3 changes: 1 addition & 2 deletions sources/BounceTrigger.m
Expand Up @@ -80,8 +80,7 @@ - (NSRequestUserAttentionType)bounceType
}
}

- (BOOL)performActionWithValues:(NSArray *)values inSession:(PTYSession *)aSession onString:(NSString *)string atAbsoluteLineNumber:(long long)absoluteLineNumber
{
- (BOOL)performActionWithValues:(NSArray *)values inSession:(PTYSession *)aSession onString:(NSString *)string atAbsoluteLineNumber:(long long)absoluteLineNumber stop:(BOOL *)stop {
[NSApp requestUserAttention:[self bounceType]];
return YES;
}
Expand Down
2 changes: 1 addition & 1 deletion sources/CaptureTrigger.m
Expand Up @@ -67,7 +67,7 @@ - (void)showCaptureOutputToolInSession:(PTYSession *)aSession {
}
}

- (BOOL)performActionWithValues:(NSArray *)values inSession:(PTYSession *)aSession onString:(NSString *)string atAbsoluteLineNumber:(long long)absoluteLineNumber {
- (BOOL)performActionWithValues:(NSArray *)values inSession:(PTYSession *)aSession onString:(NSString *)string atAbsoluteLineNumber:(long long)absoluteLineNumber stop:(BOOL *)stop {
if (!aSession.screen.shellIntegrationInstalled) {
if (![[NSUserDefaults standardUserDefaults] boolForKey:kSuppressCaptureOutputRequiresShellIntegrationWarning]) {
[self showShellIntegrationRequiredAnnouncementInSession:aSession];
Expand Down
6 changes: 2 additions & 4 deletions sources/CoprocessTrigger.m
Expand Up @@ -31,8 +31,7 @@ - (void)executeCommand:(NSString *)command inSession:(PTYSession *)aSession
[aSession launchCoprocessWithCommand:command];
}

- (BOOL)performActionWithValues:(NSArray *)values inSession:(PTYSession *)aSession onString:(NSString *)string atAbsoluteLineNumber:(long long)absoluteLineNumber
{
- (BOOL)performActionWithValues:(NSArray *)values inSession:(PTYSession *)aSession onString:(NSString *)string atAbsoluteLineNumber:(long long)absoluteLineNumber stop:(BOOL *)stop {
if (![aSession hasCoprocess]) {
NSString *command = [self paramWithBackreferencesReplacedWithValues:values];
[self executeCommand:command inSession:aSession];
Expand Down Expand Up @@ -64,8 +63,7 @@ - (void)executeCommand:(NSString *)command inSession:(PTYSession *)aSession
[aSession launchSilentCoprocessWithCommand:command];
}

- (BOOL)performActionWithValues:(NSArray *)values inSession:(PTYSession *)aSession onString:(NSString *)string atAbsoluteLineNumber:(long long)absoluteLineNumber
{
- (BOOL)performActionWithValues:(NSArray *)values inSession:(PTYSession *)aSession onString:(NSString *)string atAbsoluteLineNumber:(long long)absoluteLineNumber stop:(BOOL *)stop {
if (![aSession hasCoprocess]) {
NSString *command = [self paramWithBackreferencesReplacedWithValues:values];
[self executeCommand:command inSession:aSession];
Expand Down
3 changes: 1 addition & 2 deletions sources/GrowlTrigger.m
Expand Up @@ -27,8 +27,7 @@ - (NSString *)paramPlaceholder
return @"Enter Message";
}

- (BOOL)performActionWithValues:(NSArray *)values inSession:(PTYSession *)aSession onString:(NSString *)string atAbsoluteLineNumber:(long long)absoluteLineNumber
{
- (BOOL)performActionWithValues:(NSArray *)values inSession:(PTYSession *)aSession onString:(NSString *)string atAbsoluteLineNumber:(long long)absoluteLineNumber stop:(BOOL *)stop {
iTermGrowlDelegate *gd = [iTermGrowlDelegate sharedInstance];
[gd growlNotify:[self paramWithBackreferencesReplacedWithValues:values]
withDescription:[NSString stringWithFormat:@"A trigger fired in session \"%@\" in tab #%d.",
Expand Down
3 changes: 1 addition & 2 deletions sources/HighlightTrigger.m
Expand Up @@ -337,8 +337,7 @@ - (NSDictionary *)colors
return nil;
}

- (BOOL)performActionWithValues:(NSArray *)values inSession:(PTYSession *)aSession onString:(NSString *)string atAbsoluteLineNumber:(long long)absoluteLineNumber
{
- (BOOL)performActionWithValues:(NSArray *)values inSession:(PTYSession *)aSession onString:(NSString *)string atAbsoluteLineNumber:(long long)absoluteLineNumber stop:(BOOL *)stop {
[[aSession screen] highlightTextMatchingRegex:self.regex
colors:[self colors]];
return YES;
Expand Down
2 changes: 1 addition & 1 deletion sources/MarkTrigger.m
Expand Up @@ -67,7 +67,7 @@ - (BOOL)shouldStopScrolling {
return [self.param intValue] == kMarkTriggerParamTagStopScrolling;
}

- (BOOL)performActionWithValues:(NSArray *)values inSession:(PTYSession *)aSession onString:(NSString *)string atAbsoluteLineNumber:(long long)absoluteLineNumber {
- (BOOL)performActionWithValues:(NSArray *)values inSession:(PTYSession *)aSession onString:(NSString *)string atAbsoluteLineNumber:(long long)absoluteLineNumber stop:(BOOL *)stop {
[aSession.screen terminalSaveScrollPositionWithArgument:@"saveCursorLine"];
if ([self shouldStopScrolling]) {
[(PTYScroller *)[aSession.scrollview verticalScroller] setUserScroll:YES];
Expand Down
22 changes: 14 additions & 8 deletions sources/PTYSession.m
Expand Up @@ -1560,10 +1560,13 @@ - (void)finishedHandlingNewOutputOfLength:(int)length {
- (void)checkTriggers
{
for (Trigger *trigger in _triggers) {
[trigger tryString:_triggerLine
inSession:self
partialLine:NO
lineNumber:[_screen absoluteLineNumberOfCursor]];
BOOL stop = [trigger tryString:_triggerLine
inSession:self
partialLine:NO
lineNumber:[_screen absoluteLineNumberOfCursor]];
if (stop) {
break;
}
}
}

Expand All @@ -1574,10 +1577,13 @@ - (void)checkPartialLineTriggers {
}
_lastPartialLineTriggerCheck = now;
for (Trigger *trigger in _triggers) {
[trigger tryString:_triggerLine
inSession:self
partialLine:YES
lineNumber:[_screen absoluteLineNumberOfCursor]];
BOOL stop = [trigger tryString:_triggerLine
inSession:self
partialLine:YES
lineNumber:[_screen absoluteLineNumberOfCursor]];
if (stop) {
break;
}
}
}

Expand Down
2 changes: 1 addition & 1 deletion sources/PasswordTrigger.m
Expand Up @@ -82,7 +82,7 @@ - (NSDictionary *)menuItemsForPoupupButton {
return result;
}

- (BOOL)performActionWithValues:(NSArray *)values inSession:(PTYSession *)aSession onString:(NSString *)string atAbsoluteLineNumber:(long long)absoluteLineNumber {
- (BOOL)performActionWithValues:(NSArray *)values inSession:(PTYSession *)aSession onString:(NSString *)string atAbsoluteLineNumber:(long long)absoluteLineNumber stop:(BOOL *)stop {
iTermApplicationDelegate *delegate =
(iTermApplicationDelegate *)[[NSApplication sharedApplication] delegate];
[delegate openPasswordManagerToAccountName:[self paramWithBackreferencesReplacedWithValues:values]];
Expand Down
3 changes: 1 addition & 2 deletions sources/ScriptTrigger.m
Expand Up @@ -29,8 +29,7 @@ - (NSString *)paramPlaceholder
}


- (BOOL)performActionWithValues:(NSArray *)values inSession:(PTYSession *)aSession onString:(NSString *)string atAbsoluteLineNumber:(long long)absoluteLineNumber
{
- (BOOL)performActionWithValues:(NSArray *)values inSession:(PTYSession *)aSession onString:(NSString *)string atAbsoluteLineNumber:(long long)absoluteLineNumber stop:(BOOL *)stop {
NSString *command = [self paramWithBackreferencesReplacedWithValues:values];
[NSThread detachNewThreadSelector:@selector(runCommand:)
toTarget:[self class]
Expand Down
3 changes: 1 addition & 2 deletions sources/SendTextTrigger.m
Expand Up @@ -26,8 +26,7 @@ - (NSString *)paramPlaceholder
}


- (BOOL)performActionWithValues:(NSArray *)values inSession:(PTYSession *)aSession onString:(NSString *)string atAbsoluteLineNumber:(long long)absoluteLineNumber
{
- (BOOL)performActionWithValues:(NSArray *)values inSession:(PTYSession *)aSession onString:(NSString *)string atAbsoluteLineNumber:(long long)absoluteLineNumber stop:(BOOL *)stop {
NSString *message = [self paramWithBackreferencesReplacedWithValues:values];
[aSession writeTask:[message dataUsingEncoding:NSUTF8StringEncoding]];
return YES;
Expand Down
13 changes: 13 additions & 0 deletions sources/StopTrigger.h
@@ -0,0 +1,13 @@
//
// StopTrigger.h
// iTerm2
//
// Created by George Nachman on 5/15/15.
//
//

#import "Trigger.h"

@interface StopTrigger : Trigger

@end
30 changes: 30 additions & 0 deletions sources/StopTrigger.m
@@ -0,0 +1,30 @@
//
// StopTrigger.m
// iTerm2
//
// Created by George Nachman on 5/15/15.
//
//

#import "StopTrigger.h"

@implementation StopTrigger

+ (NSString *)title {
return @"Stop Processing Triggers";
}

- (BOOL)takesParameter {
return NO;
}

- (BOOL)performActionWithValues:(NSArray *)values
inSession:(PTYSession *)aSession
onString:(NSString *)string
atAbsoluteLineNumber:(long long)absoluteLineNumber
stop:(BOOL *)stop {
*stop = YES;
return NO;
}

@end
9 changes: 7 additions & 2 deletions sources/Trigger.h
Expand Up @@ -52,13 +52,18 @@ extern NSString * const kTriggerPartialLineKey;
- (NSArray *)objectsSortedByValueInDict:(NSDictionary *)dict;

- (NSString *)paramWithBackreferencesReplacedWithValues:(NSArray *)values;
- (void)tryString:(NSString *)s
// Returns YES if no more triggers should be processed.
- (BOOL)tryString:(NSString *)s
inSession:(PTYSession *)aSession
partialLine:(BOOL)partialLine
lineNumber:(long long)lineNumber;

// Subclasses must override this. Return YES if it can fire again on this line.
- (BOOL)performActionWithValues:(NSArray *)values inSession:(PTYSession *)aSession onString:(NSString *)string atAbsoluteLineNumber:(long long)absoluteLineNumber;
- (BOOL)performActionWithValues:(NSArray *)values
inSession:(PTYSession *)aSession
onString:(NSString *)string
atAbsoluteLineNumber:(long long)absoluteLineNumber
stop:(BOOL *)stop;

- (NSComparisonResult)compareTitle:(Trigger *)other;

Expand Down
18 changes: 12 additions & 6 deletions sources/Trigger.m
Expand Up @@ -94,13 +94,16 @@ - (void)dealloc {
[super dealloc];
}

- (BOOL)performActionWithValues:(NSArray *)values inSession:(PTYSession *)aSession onString:(NSString *)string atAbsoluteLineNumber:(long long)absoluteLineNumber
{
- (BOOL)performActionWithValues:(NSArray *)values
inSession:(PTYSession *)aSession
onString:(NSString *)string
atAbsoluteLineNumber:(long long)absoluteLineNumber
stop:(BOOL *)stop {
assert(false);
return NO;
}

- (void)tryString:(NSString *)s
- (BOOL)tryString:(NSString *)s
inSession:(PTYSession *)aSession
partialLine:(BOOL)partialLine
lineNumber:(long long)lineNumber {
Expand All @@ -109,13 +112,14 @@ - (void)tryString:(NSString *)s
if (!partialLine) {
_lastLineNumber = -1;
}
return;
return NO;
}
if (partialLine && !_partialLine) {
// This trigger doesn't support partial lines.
return;
return NO;
}
NSRange range = [s rangeOfRegex:regex_];
BOOL stop = NO;
if (range.location != NSNotFound) {
NSArray *captures = [s arrayOfCaptureComponentsMatchedByRegex:regex_];
if (captures.count) {
Expand All @@ -125,14 +129,16 @@ - (void)tryString:(NSString *)s
if (![self performActionWithValues:matches
inSession:aSession
onString:s
atAbsoluteLineNumber:lineNumber]) {
atAbsoluteLineNumber:lineNumber
stop:&stop]) {
break;
}
}
}
if (!partialLine) {
_lastLineNumber = -1;
}
return stop;
}

- (NSString *)paramWithBackreferencesReplacedWithValues:(NSArray *)values
Expand Down
4 changes: 3 additions & 1 deletion sources/TriggerController.m
Expand Up @@ -19,6 +19,7 @@
#import "Trigger.h"
#import "CoprocessTrigger.h"
#import "SendTextTrigger.h"
#import "StopTrigger.h"
#import "PasswordTrigger.h"
#import "FutureMethods.h"

Expand Down Expand Up @@ -61,7 +62,8 @@ - (NSArray *)triggerClasses {
[MuteCoprocessTrigger class],
[HighlightTrigger class],
[MarkTrigger class],
[PasswordTrigger class] ];
[PasswordTrigger class],
[StopTrigger class] ];

return [allClasses sortedArrayUsingComparator:^NSComparisonResult(id obj1, id obj2) {
return [[obj1 title] compare:[obj2 title]];
Expand Down

0 comments on commit 6e6e52d

Please sign in to comment.