Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

colorful

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

colorful

  • 0.0.3
  • Rubygems
  • Socket score

Version published
Maintainers
1
Created
Source

Colorful is a gem that provides color and effect support to native Ruby Strings when printed in an ANSI color supporting terminal.

The following code will print "Test" in red using the terminal's color scheme:

puts "Test".red

Background colors are also supported:

puts "Test".blue_background

You can combine the two:

puts "Test".red.blue_background

or:

puts "Test".red_on_blue

Add some effects:

puts "Test".red_on_blue.blink.underline

And then remove some:

puts "Test".red_on_blue.blink.underline.no_blink

The supported terminal colors are:

  • black
  • red
  • green
  • yellow
  • blue
  • magenta
  • cyan
  • white
  • default

The supported effects are:

  • reset
  • bright/bold
  • italic
  • underline
  • blink
  • inverse
  • hide

Note that not all of these formats may not be supported in all environments. Using an unsupported effect will not cause any display issues, other than the style not being applied.

Additionally, Colorful supports full rgb256 or HTML color values

To use rgb256 true red as the foreground:

puts "Test".color(255, 0, 0)

For the HTML version:

puts "Test".color("F00")

or:

puts "Test".color("#ff0000")

or:

puts "Test".color(:_ff0000)

These methods handle standard or shortened HTML codes, case insensitive, with or without # or _

Note that these methods require xterm 256 color support, and colors will be translated to the nearest possible valid color.

Lastly, some methods have been added that allow for cursor movement. The supported movement operations include:

  • and_go_up(n)
  • and_go_down(n)
  • and_go_left(n)
  • and_go_right(n)
  • and_go_to(n)

To return to the beginning of the line:

10.times do |n|
  print n.to_s.and_go_to 0
end

or:

10.times do |n|
  puts n.to_s.and_go_up 1
end

Note that some methods work better with puts, and others with print. Puts will implicitly add a new line to the end of the string it is printing, moving the cursor.

This is a work in progress but is stable. Let me know if you would like a feature added to the project.

FAQs

Package last updated on 09 Dec 2011

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc