-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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 Colorize #7690
Improve Colorize #7690
Conversation
I would like to use these two methods in my code because I want to append only the start ANSI escape sequence, not the end. I want to append the end at a different time. This would allow me to implement something efficiently.
I resolved the conflicts, fixed some bugs and deprecated a method. Can this please be reviewed? |
Co-Authored-By: Sijawusz Pur Rahnama <[email protected]>
Bump, this still on anyone's radar? Seems it needs another rebase... |
Hello, I don't think there is interest in this PR but I resolved the conflicts anyway. It's unfortunate that this wasn't merged before 1.0 because it does some breaking changes like removing |
I think most of this is really good, but it's also a bunch of different changes merged together. It's hard to review. IMO it would be easier to merge in spearate chunks. Ideally, I think each of the bullet points in the OP should be a separate PR. Maybe some could be merged, but to me it seems they're for the most part independent changes. As you already mentioned, we can't simply remove |
if mode == Mode::Bright | ||
puts "Warning: The text decoration `bright` is deprecated. Please use `bold` instead.".colorize(:light_yellow) unless @@warning_printed | ||
@@warning_printed = true | ||
end |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do deprecation warnings work on enum members? Don't think the annotation existed when this PR was made but that would prob be more ideal.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, it would be nice if that worked but they don't work.
I have re-added |
|
This:
Colorize
and improves some.Colorize.on_tty_only!
and makes it the default so you don't have to put it at the beginning of every program that usesColorize
because you don't want that your program behaves badly in non-TTY terminals (i.e. that the ANSI escape codes become visible). Most people don't do this/forget it.Fixes Remove manual symbols in Crystal with automatic casting enums? #6736 because as to my knowledge there are no other examples where enums are being manually duplicated as symbols.
Object.colorize(r, g, b)
which is a syntactic sugar forObject.colorize(Colorize::ColorRGB.new(r, g, b))
. It's a bit of an alias but I'd say it's rather syntactic sugar and less worse than all the other aliases inColorize
."hello".colorize(:red).inspect
returning"hello"
in red instead of"\e[31mhello\e[0m"
which is probably what you want when you inspect a colored string.bright
. See Improve Colorize #7690 (comment).