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

Ability to visualize colors #103

Closed
ZevEisenberg opened this issue Jul 28, 2015 · 18 comments
Closed

Ability to visualize colors #103

ZevEisenberg opened this issue Jul 28, 2015 · 18 comments

Comments

@ZevEisenberg
Copy link

If I run visualize someColor, I get:

UIDeviceRGBColor isn't supported. You can visualize UIImage, CGImageRef, UIView, CALayer or NSData.

Chisel should generate a square or circular image of the color, optionally with some RGB/hex info included in the image, and open the image in Preview.

@ZevEisenberg
Copy link
Author

Reference: when you Quick Look a color in the variables list:

screen shot 2015-07-28 at 5 34 19 pm

@kastiglione
Copy link
Contributor

Nice. Can I interest you in trying a pull request 😄

@ZevEisenberg
Copy link
Author

Definitely interested. I’ll put it on my list for my job’s semi-weekly hack days.

@kastiglione
Copy link
Contributor

Let me know if you have any questions, happy to answer anything.

@ZevEisenberg
Copy link
Author

@kastiglione would it be a faux pas to expr @import CoreFoundation in my command? I'm trying to have it be able to differentiate between UIColor, CIColor, and CGColor (and maybe NSColor?)

@ZevEisenberg
Copy link
Author

Specifically:

result = frame.EvaluateExpression('(CFTypeID)CFGetTypeID({color}) == (CFTypeID)CGColorGetTypeID()'.format(color=color))

@kastiglione
Copy link
Contributor

would it be a faux pas to expr @import CoreFoundation in my command?

Nah. In fact I think it would be great to do, UIKit too. Thinking aloud, I wonder if it could be done on the first time any breakpoint is hit. Then by using Chisel, you get these for free.

@kastiglione
Copy link
Contributor

Not to give you scope creep, feel free to put it in your command only. Someone can look to make it more general later.

@ZevEisenberg
Copy link
Author

I've seen it advised to always import UIKit on an exception breakpoint. I had put a UIKit import in my ~/.lldbinit, but it seemed to slow down Xcode every time I started a debugging session. I'll try again some time.

Current question: here's an error I'm getting in lldb:

error: cannot initialize a parameter of type 'CGColor *' with an rvalue of type 'CGColorRef' (aka 'CGColor *')

From a python line like this:

colorToUse = '[UIColor colorWithCGColor:(CGColorRef){}]'.format(color)

Seen anything like this?

@ZevEisenberg
Copy link
Author

Or, to simplify the question, what is the right way to call this in lldb?

po [UIColor colorWithCGColor:(CGColorRef)[[UIColor redColor] CGColor]]

@kastiglione
Copy link
Contributor

Cast the color to void *?

@ZevEisenberg
Copy link
Author

Nope:

(lldb) po [UIColor colorWithCGColor:(void *)[[UIColor redColor] CGColor]]
error: cannot initialize a parameter of type 'CGColor *' with an rvalue of type 'void *'
error: 1 errors parsing expression

(assuming that's what you meant?)

@kastiglione
Copy link
Contributor

Yup, that is what I meant. Hmm. Maybe one of:

po [UIColor colorWithCGColor:(id)[[UIColor redColor] CGColor]]
po [UIColor colorWithCGColor:(CGColor *)[[UIColor redColor] CGColor]]
po [UIColor colorWithCGColor:(CGColor *)(void *)[[UIColor redColor] CGColor]]

@kastiglione
Copy link
Contributor

Oh, I'm curious why you're going from UIColor to CGColor to UIColor?

@ZevEisenberg
Copy link
Author

Just a simple test case to reproduce what I’m seeing in the script with a CGColor. I didn’t have a CGColor handy in an app, so I was making one from a UIColor in the debugger. If I can make a CGColor in code and reference it in the script and it works, I guess I will ignore this issue for now as an edge case. I’ll try that, and your suggestions.

@ZevEisenberg
Copy link
Author

None of the suggestions worked, but worse, the actual case I'm trying to use also doesn't work. If I'm on a breakpoint and I have a local variable, cgColor, of type CGColorRef:

(lldb) po cgColor
<CGColor 0x7fdfa0546910> [<CGColorSpace 0x7fdfa0643f70> (kCGColorSpaceDeviceRGB)] ( 0 0.478431 1 1 )

(lldb) po [UIColor colorWithCGColor:cgColor]
error: cannot initialize a parameter of type 'CGColor *' with an lvalue of type 'CGColorRef' (aka 'CGColor *')
error: 1 errors parsing expression
(lldb) po [UIColor colorWithCGColor:(id)cgColor]
error: cannot initialize a parameter of type 'CGColor *' with an rvalue of type 'id'
error: 1 errors parsing expression
(lldb) po [UIColor colorWithCGColor:(CGColorRef)cgColor]
error: cannot initialize a parameter of type 'CGColor *' with an rvalue of type 'CGColorRef' (aka 'CGColor *')
error: 1 errors parsing expression
(lldb) po [UIColor colorWithCGColor:(CGColor *)cgColor]
error: use of undeclared identifier 'CGColor'
error: expected expression
error: 2 errors parsing expression
(lldb) po [UIColor colorWithCGColor:(struct CGColor *)cgColor]
error: cannot initialize a parameter of type 'CGColor *' with an rvalue of type 'struct CGColor *'
error: 1 errors parsing expression
(lldb) expr @import CoreGraphics
(lldb) po [UIColor colorWithCGColor:(struct CGColor *)cgColor]
error: cannot initialize a parameter of type 'CGColor *' with an rvalue of type 'struct CGColor *'
error: 1 errors parsing expression

So I can't use it in my script because it doesn't even work in the real debugger, at least not with the incantations I'm using.

@ZevEisenberg
Copy link
Author

It looks like this is maybe already done in chisel? Does this code work? https://github.com/facebook/chisel/blob/master/commands/FBAutoLayoutCommands.py#L44

lldb.debugger.HandleCommand('expr (void)[%s setBorderColor:(CGColorRef)[(id)[UIColor %sColor] CGColor]]' % (layer, color))

@ZevEisenberg
Copy link
Author

@kastiglione alright, I got a workaround thanks to @jvisenti: http://stackoverflow.com/a/31810890/255489

I believe it's related to the UIColor going out of scope, and -CGColor returning an internal pointer:

@property(nonatomic,readonly) CGColorRef CGColor;
- (CGColorRef)CGColor NS_RETURNS_INNER_POINTER CF_RETURNS_NOT_RETAINED;

PR should be in at some point soon-ish

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants