Skip to content
Snippets Groups Projects
Commit 7c1f0d6b authored by George Nachman's avatar George Nachman
Browse files

Add an experimental feature to draw an outline around underline and vertical...

Add an experimental feature to draw an outline around underline and vertical bar cursors to improve distinction from text. Suggested in issue 4614.
parent d97e0a7b
No related branches found
No related tags found
No related merge requests found
Loading
Loading
@@ -179,5 +179,6 @@
+ (BOOL)excludeBackgroundColorsFromCopiedStyle;
+ (BOOL)useGCDUpdateTimer;
+ (BOOL)fullHeightCursor;
+ (BOOL)drawOutlineAroundCursor;
 
@end
Loading
Loading
@@ -265,5 +265,6 @@ DEFINE_BOOL(trackingRunloopForLiveResize, YES, @"Experimental Features: Use a tr
 
DEFINE_BOOL(enableAPIServer, NO, @"Experimental Features: Enable websocket API server.\nYou must restart iTerm2 for this change to take effect.");
DEFINE_BOOL(useGCDUpdateTimer, NO, @"Experimental Features: Use GCD-based update timer instead of NSTimer.\nThis should cause more regular screen updates. Restart iTerm2 after changing this setting.");
DEFINE_BOOL(drawOutlineAroundCursor, NO, @"Experimental Features: Draw outline around underline and vertical bar cursors using background color.");
 
@end
Loading
Loading
@@ -48,7 +48,7 @@ typedef struct {
smart:(BOOL)smart
focused:(BOOL)focused
coord:(VT100GridCoord)coord
cellHeight:(CGFloat)cellHeight;
outline:(BOOL)outline;
 
 
@end
Loading
Loading
@@ -47,7 +47,18 @@
smart:(BOOL)smart
focused:(BOOL)focused
coord:(VT100GridCoord)coord
cellHeight:(CGFloat)cellHeight {
outline:(BOOL)outline {
}
- (void)drawOutlineOfRect:(NSRect)cursorRect withColor:(NSColor *)color {
[[color colorWithAlphaComponent:0.75] set];
NSRect rect = cursorRect;
CGFloat frameWidth = 0.5;
rect.origin.x -= frameWidth;
rect.origin.y -= frameWidth;
rect.size.width += frameWidth * 2;
rect.size.height += frameWidth * 2;
NSFrameRectWithWidthUsingOperation(rect, 0.5, NSCompositeSourceOver);
}
 
@end
Loading
Loading
@@ -62,12 +73,18 @@
smart:(BOOL)smart
focused:(BOOL)focused
coord:(VT100GridCoord)coord
cellHeight:(CGFloat)cellHeight {
[backgroundColor set];
NSRectFill(NSMakeRect(rect.origin.x,
rect.origin.y + rect.size.height - 2,
ceil(rect.size.width),
2));
outline:(BOOL)outline {
const CGFloat height = 2;
NSRect cursorRect = NSMakeRect(rect.origin.x,
rect.origin.y + rect.size.height - height,
ceil(rect.size.width),
height);
if (outline) {
[self drawOutlineOfRect:cursorRect withColor:backgroundColor];
} else {
[backgroundColor set];
NSRectFill(cursorRect);
}
}
 
@end
Loading
Loading
@@ -82,9 +99,14 @@
smart:(BOOL)smart
focused:(BOOL)focused
coord:(VT100GridCoord)coord
cellHeight:(CGFloat)cellHeight {
[backgroundColor set];
NSRectFill(NSMakeRect(rect.origin.x, rect.origin.y, 1, rect.size.height));
outline:(BOOL)outline {
NSRect cursorRect = NSMakeRect(rect.origin.x, rect.origin.y, 1, rect.size.height);
if (outline) {
[self drawOutlineOfRect:cursorRect withColor:backgroundColor];
} else {
[backgroundColor set];
NSRectFill(cursorRect);
}
}
 
@end
Loading
Loading
@@ -99,7 +121,9 @@
smart:(BOOL)smart
focused:(BOOL)focused
coord:(VT100GridCoord)coord
cellHeight:(CGFloat)cellHeight {
outline:(BOOL)outline {
assert(!outline);
// Draw the colored box/frame
if (smart) {
iTermCursorNeighbors neighbors = [self.delegate cursorNeighbors];
Loading
Loading
Loading
Loading
@@ -371,7 +371,7 @@ typedef struct iTermTextColorContext {
 
const BOOL drawCursorBeforeText = (_cursorType == CURSOR_UNDERLINE || _cursorType == CURSOR_VERTICAL);
if (drawCursorBeforeText) {
[self drawCursor];
[self drawCursor:NO];
}
 
// Now iterate over the lines and paint the characters.
Loading
Loading
@@ -410,8 +410,12 @@ typedef struct iTermTextColorContext {
cursorHeight:_cellSizeWithoutSpacing.height
ctx:ctx];
_blinkingFound |= self.cursorBlinking;
if (!drawCursorBeforeText) {
[self drawCursor];
if (drawCursorBeforeText) {
if ([iTermAdvancedSettingsModel drawOutlineAroundCursor]) {
[self drawCursor:YES];
}
} else {
[self drawCursor:NO];
}
}
 
Loading
Loading
@@ -2224,8 +2228,21 @@ static BOOL iTermTextDrawingHelperIsCharacterDrawable(screen_char_t *c,
}
}
 
- (void)drawCursor {
DLog(@"drawCursor");
- (NSRect)cursorFrameIncludingDoubleWidthAdjustment {
screen_char_t *theLine = [self.delegate drawingHelperLineAtScreenIndex:_cursorCoord.y];
BOOL isDoubleWidth;
[self charForCursorAtColumn:_cursorCoord.x
inLine:theLine
doubleWidth:&isDoubleWidth];
NSRect rect = [self cursorFrame];
if (isDoubleWidth) {
rect.size.width *= 2;
}
return rect;
}
- (void)drawCursor:(BOOL)outline {
DLog(@"drawCursor:%@", @(outline));
 
// Update the last time the cursor moved.
NSTimeInterval now = [NSDate timeIntervalSinceReferenceDate];
Loading
Loading
@@ -2246,7 +2263,11 @@ static BOOL iTermTextDrawingHelperIsCharacterDrawable(screen_char_t *c,
 
// Get the color of the cursor.
NSColor *cursorColor;
cursorColor = [self backgroundColorForCursor];
if (outline) {
cursorColor = [_colorMap colorForKey:kColorMapBackground];
} else {
cursorColor = [self backgroundColorForCursor];
}
NSRect rect = [self cursorFrame];
if (isDoubleWidth) {
rect.size.width *= 2;
Loading
Loading
@@ -2274,7 +2295,7 @@ static BOOL iTermTextDrawingHelperIsCharacterDrawable(screen_char_t *c,
smart:_useSmartCursorColor
focused:((_isInKeyWindow && _textViewIsActiveSession) || _shouldDrawFilledInCursor)
coord:_cursorCoord
cellHeight:_cellSize.height];
outline:outline];
if (_showSearchingCursor) {
NSImage *image = [NSImage imageNamed:@"SearchCursor"];
if (image) {
Loading
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment