• Stars
    star
    1,222
  • Rank 36,827 (Top 0.8 %)
  • Language
    Ruby
  • License
    GNU General Publi...
  • Created over 14 years ago
  • Updated 11 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Ruby string class extension. It add some methods to set color, background color and text effect on console easier using ANSI escape sequences.

colorize Gem Version Ruby Gem Code Climate Test Coverage

Ruby gem for colorizing text using ANSI escape sequences. Extends String class or add a ColorizedString with methods to set the text color, background color and text effects.

modes

  • require 'colorize' - Extends String class
  • require 'colorized_string' - add ColorizedString class

features

  • change string color
  • change string background
  • change string effect
  • chain methods
  • display color samples
  • disable colorization
  • prevent colors

usage

require 'colorize'

String.colors                       # return array of all possible colors names
String.modes                        # return array of all possible modes
String.color_samples                # displays color samples in all combinations
String.disable_colorization         # check if colorization is disabled

# disable colorization (false by default)

String.disable_colorization = false # enable colorization
String.disable_colorization false   # enable colorization
String.disable_colorization = true  # disable colorization
String.disable_colorization true    # disable colorization

# prevent colors (false by default)

String.prevent_colors = false # override current string colors
String.prevent_colors false   # override current string colors
String.prevent_colors = true  # don't colorize colorized strings
String.prevent_colors true    # don't colorize colorized strings

# adding aliases (:gray and :grey added by default)

String.add_color_alias(:niebieski, :blue)
String.add_color_alias(:zielony => :green)
String.add_color_alias(czarny: :black)
String.add_color_alias(czerwony: :red, granatowy: :blue)

# examaples

puts "This is blue".colorize(:blue)
puts "This is light blue".colorize(:light_blue)
puts "This is also blue".colorize(:color => :blue)
puts "This is bold green".colorize(:color => :green, :mode => :bold)
puts "This is light blue with red background".colorize(:color => :light_blue, :background => :red)
puts "This is light blue with red background".colorize(:light_blue ).colorize( :background => :red)
puts "This is blue text on red".blue.on_red
puts "This is red on blue".colorize(:red).on_blue
puts "This is red on blue and underline".colorize(:red).on_blue.underline
puts "This is blinking blue text on red".blue.on_red.blink
puts "This is uncolorized".blue.on_red.uncolorize
require 'colorized_string'

ColorizedString.colors                       # return array of all possible colors names
ColorizedString.modes                        # return array of all possible modes
ColorizedString.color_samples                # displays color samples in all combinations
ColorizedString.disable_colorization         # check if colorization is disabled

# disable colorization (false by default)

ColorizedString.disable_colorization = false # enable colorization
ColorizedString.disable_colorization false   # enable colorization
ColorizedString.disable_colorization = true  # disable colorization
ColorizedString.disable_colorization true    # disable colorization

# prevent colors (false by default)

ColorizedString.prevent_colors = false # override current string colors
ColorizedString.prevent_colors false   # override current string colors
ColorizedString.prevent_colors = true  # don't colorize colorized strings
ColorizedString.prevent_colors true    # don't colorize colorized strings

# adding aliases (:gray and :grey added by default)

ColorizedString.add_color_alias(:niebieski, :blue)
ColorizedString.add_color_alias(:zielony => :green)
ColorizedString.add_color_alias(czarny: :black)
ColorizedString.add_color_alias(czerwony: :red, granatowy: :blue)

# examples

puts ColorizedString["This is blue"].colorize(:blue)
puts ColorizedString["This is light blue"].colorize(:light_blue)
puts ColorizedString["This is also blue"].colorize(:color => :blue)
puts ColorizedString["This is bold green"].colorize(:color => :green, :mode => :bold)
puts ColorizedString["This is light blue with red background"].colorize(:color => :light_blue, :background => :red)
puts ColorizedString["This is light blue with red background"].colorize(:light_blue ).colorize( :background => :red)
puts ColorizedString["This is blue text on red"].blue.on_red
puts ColorizedString["This is red on blue"].colorize(:red).on_blue
puts ColorizedString["This is red on blue and underline"].colorize(:red).on_blue.underline
puts ColorizedString["This is blinking blue text on red"].blue.on_red.blink
puts ColorizedString["This is uncolorized"].blue.on_red.uncolorize

