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

Support for ANSI escape codes. #12

Open
wants to merge 5 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
52 changes: 52 additions & 0 deletions TestXcodeColors/AppDelegate.m
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#import "AppDelegate.h"
#import "XcodeColors.h"

// How to apply color formatting to your log statements:
//
Expand Down Expand Up @@ -53,6 +54,57 @@ - (void)applicationDidFinishLaunching:(NSNotification *)aNotification
NSLog(XCODE_COLORS_ESCAPE @"fg209,57,168;" @"You can supply your own RGB values!" XCODE_COLORS_RESET);

LogBlue(@"Blue text via macro");

// [self testANSIColors];
}

- (void)testANSIColors {

NSLog(@"\n=======Testing ANSI colors=======");

//These correspond to the TRShellColor values
NSArray *colorNames = @[@"Black", @"Red", @"Green", @"Yellow", @"Blue", @"Magenta", @"Cyan", @"White"];

TRShellAttribute baseAttributes[] = {TRShellAttributeForegroundRegular, TRShellAttributeForegroundLight, TRShellAttributeBackgroundRegular, TRShellAttributeBackgroundLight};

TRShellColor colorCode;
for (NSInteger i = 0; i < 4; i++) {

TRShellAttribute baseAttribute = baseAttributes[i];

// Test without reset
colorCode = TRShellColorBlack;
for (NSString *colorName in colorNames) {

NSLog(@"%@%lum%@", XCODE_COLORS_ESCAPE, baseAttribute + colorCode++, colorName);
}

NSLog(@"No Attribute");


//Test with reset
colorCode = TRShellColorBlack;
for (NSString *colorName in colorNames) {

NSLog(@"%@%lum%@%@", XCODE_COLORS_ESCAPE, baseAttribute + colorCode++, colorName, XCODE_COLORS_RESET);
}

NSLog(@"No Attribute");
}

// Test setting both background and foreground
colorCode = TRShellColorBlack;
NSInteger count = 0;

for (NSString *colorName in colorNames) {

TRShellColor bgColorCode = [colorNames count] - (1 + count++);
NSString *bgColorName = colorNames[bgColorCode];
NSLog(@"%@%lu;%lum%@-bg%@%@", XCODE_COLORS_ESCAPE, TRShellAttributeForegroundRegular + colorCode, TRShellAttributeBackgroundRegular + bgColorCode, colorName, bgColorName,XCODE_COLORS_RESET);
colorCode++;
}

NSLog(@"No Attribute");
}

- (BOOL)applicationShouldTerminateAfterLastWindowClosed:(NSApplication *)theApplication
Expand Down
23 changes: 12 additions & 11 deletions XcodeColors/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,6 @@
<string>ru.DeepIT.${PRODUCT_NAME}</string>
<key>CFBundleInfoDictionaryVersion</key>
<string>6.0</string>
<key>DVTPlugInCompatibilityUUIDs</key>
<array>
<string>63FC1C47-140D-42B0-BB4D-A10B2D225574</string>
<string>37B30044-3B14-46BA-ABAA-F01000C27B63</string>
<string>640F884E-CE55-4B40-87C0-8869546CAB7A</string>
<string>A2E4D43F-41F4-4FB9-BB94-7177011C9AED</string>
</array>
<key>CFBundleName</key>
<string>${PRODUCT_NAME}</string>
<key>CFBundlePackageType</key>
Expand All @@ -29,6 +22,14 @@
<string>????</string>
<key>CFBundleVersion</key>
<string>109</string>
<key>DVTPlugInCompatibilityUUIDs</key>
<array>
<string>63FC1C47-140D-42B0-BB4D-A10B2D225574</string>
<string>37B30044-3B14-46BA-ABAA-F01000C27B63</string>
<string>640F884E-CE55-4B40-87C0-8869546CAB7A</string>
<string>A2E4D43F-41F4-4FB9-BB94-7177011C9AED</string>
<string>AD68E85B-441B-4301-B564-A45E4919A6AD</string>
</array>
<key>LoadAtLaunch</key>
<true/>
<key>NSPrincipalClass</key>
Expand All @@ -44,13 +45,13 @@
<string>com.apple.dt.Xcode</string>
</dict>
</array>
<key>XCGCReady</key>
<true/>
<key>XCPluginHasUI</key>
<false/>
<key>XC4Compatible</key>
<true/>
<key>XC5Compatible</key>
<true/>
<key>XCGCReady</key>
<true/>
<key>XCPluginHasUI</key>
<false/>
</dict>
</plist>
75 changes: 75 additions & 0 deletions XcodeColors/XcodeColors.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,81 @@

#import <Cocoa/Cocoa.h>

typedef NS_OPTIONS(NSUInteger, TRShellColor) {

TRShellColorBlack = 0,
TRShellColorRed,
TRShellColorGreen,
TRShellColorYellow,
TRShellColorBlue,
TRShellColorMagenta,
TRShellColorCyan,
TRShellColorWhite
};

