Okay, I'm trying to keep this one simple and meet my own needs at the same time. First of all, the insert color command didn't recognize abbreviated (3 character) RGB color codes. This had 2 drawbacks: The tab stop inserted by any of the CSS commands, when used in combination with Insert Color, would add an extra # sign and it wouldn't properly set the default color when it loaded the color picker. This revised command is my usual unskilled kludge, but it recognizes both 3 and 6 character rgb strings, strips the # sign if unnecessary, and if the resulting hex code is a series of double repeating characters it will abbreviate (BBAADD becomes BAD). I wanted to use squeeze to do this in Ruby, but had trouble with colors like 0000FF, where it would just give back 0F. So I made a mess of it. It works, but I'd really like to see it cleaned up (I know Haris could do this in about 4 lines of code). So if anyone has the time... It'd be great to learn a new algorithm to handle this.
As a side note, I've been using Color Schemer Studio to create websmart palettes. I can drag directly from the current color selection into textmate, but it was less convenient than the color picker. So I've been creating the palettes, and then importing them into the color picker. That's where this command came from...
Thanks, Brett
Brett,
I haven't had time to look at this yet, though I will be doing so. However, the command you have pasted has the same UUID as the one already existing in the bundle right now. In other words, you edited the command in the CSS bundle. The problem with this is that people can't really install it without hiding/overriding the existing command. It would be a better idea to make a copy of your command _in TextMate_ and then send us that one. When you duplicate a command in TextMate, it generates a new UUID for it, so that it can distinguish them.
On Oct 20, 2006, at 10:42 PM, Brett Terpstra wrote:
Thanks, Brett
Haris
Oops. Kinda wasn't thinking.
Here's a copied command.
On Oct 20, 2006, at 10:53 PM, Charilaos Skiadas wrote:
Brett,
I haven't had time to look at this yet, though I will be doing so. However, the command you have pasted has the same UUID as the one already existing in the bundle right now. In other words, you edited the command in the CSS bundle. The problem with this is that people can't really install it without hiding/overriding the existing command. It would be a better idea to make a copy of your command _in TextMate_ and then send us that one. When you duplicate a command in TextMate, it generates a new UUID for it, so that it can distinguish them.
On Oct 20, 2006, at 10:42 PM, Brett Terpstra wrote:
Thanks, Brett
Haris
For new threads USE THIS: textmate@lists.macromates.com (threading gets destroyed and the universe will collapse if you don't) http://lists.macromates.com/mailman/listinfo/textmate
Brett Terpstra : Art Director Circle Six Design, Inc. 111 Riverfront Dr, Suite 204 .................................................. p: 507.459.4398 877.858.4332 f: 1.866.540.3063 e: brett@circlesixdesign.com http://www.circlesixdesign.com ..................................................
On Oct 20, 2006, at 10:42 PM, Brett Terpstra wrote:
It works, but I'd really like to see it cleaned up (I know Haris could do this in about 4 lines of code). So if anyone has the time... It'd be great to learn a new algorithm to handle this.
Well, since you asked for it ;) I'm sure JEG2 can shorten this further, but here is my take on it. I've attached the command, and appended the actual code.
Perhaps we should add this to the CSS bundle?
Haris
#!/usr/bin/env ruby string = STDIN.read prefix, string = string.match(/(#?)(.*)/)[1,2] string = $1 * 2 + $2 * 2 + $3 * 2 if string =~ /^(.)(.)(.)$/ def_col = ' default color {' + string.scan(/../).map { |i| i.hex * 257 }.join(",") + '}' col = `osascript 2>/dev/null -e 'tell app "TextMate" to choose color# {def_col}'` exit 200 if col == "" col=col.scan(/\d+/).map { |i| "%02X" % (i.to_i / 257) }.join("") print prefix if col.match(/(.)\1(.)\2(.)\3/) then print $1 + $2 + $3 else print col end
On Oct 21, 2006, at 12:19 AM, Charilaos Skiadas wrote:
On Oct 20, 2006, at 10:42 PM, Brett Terpstra wrote:
It works, but I'd really like to see it cleaned up (I know Haris could do this in about 4 lines of code). So if anyone has the time... It'd be great to learn a new algorithm to handle this.
Well, since you asked for it ;) I'm sure JEG2 can shorten this further, but here is my take on it. I've attached the command, and appended the actual code.
Thank you, that is spectacular. This is what really had me stumped:
string = $1 * 2 + $2 * 2 + $3 * 2 if string =~ /^(.)(.)(.)$/
You do hate intermediate variables, don't you ;-)? Anyway, thanks for your time, now it's ready for prime time.
Perhaps we should add this to the CSS bundle?
I second the motion. As I mentioned before, the included command is in conflict with almost all of the snippets in the CSS bundle, which insert #DDD as the tab stop and only highlight the DDD. If you run the default Insert Color command and choose white at that point you'll end up with ##FFFFFF. I strongly recommend that this be modified!
Haris
Thanks, Brett
I think this needed a minor revision to make it work if there was no text selected (no previous color) and you just wanted to insert a color. Once again, probably not the most elegant way to handle it (but it works). Let me know what you think.
#!/usr/bin/env ruby
string = STDIN.read prefix, string = string.match(/(#?)(.*)/)[1,2] string = $1 * 2 + $2 * 2 + $3 * 2 if string =~ /^(.)(.)(.)$/ if string == '' then prefix = '#' def_col = '' else def_col = ' default color {' + string.scan(/../).map { |i| i.hex * 257 }.join(",") + '}' end col = `osascript 2>/dev/null -e 'tell app "TextMate" to choose color# {def_col}'` exit 200 if col == "" col=col.scan(/\d+/).map { |i| "%02X" % (i.to_i / 257) }.join("") print prefix if col.match(/(.)\1(.)\2(.)\3/) then print $1 + $2 + $3 else print col end
Brett
On Oct 21, 2006, at 12:19 AM, Charilaos Skiadas wrote:
On Oct 20, 2006, at 10:42 PM, Brett Terpstra wrote:
It works, but I'd really like to see it cleaned up (I know Haris could do this in about 4 lines of code). So if anyone has the time... It'd be great to learn a new algorithm to handle this.
Well, since you asked for it ;) I'm sure JEG2 can shorten this further, but here is my take on it. I've attached the command, and appended the actual code.
Perhaps we should add this to the CSS bundle?
Haris
#!/usr/bin/env ruby string = STDIN.read prefix, string = string.match(/(#?)(.*)/)[1,2] string = $1 * 2 + $2 * 2 + $3 * 2 if string =~ /^(.)(.)(.)$/ def_col = ' default color {' + string.scan(/../).map { |i| i.hex * 257 }.join(",") + '}' col = `osascript 2>/dev/null -e 'tell app "TextMate" to choose color#{def_col}'` exit 200 if col == "" col=col.scan(/\d+/).map { |i| "%02X" % (i.to_i / 257) }.join("") print prefix if col.match(/(.)\1(.)\2(.)\3/) then print $1 + $2 + $3 else print col end
<Insert Color revised copy2.tmCommand>
For new threads USE THIS: textmate@lists.macromates.com (threading gets destroyed and the universe will collapse if you don't) http://lists.macromates.com/mailman/listinfo/textmate
Brett Terpstra : Art Director Circle Six Design, Inc. 111 Riverfront Dr, Suite 204 .................................................. p: 507.459.4398 877.858.4332 f: 1.866.540.3063 e: brett@circlesixdesign.com http://www.circlesixdesign.com ..................................................
On Oct 21, 2006, at 8:21 AM, Brett Terpstra wrote:
string = $1 * 2 + $2 * 2 + $3 * 2 if string =~ /^(.)(.)(.)$/
You do hate intermediate variables, don't you ;-)?
Hehe yes I do, I try to minimize the variables I use. Mostly because I am not very good at coming up with names for them ;) Also, influenced from functional programming, I try minimize the number of assignments I use.
I think this needed a minor revision to make it work if there was no text selected (no previous color) and you just wanted to insert a color. Once again, probably not the most elegant way to handle it (but it works). Let me know what you think.
Why not instead simply give it a default, if string is empty?
string = STDIN.read string = "#999" if string.empty? prefix, string = string.match(/(#?)(.*)/)[1,2] string = $1 * 2 + $2 * 2 + $3 * 2 if string =~ /^(.)(.)(.)$/ def_col = ' default color {' + string.scan(/../).map { |i| i.hex * 257 }.join(",") + '}' ......
Haris
Good call.
I think this needed a minor revision to make it work if there was no text selected (no previous color) and you just wanted to insert a color. Once again, probably not the most elegant way to handle it (but it works). Let me know what you think.
Why not instead simply give it a default, if string is empty?
string = STDIN.read string = "#999" if string.empty? prefix, string = string.match(/(#?)(.*)/)[1,2] string = $1 * 2 + $2 * 2 + $3 * 2 if string =~ /^(.)(.)(.)$/ def_col = ' default color {' + string.scan(/../).map { |i| i.hex * 257 }.join(",") + '}' ......
Haris
For new threads USE THIS: textmate@lists.macromates.com (threading gets destroyed and the universe will collapse if you don't) http://lists.macromates.com/mailman/listinfo/textmate
Brett Terpstra : Art Director Circle Six Design, Inc. 111 Riverfront Dr, Suite 204 .................................................. p: 507.459.4398 877.858.4332 f: 1.866.540.3063 e: brett@circlesixdesign.com http://www.circlesixdesign.com ..................................................