Comments (7)
I further encourage the more general support for traditional color hue spectrum: ROYGBIV
from colorize.
oh please do it 👍
from colorize.
I think this would be a great option too. Until then, here are some ways to do it yourself.
Picking a random color for an entire string is relatively easy:
# First get all the possible colors
colors = String.colors
# Remove :default plus any other colors you don't want
colors -= [:default, :black]
# Send a random color to your string
puts "Random Color".send(colors.sample)
Producing a rainbow of different colors in the same string can be done this way:
# First get all the possible colors
colors = String.colors
# Remove :default plus any other colors you don't want
colors -= [:default, :black]
# Break the string into characters, colorize each, and put back together
puts "Rainbow String".split('').map{|char| char.send(colors.sample)}.join('')
from colorize.
class String
def rainbow
rainbow_colors = %i[red light_red light_yellow green light_green light_blue blue light_magenta]
r = rainbow_colors.each.cycle
each_char.map { |c| c.send(r.next) }.join
end
end
text = 'Colorize me!, color me like a rainbow!'.rainbow
puts text
from colorize.
That's a lot of extra hidden characters in text. Fun idea though!
IMO something like this goes a little bit beyond the intent of what this gem would do: making simple color enhancements and highlights.
I know it's been 2-3 years, but would you be at all interested in submitting a PR, even for a very minimal possible implementation for this? This library isn't all that big.
Alternatively I could see a rainbow as either (a) something you need to explicitly enable, or (b) as a separate gem, something like colorize-rainbow
that would follow a similar mechanism as this library (i.e. extending the String
class) to add this functionality.
Thoughts @elisaado ?
BTW: I'm not a library maintainer, and even if a PR were submitted for this, I can't say if @fazibear would be open to it, but at least with a proposed solution there's greater ground for possible feedback.
Thanks!
from colorize.
Also, if this is the only feature you're particularly interested in, consider the rainbow
or lolize
gems.
Here's a blog post that shows some visual differences in their features.
from colorize.
Looks like lolize gem it the best thing for rainbowing text :)
from colorize.
Related Issues (20)
- Some escape sequences are not properly applied when a string is colorized
- Compatibility with Rails 5 HOT 1
- Support 256 colors HOT 1
- Feature request: method to return original length of a string HOT 1
- Consider adding support for random and sequenced colours HOT 1
- Any chance of switching to an Apache or MIT license? HOT 5
- Incompatible with colored gem HOT 2
- missing git tag HOT 4
- is it possible to colorize just part of the string? HOT 1
- Question - Is it possible to strip the color codes from a string that is read from STDIN HOT 1
- Colorizing with true color
- The 'trollop' gem has been deprecated and has been replaced by 'optimist'. HOT 1
- Support for Regex matched ruby string colorization
- FR: gr[ea]y HOT 9
- Gem project release notes or status HOT 2
- Readline support issue (should be optional ?) HOT 2
- Class ColorizedString add grey alias twice HOT 3
- `?` is omitted when printing HOT 3
- Regressions HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from colorize.