Ruby library Reference for v3.1.0 and over
Two modes
CE
module will be read by require 'color_echo'
or require 'color_echo/get'
.
You might not generate instance because CE
is not a class, CE
is a module.
All of function of color_echo
are module funtion.
For exmaple, when you loaded require 'color_echo'
and you called CE.fg(:cyan)
,
standard out of Kernel module functions followings puts
,p
,print
,printf
,putc
are colored with cyan
.
Hint: printf
,putc
were added in version 3.1.0
.
If you would not like to be overwritten Kernel.#puts
,Kernel.#p
,Kernel.#print
,Kernel.#printf
,Kernel.#putc
, you might load require 'color_echo/get'
instead of require 'color_echo'
.
When you load by require 'color_echo/get'
, Kernel.#puts
,Kernel.#p
,Kernel.#print
,Kernel.#printf
,Kernel.#putc
will not be overrwritten.
You would like to get String that be decorated, you might use CE.get("foo")
.
Reference of module functions
CE.pickup(pattern, foreground=:cyan, backgruond=nil, *text_attribute)
- pattern : string or regexp or array of them
- foreground : symbol or nil foreground color of string that matches pattern
- background : symbol or nil background color of string that matches pattern
- text_attribute : symbol or array of them text attribute of string that matches pattern
- Return -> self
Decorates String that matches pattern with foreground_color
and background_color
and text_attribute
.
You can see the list of value of foreground_color
, background_color
, text_attribute
by colorecho -s
and also colorecho -l
.
When to be called CE.rainbow
, this module function will be ignored.
You can highlight specific string by CE.pickup
.
CE.highlight(foreground=nil, background=nil, *text_attribute)
- foreground : symbol or nil foreground color of line that matches pattern
- background : symbol or nil background color of line that matches pattern
- text_attribute : symbol or array of them text attribute of line that matches pattern
- Return -> self
Decorates line that matches pattern with foreground_color
and background_color
and text_attribute
.
You can see the list of values of foreground_color
, background_color
, text_attribute
by colorecho -s
and also colorecho -l
.
CE.ch_fg(foreground_color)
- foreground_color : symbol foreground color
- Return -> self
Changes foreground color to specified value by foreground
.
Alias of this module function is fg
.
- symbol list that can to specify in
foreground
- :black
- :red
- :green
- :yellow
- :blue
- :magenta
- :cyan
- :white
- :gray
- :h_red
- :h_green
- :h_yellow
- :h_blue
- :h_magenta
- :h_cyan
- :h_white
- :index[1-256]
CE.ch_bg(background_color)
- background : symbol background color
- Return -> self
Changes background color to specified value by background_color
.
Alias of this module function is bg
.
- symbol list that can to specify in
background_color
- :black
- :red
- :green
- :yellow
- :blue
- :magenta
- :cyan
- :white
- :gray
- :h_red
- :h_green
- :h_yellow
- :h_blue
- :h_magenta
- :h_cyan
- :h_white
- :index[1-256]
CE.ch_tx(*text_attribute)
- text_attribute : symbol or array of them
- Return -> self
Changes text attribute to specified value by text_attribute
.
You can see the list of value of text_attribute by colorecho -s.
Alias of this module function is tx
.
- symbol list that can to specify in
text_attribute
- :bold … Bold or increased intensity
- :underline … Underline: Single
- :blink … Blink: Slow
- :reverse_video … reverse video
- :concealed … Conceal; Not widely supported
CE.ch(foreground, background=nil, *text_attribute)
- foreground : symbol or nil foreground color; accept `nil`
- background : symbol or nil background color; accept `nil`
- text_attribute : symbol or array of them text attribute
- Return -> self
Changes foreground color and background color and text attribute to specified values.
CE.reset(scope=:all)
- scope : symbol or array of them scope of target to reset
- Return -> self
resets specified values. scopre of target to reset will be decided parameter of scope
.
Default is :all
, So all of values will be reset.
Alias of this module function are off
, disable
.
- symbol list that can to specify in
scope
- :all … resets all of values
- :fg … resets value of foregroud color by
CE.ch_fg
- :bg … resets value of background color by
CE.ch_bg
- :tx … resets value of text attribute by
CE.ch_tx
- :pickup … reset values of pattern by
CE.pickup
- :highlight … reset values of decoration by
CE.highlight
- :rainbow … reset rainbow foreground color by
CE.rainbow
CE.once
- Return -> self
Decorates just once. It’s the same as CE.times(1)
.
CE.times(cnt)
- cnt : integer
- Return -> self
Decorates number of times that is specified with cnt
.
CE.enable_refresh(scope=:all)
- scope : symbol
- Return -> self
Tries to delete sequence code of given input.
- symbol list that can to specify in
scope
- :all … always tries to delete sequence code
- :prematch … tries to delete sequence code when matches -p option’s patern
CE.disable_refresh
- Return -> self
Dosen’t try to delete sequence code that is given form input. This is default.
CE.unuse
- Return -> void
Turns to disable color_echo
.
CE.rainbow
- Return -> self
Changes foreground color to like rainbow.
CE.get(string)
- string : string string of target
- Return -> string
Returns string
with decoration.
This module function can to call when be loaded not require 'color_echo'
but require 'color_echo/get'
.
After this module function was called, all of specification for decoration will be reset.
If you would not that, you might call CE.stateful
before this module function.
CE.stateful
- Return -> self
Keeps specification for decoration after CE.get
was called.
When you don’t call CE.get
, this module function is meaningless.
CE.stateless
- Return -> self
All of specification for decoration will be reset after CE.get
was called.
When you don’t call CE.get
, this module function is meaningless.
CE.withdraw(target [,...])
- target : symbol
- Return -> array
Dose not assign preference of decaration toward the module functions that be specified in argument.
For example executed CE.withdraw(:printf)
, output of printf
won’t be decorated.
You can specify values at the same time by comma.
The return value is array of symbol that succeeded to withdraw them.
This module function was added in version 3.1.0
.
- symbol list that can to specify in
target
- :puts … withdraw
Kernel.#puts
decoration - :p … withdraw
Kernel.#p
decoration - :print … withdraw
Kernel.#print
decoration - :printf … withdraw
Kernel.#printf
decoration - :putc … withdraw
Kernel.#putc
decoration
- :puts … withdraw
CE.get_assigned
- Return -> array
Returns array of symbol of module functions that assigned preference of decoration.
It will returns [:puts, :p, :print, :printf, :putc]
When you didn’t call CE.withdraw
.
This module function was added in version 3.1.0
.