typedef NS_ENUM(NSInteger, TRShellAttribute) {

TRShellAttributeResetAll = 0,
/* TRShellAttributeBold = 1,
TRShellAttributeDim = 2,
TRShellAttributeUnderlined = 4,
TRShellAttributeBlink = 5,
TRShellAttributeInvert = 7,
TRShellAttributeHidden = 8,

TRShellAttributeResetBold = 21,
TRShellAttributeResetDim = 22,
TRShellAttributeResetUnderlined = 24,
TRShellAttributeResetBlink = 25,
TRShellAttributeResetReverse = 27,
TRShellAttributeResetHidden = 28,
*/

TRShellAttributeForegroundRegular = 30,
TRShellAttributeForegroundBlack = TRShellAttributeForegroundRegular + TRShellColorBlack,
TRShellAttributeForegroundRed = TRShellAttributeForegroundRegular + TRShellColorRed,
TRShellAttributeForegroundGreen = TRShellAttributeForegroundRegular + TRShellColorGreen,
TRShellAttributeForegroundYellow = TRShellAttributeForegroundRegular + TRShellColorYellow,
TRShellAttributeForegroundBlue = TRShellAttributeForegroundRegular + TRShellColorBlue,
TRShellAttributeForegroundMagenta = TRShellAttributeForegroundRegular + TRShellColorMagenta,
TRShellAttributeForegroundCyan = TRShellAttributeForegroundRegular + TRShellColorCyan,
TRShellAttributeForegroundLightGray = TRShellAttributeForegroundRegular + TRShellColorWhite,

TRShellAttributeForegroundDefault = 39,

TRShellAttributeForegroundLight = 90,
TRShellAttributeForegroundDarkGray = TRShellAttributeForegroundLight + TRShellColorBlack,
TRShellAttributeForegroundLightRed = TRShellAttributeForegroundLight + TRShellColorRed,
TRShellAttributeForegroundLightGreen = TRShellAttributeForegroundLight + TRShellColorGreen,
TRShellAttributeForegroundLightYellow = TRShellAttributeForegroundLight + TRShellColorYellow,
TRShellAttributeForegroundLightBlue = TRShellAttributeForegroundLight + TRShellColorBlue,
TRShellAttributeForegroundLightMagenta = TRShellAttributeForegroundLight + TRShellColorMagenta,
TRShellAttributeForegroundLightCyan = TRShellAttributeForegroundLight + TRShellColorCyan,
TRShellAttributeForegroundWhite = TRShellAttributeForegroundLight + TRShellColorWhite,

TRShellAttributeBackgroundRegular = 40,
TRShellAttributeBackgroundBlack = TRShellAttributeBackgroundRegular + TRShellColorBlack,
TRShellAttributeBackgroundRed = TRShellAttributeBackgroundRegular + TRShellColorRed,
TRShellAttributeBackgroundGreen = TRShellAttributeBackgroundRegular + TRShellColorGreen,
TRShellAttributeBackgroundYellow = TRShellAttributeBackgroundRegular + TRShellColorYellow,
TRShellAttributeBackgroundBlue = TRShellAttributeBackgroundRegular + TRShellColorBlue,
TRShellAttributeBackgroundMagenta = TRShellAttributeBackgroundRegular + TRShellColorMagenta,
TRShellAttributeBackgroundCyan = TRShellAttributeBackgroundRegular + TRShellColorCyan,
TRShellAttributeBackgroundLightGray = TRShellAttributeBackgroundRegular + TRShellColorWhite,

TRShellAttributeBackgroundDefault = 49,

TRShellAttributeBackgroundLight = 100,
TRShellAttributeBackgroundDarkGray = TRShellAttributeBackgroundLight + TRShellColorBlack,
TRShellAttributeBackgroundLightRed = TRShellAttributeBackgroundLight + TRShellColorRed,
TRShellAttributeBackgroundLightGreen = TRShellAttributeBackgroundLight + TRShellColorGreen,
TRShellAttributeBackgroundLightYellow = TRShellAttributeBackgroundLight + TRShellColorYellow,
TRShellAttributeBackgroundLightBlue = TRShellAttributeBackgroundLight + TRShellColorBlue,
TRShellAttributeBackgroundLightMagenta = TRShellAttributeBackgroundLight + TRShellColorMagenta,
TRShellAttributeBackgroundLightCyan = TRShellAttributeBackgroundLight + TRShellColorCyan,
TRShellAttributeBackgroundWhite = TRShellAttributeBackgroundLight + TRShellColorWhite,
};

@interface XcodeColors_NSTextStorage : NSTextStorage

- (void)fixAttributesInRange:(NSRange)aRange;
Expand Down
Loading