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

Add a new proprietary API to get cell size in points. OSC 1337 ;...

Add a new proprietary API to get cell size in points. OSC 1337 ; ReportCellSize ST will respond with OSC 1337 ; ReportCellSize= H ; W ST where H and W are floating point values giving the height and width of a cell, respectively.
parent 76a257c7
No related branches found
No related tags found
No related merge requests found
Loading
Loading
@@ -214,6 +214,11 @@ int decode_utf8_char(const unsigned char * restrict datap,
// Returns modified attributes for drawing self fitting size within one point.
- (NSDictionary *)attributesUsingFont:(NSFont *)font fittingSize:(NSSize)size attributes:(NSDictionary *)attributes;
 
// Removes trailing zeros from a floating point value, leaving at most one.
// 1.0000 -> 1.0
// 1.0010 -> 1.001
- (NSString *)stringByCompactingFloatingPointString;
@end
 
@interface NSMutableString (iTerm)
Loading
Loading
Loading
Loading
@@ -1495,6 +1495,18 @@ static TECObjectRef CreateTECConverterForUTF8Variants(TextEncodingVariant varian
return attributes;
}
 
- (NSString *)stringByCompactingFloatingPointString {
if ([self rangeOfString:@"."].location == NSNotFound) {
// Bogus input. Don't even try.
return self;
}
NSString *compact = [self stringByTrimmingTrailingCharactersFromCharacterSet:[NSCharacterSet characterSetWithCharactersInString:@"0"]];
if ([compact hasSuffix:@"."]) {
compact = [compact stringByAppendingString:@"0"];
}
return compact;
}
@end
 
@implementation NSMutableString (iTerm)
Loading
Loading
Loading
Loading
@@ -3750,6 +3750,10 @@ static NSString *const kInlineFileBase64String = @"base64 string"; // NSMutable
return result;
}
 
- (NSSize)terminalCellSizeInPoints {
return [delegate_ screenCellSize];
}
#pragma mark - Private
 
- (VT100GridCoordRange)commandRange {
Loading
Loading
Loading
Loading
@@ -3,6 +3,7 @@
#import "NSColor+iTerm.h"
#import "NSDictionary+iTerm.h"
#import "NSObject+iTerm.h"
#import "NSStringITerm.h"
#import "VT100DCSParser.h"
#import "VT100Parser.h"
#import <apr-1/apr_base64.h> // for xterm's base64 decoding (paste64)
Loading
Loading
@@ -2090,6 +2091,15 @@ static const int kMaxScreenRows = 4096;
[delegate_ terminalSetBadgeFormat:value];
} else if ([key isEqualToString:@"SetUserVar"]) {
[delegate_ terminalSetUserVar:value];
} else if ([key isEqualToString:@"ReportCellSize"]) {
if ([delegate_ terminalShouldSendReport]) {
NSSize size = [delegate_ terminalCellSizeInPoints];
NSString *width = [[NSString stringWithFormat:@"%0.2f", size.width] stringByCompactingFloatingPointString];
NSString *height = [[NSString stringWithFormat:@"%0.2f", size.height] stringByCompactingFloatingPointString];
NSString *s = [NSString stringWithFormat:@"\033]1337;ReportCellSize=%@;%@\033\\",
height, width];
[delegate_ terminalSendReport:[s dataUsingEncoding:NSUTF8StringEncoding]];
}
}
}
 
Loading
Loading
Loading
Loading
@@ -232,6 +232,9 @@ typedef NS_ENUM(NSInteger, VT100TerminalUnits) {
- (int)terminalWidth;
- (int)terminalHeight;
 
// Returns the size of a single cell. May contain non-integer values.
- (NSSize)terminalCellSizeInPoints;
// Called when the mouse reporting mode changes.
- (void)terminalMouseModeDidChangeTo:(MouseMode)mouseMode;
 
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