forked from gnachman/iTerm2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
HighlightTrigger.m
151 lines (129 loc) · 4.22 KB
/
HighlightTrigger.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
//
// HighlightTrigger.m
// iTerm2
//
// Created by George Nachman on 9/23/11.
//
#import "HighlightTrigger.h"
#import "PTYSession.h"
#import "PTYTab.h"
#import "PseudoTerminal.h"
#import "VT100Screen.h"
// Preserve these values - they are the tags and are saved in preferences.
enum {
kYellowOnBlackHighlight,
kBlackOnYellowHighlight,
kWhiteOnRedHighlight,
kRedOnWhiteHighlight,
kBlackOnOrangeHighlight,
kOrangeOnBlackHighlight,
kBlackOnPurpleHighlight,
kPurpleOnBlackHighlight,
};
@implementation HighlightTrigger
- (NSString *)title
{
return @"Highlight Text…";
}
- (NSString *)paramPlaceholder
{
return @"";
}
- (BOOL)takesParameter
{
return YES;
}
- (BOOL)paramIsPopupButton
{
return YES;
}
- (NSDictionary *)menuItemsForPoupupButton
{
return [NSDictionary dictionaryWithObjectsAndKeys:
@"Yellow on Black", [NSNumber numberWithInt:(int)kYellowOnBlackHighlight],
@"Black on Yellow", [NSNumber numberWithInt:(int)kBlackOnYellowHighlight],
@"White on Red", [NSNumber numberWithInt:(int)kWhiteOnRedHighlight],
@"Red on White", [NSNumber numberWithInt:(int)kRedOnWhiteHighlight],
@"Black on Orange", [NSNumber numberWithInt:(int)kBlackOnOrangeHighlight],
@"Orange on Black", [NSNumber numberWithInt:(int)kOrangeOnBlackHighlight],
@"Purple on Black", [NSNumber numberWithInt:(int)kPurpleOnBlackHighlight],
@"Black on Purple", [NSNumber numberWithInt:(int)kBlackOnPurpleHighlight],
nil];
}
- (NSArray *)tagsSortedByValue
{
return [[self menuItemsForPoupupButton] keysSortedByValueUsingSelector:@selector(localizedCaseInsensitiveCompare:)];
}
- (int)indexOfTag:(int)theTag
{
int i = 0;
for (NSNumber *n in [self tagsSortedByValue]) {
if ([n intValue] == theTag) {
return i;
}
i++;
}
return -1;
}
- (int)tagAtIndex:(int)theIndex
{
return [[[self tagsSortedByValue] objectAtIndex:theIndex] intValue];
}
- (int)colorCodeForColor:(NSColor *)theColor
{
theColor = [theColor colorUsingColorSpaceName:NSCalibratedRGBColorSpace];
int r = 5 * [theColor redComponent];
int g = 5 * [theColor greenComponent];
int b = 5 * [theColor blueComponent];
return 16 + b + g*6 + r*36;
}
- (screen_char_t)prototypeChar
{
screen_char_t sct;
sct.alternateBackgroundSemantics = NO;
sct.alternateForegroundSemantics = NO;
sct.bold = NO;
sct.blink = NO;
sct.underline = NO;
switch ([self.param intValue]) {
case kYellowOnBlackHighlight:
sct.foregroundColor = [self colorCodeForColor:[NSColor yellowColor]];
sct.backgroundColor = [self colorCodeForColor:[NSColor blackColor]];
break;
case kBlackOnYellowHighlight:
sct.foregroundColor = [self colorCodeForColor:[NSColor blackColor]];
sct.backgroundColor = [self colorCodeForColor:[NSColor yellowColor]];
break;
case kWhiteOnRedHighlight:
sct.foregroundColor = [self colorCodeForColor:[NSColor whiteColor]];
sct.backgroundColor = [self colorCodeForColor:[NSColor redColor]];
break;
case kRedOnWhiteHighlight:
sct.foregroundColor = [self colorCodeForColor:[NSColor redColor]];
sct.backgroundColor = [self colorCodeForColor:[NSColor whiteColor]];
break;
case kBlackOnOrangeHighlight:
sct.foregroundColor = [self colorCodeForColor:[NSColor blackColor]];
sct.backgroundColor = [self colorCodeForColor:[NSColor orangeColor]];
break;
case kOrangeOnBlackHighlight:
sct.foregroundColor = [self colorCodeForColor:[NSColor orangeColor]];
sct.backgroundColor = [self colorCodeForColor:[NSColor blackColor]];
break;
case kBlackOnPurpleHighlight:
sct.foregroundColor = [self colorCodeForColor:[NSColor blackColor]];
sct.backgroundColor = [self colorCodeForColor:[NSColor purpleColor]];
break;
case kPurpleOnBlackHighlight:
sct.foregroundColor = [self colorCodeForColor:[NSColor purpleColor]];
sct.backgroundColor = [self colorCodeForColor:[NSColor blackColor]];
break;
}
return sct;
}
- (void)performActionWithValues:(NSArray *)values inSession:(PTYSession *)aSession
{
[[aSession SCREEN] highlightTextMatchingRegex:self.regex
prototypeChar:[self prototypeChar]];
}
@end