puts ColorizedString.new("This is blue").blue
puts ColorizedString.new("This is light blue").colorize(:light_blue)

requirements

  • Win32/Console/ANSI (for Windows)

install

  • gem install colorize

Note: You may need to use sudo to install gems

thank you

Become Patreon

license

Copyright (C) 2007-2024 Michał Kalbarczyk

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License along
with this program; if not, write to the Free Software Foundation, Inc.,
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.

More Repositories

1

export

Erlport wrapper for Elixir
Elixir
175
star
2

defql

Create elixir functions with SQL as a body.
Elixir
103
star
3

awesome-opal

Awesome Opal
96
star
4

elixir_desktop_application

Code for story: https://puddleofcode.com/story/how-to-create-desktop-application-with-elixir
Elixir
51
star
5

tensorflow.cr

Crystal binding for TensorFlow.
Crystal
39
star
6

rust_to_js

An example of Rust code that compiles to javascript.
HTML
26
star
7

airbrakex

Elixir client for the Airbrake service.
Elixir
26
star
8

codeclimate-credo

Code Climate Credo Engine
Elixir
25
star
9

ex_ical

ICalendar parser for Elixir.
Elixir
23
star
10

gedit-mterminal

Terminal with multiple windows plugin for GEdit
Python
22
star
11

opal-virtual-dom

virtual-dom wrapper for opal
Ruby
22
star
12

fazic

fazic.fazibear.me
Rust
16
star
13

crystal_lib_gen

Automatic binding generator for Crystal
Crystal
15
star
14

Rubocop.tmbundle

Rubocop Textmate 2 Bundle
Ruby
11
star
15

codeclimate-dogma

Elixir
10
star
16

mrubyvst

VST plugin scriptable with MRuby
C++
9
star
17

asciify-me

Asciify yourself!
Ruby
8
star
18

gruby

Gadu-Gadu (polish communicator) protocol implementation in Ruby language.
Ruby
8
star
19

codeclimate-elixir

Code Climate Engine for Elixir.
Elixir
7
star
20

cmp-nerdfonts

nvim-cmp source for nerdfonts.
Lua
6
star
21

opal-phoenix

Opal wrapper for Phoenix Framework javascript library.
Ruby
6
star
22

opal-slim-sass-sprockets-example

Opal environment with sprockets, slim, sass, and rails-assets
Ruby
5
star
23

inesid

Retro Web SID Player
HTML
5
star
24

exrbbench

Elixir
4
star
25

rubyscript

attempt to convert ruby syntax to JS syntax
Ruby
3
star
26

Crystal.tmbundle

Shell
3
star
27

mrubybyexample

mruby snippets
C
3
star
28

pix_elixir

Elixir
3
star
29

opal-web-midi

Web MIDI for Opal.
Ruby
3
star
30

twitdrone

Shut up, and listen to twitter ...
Ruby
2
star
31

frubby

Bring fuzzy_match directly into ruby.
Ruby
2
star
32

tensorflow.cr_examples

Examples for crystal binding for TensorFlow.
Crystal
2
star
33

screen_saviour.nvim

Lua
2
star
34

netvibes-widgets

UWA/Netvibes Widgets
1
star
35

grtail

Grouped RailsLog Tail
Ruby
1
star
36

elixirscript-loader

JavaScript
1
star
37

web-audio-playground

Ruby
1
star
38

rebar_elixir

Rebar plugin to compile elixir code and support mix packages
Erlang
1
star
39

opal-airbrake

Opal wrapper for airbrake-js javascript library.
Ruby
1
star
40

bobi

Bobi
Ruby
1
star
41

oxmlrpc

Simple, lightweight and fast XML-RPC client library for ruby. It's based on OX XML parser.
Ruby
1
star
42

asciifyme.go

Web asciifyier in go
Go
1
star
43

ascii_chat

Simple asciiart chat web application
JavaScript
1
star