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

Improve support for OS X command line tools #194

Merged
merged 8 commits into from
Jan 14, 2014
Merged
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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -27,3 +27,5 @@ Icon?
.DS_Store
Xcode/PerUserLogLevels/PerUserLogLevels/LumberjackUser.h
Xcode/PerUserLogLevels/PerUserLogLevels/LumberjackUser.temp.h

Pods
3 changes: 3 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,6 @@ script:
- xctool -project Xcode/BenchmarkIPhone/BenchmarkIPhone.xcodeproj -scheme 'BenchmarkIPhone' -configuration Release -sdk iphonesimulator -arch i386 build
- xctool -project Xcode/Testing/TestXcodeColors/Desktop/TestXcodeColors.xcodeproj -scheme 'TestXcodeColors'
- xctool -project Xcode/UniversalApp/UniversalApp.xcodeproj -scheme 'UniversalApp' -configuration Release -sdk iphonesimulator -arch i386 build
- cd Xcode/CLI
- pod install
- xctool -workspace CLI.xcworkspace -scheme 'CLI'
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Made sure not to break other usages.

7 changes: 7 additions & 0 deletions CocoaLumberjack.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ Pod::Spec.new do |s|

s.public_header_files = 'Lumberjack/**/*.h'

s.default_subspec = 'Extensions'
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Other projects skip the new subspec.


s.subspec 'Core' do |ss|
ss.source_files = 'Lumberjack/*.{h,m}'
end
Expand All @@ -30,4 +32,9 @@ Pod::Spec.new do |s|
ss.source_files = 'Lumberjack/Extensions/*.{h,m}'
end

s.subspec 'CLI' do |ss|
ss.dependency 'CocoaLumberjack/Core'
ss.source_files = 'Lumberjack/CLI/*.{h,m}'
end
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

New subspec for OS X projects that don't use AppKit.


end
19 changes: 19 additions & 0 deletions Lumberjack/CLI/CLIColor.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
//
// CLIColor.h
// CocoaLumberjack
//
// Created by Ernesto Rivera on 2013/12/27.
//
//

#import <Foundation/Foundation.h>

/**
Simple NSColor replacement for CLI projects that don't link with AppKit
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Which is a simple NSColor replacement.

*/
@interface CLIColor : NSObject

+ (CLIColor *)colorWithCalibratedRed:(CGFloat)red green:(CGFloat)green blue:(CGFloat)blue alpha:(CGFloat)alpha;
- (void)getRed:(CGFloat *)red green:(CGFloat *)green blue:(CGFloat *)blue alpha:(CGFloat *)alpha;

@end
34 changes: 34 additions & 0 deletions Lumberjack/CLI/CLIColor.m
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
//
// CLIColor.m
// CocoaLumberjack
//
// Created by Ernesto Rivera on 2013/12/27.
//
//

#import "CLIColor.h"

@implementation CLIColor
{
CGFloat _red, _green, _blue, _alpha;
}

+(CLIColor *)colorWithCalibratedRed:(CGFloat)red green:(CGFloat)green blue:(CGFloat)blue alpha:(CGFloat)alpha
{
CLIColor * color = [CLIColor new];
color->_red = red;
color->_green = green;
color->_blue = blue;
color->_alpha = alpha;
return color;
}

- (void)getRed:(CGFloat *)red green:(CGFloat *)green blue:(CGFloat *)blue alpha:(CGFloat *)alpha
{
if (red) *red = _red;
if (green) *green = _green;
if (blue) *blue = _blue;
if (alpha) *alpha = _alpha;
}

@end
6 changes: 3 additions & 3 deletions Lumberjack/DDLog.m
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ + (void)initialize
#else
NSString *notificationName = nil;

if (NSApp)
if (NSClassFromString(@"NSApplication"))
{
notificationName = @"NSApplicationWillTerminateNotification";
}
Expand Down Expand Up @@ -908,7 +908,7 @@ - (instancetype)initWithLogMsg:(NSString *)msg
#endif
floor(NSFoundationVersionNumber) > NSFoundationVersionNumber_iOS_6_1 // iOS 7+ (> iOS 6.1)
#else
[[NSApplication sharedApplication] respondsToSelector:@selector(occlusionState)] // OS X 10.9+
[NSTimer instancesRespondToSelector:@selector(tolerance)] // OS X 10.9+
#endif
) {
queueLabel = dd_str_copy(dispatch_queue_get_label(DISPATCH_CURRENT_QUEUE_LABEL));
Expand All @@ -925,7 +925,7 @@ - (instancetype)initWithLogMsg:(NSString *)msg
#endif
floor(NSFoundationVersionNumber) < NSFoundationVersionNumber_iOS_6_0 // < iOS 6.0
#else
![[NSApplication sharedApplication] respondsToSelector:@selector(occlusionState)] // < OS X 10.9
![NSTimer instancesRespondToSelector:@selector(tolerance)] // < OS X 10.9
#endif
) {
#pragma clang diagnostic push
Expand Down
20 changes: 15 additions & 5 deletions Lumberjack/DDTTYLogger.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
#import <Foundation/Foundation.h>
#if TARGET_OS_IPHONE
#import <UIKit/UIColor.h>
#import <UIKit/UIColor.h> // iOS
#elif !defined (COCOAPODS_POD_AVAILABLE_CocoaLumberjack_CLI)
#import <AppKit/NSColor.h> // OS X with AppKit
#else
#import <AppKit/NSColor.h>
#import "CLIColor.h" // OS X without AppKit
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TTY logger detects here if it should replace NSColor by CLIColor.

#endif

#import "DDLog.h"
Expand Down Expand Up @@ -109,8 +111,10 @@
**/
#if TARGET_OS_IPHONE
- (void)setForegroundColor:(UIColor *)txtColor backgroundColor:(UIColor *)bgColor forFlag:(int)mask;
#else
#elif !defined (COCOAPODS_POD_AVAILABLE_CocoaLumberjack_CLI)
- (void)setForegroundColor:(NSColor *)txtColor backgroundColor:(NSColor *)bgColor forFlag:(int)mask;
#else
- (void)setForegroundColor:(CLIColor *)txtColor backgroundColor:(CLIColor *)bgColor forFlag:(int)mask;
#endif

/**
Expand All @@ -126,8 +130,10 @@
**/
#if TARGET_OS_IPHONE
- (void)setForegroundColor:(UIColor *)txtColor backgroundColor:(UIColor *)bgColor forFlag:(int)mask context:(int)ctxt;
#else
#elif !defined (COCOAPODS_POD_AVAILABLE_CocoaLumberjack_CLI)
- (void)setForegroundColor:(NSColor *)txtColor backgroundColor:(NSColor *)bgColor forFlag:(int)mask context:(int)ctxt;
#else
- (void)setForegroundColor:(CLIColor *)txtColor backgroundColor:(CLIColor *)bgColor forFlag:(int)mask context:(int)ctxt;
#endif

/**
Expand All @@ -144,6 +150,8 @@
* UIColor *purple = [UIColor colorWithRed:(64/255.0) green:(0/255.0) blue:(128/255.0) alpha:1.0];
* #else
* NSColor *purple = [NSColor colorWithCalibratedRed:(64/255.0) green:(0/255.0) blue:(128/255.0) alpha:1.0];
*
* Note: For CLI OS X projects that don't link with AppKit use CLIColor objects instead
*
* [[DDTTYLogger sharedInstance] setForegroundColor:purple backgroundColor:nil forTag:PurpleTag];
* [DDLog addLogger:[DDTTYLogger sharedInstance]];
Expand All @@ -154,8 +162,10 @@
**/
#if TARGET_OS_IPHONE
- (void)setForegroundColor:(UIColor *)txtColor backgroundColor:(UIColor *)bgColor forTag:(id <NSCopying>)tag;
#else
#elif !defined (COCOAPODS_POD_AVAILABLE_CocoaLumberjack_CLI)
- (void)setForegroundColor:(NSColor *)txtColor backgroundColor:(NSColor *)bgColor forTag:(id <NSCopying>)tag;
#else
- (void)setForegroundColor:(CLIColor *)txtColor backgroundColor:(CLIColor *)bgColor forTag:(id <NSCopying>)tag;
#endif

/**
Expand Down
21 changes: 13 additions & 8 deletions Lumberjack/DDTTYLogger.m
Original file line number Diff line number Diff line change
Expand Up @@ -65,15 +65,14 @@
// Some simple defines to make life easier on ourself

#if TARGET_OS_IPHONE
#define OSColor UIColor
#define MakeColor(r, g, b) [UIColor colorWithRed:(r/255.0f) green:(g/255.0f) blue:(b/255.0f) alpha:1.0f]
#else
#elif !defined (COCOAPODS_POD_AVAILABLE_CocoaLumberjack_CLI)
#define OSColor NSColor
#define MakeColor(r, g, b) [NSColor colorWithCalibratedRed:(r/255.0f) green:(g/255.0f) blue:(b/255.0f) alpha:1.0f]
#endif

#if TARGET_OS_IPHONE
#define OSColor UIColor
#else
#define OSColor NSColor
#define OSColor CLIColor
#define MakeColor(r, g, b) [CLIColor colorWithCalibratedRed:(r/255.0f) green:(g/255.0f) blue:(b/255.0f) alpha:1.0f]
#endif

// If running in a shell, not all RGB colors will be supported.
Expand Down Expand Up @@ -702,14 +701,20 @@ + (void)getRed:(CGFloat *)rPtr green:(CGFloat *)gPtr blue:(CGFloat *)bPtr fromCo
CGColorSpaceRelease(rgbColorSpace);
}

#else
#elif !defined (COCOAPODS_POD_AVAILABLE_CocoaLumberjack_CLI)

// Mac OS X
// OS X with AppKit

NSColor *safeColor = [color colorUsingColorSpaceName:NSCalibratedRGBColorSpace];

[safeColor getRed:rPtr green:gPtr blue:bPtr alpha:NULL];

#else

// OS X without AppKit

[color getRed:rPtr green:gPtr blue:bPtr alpha:NULL];

#endif
}

Expand Down
Loading