Sha256: 423211be74acda510d9a6969d33f078d46ee23db64260541e2bdabb2caf8ccc3

Contents?: true

Size: 1.31 KB

Versions: 18

Compression:

Stored size: 1.31 KB

Contents

= ANSI::Code

Require the library.

  require 'ansi/code'

ANSI::Code can be used as a functions module.

  str = ANSI::Code.red + "Hello" + ANSI::Code.blue + "World"
  str.assert == "\e[31mHello\e[34mWorld"

If a block is supplied to each method then yielded value will
be wrapped in the ANSI code and clear code. 

  str = ANSI::Code.red{ "Hello" } + ANSI::Code.blue{ "World" }
  str.assert == "\e[31mHello\e[0m\e[34mWorld\e[0m"

More conveniently the ANSI::Code module extends ANSI itself.

  str = ANSI.red + "Hello" + ANSI.blue + "World"
  str.assert == "\e[31mHello\e[34mWorld"

  str = ANSI.red{ "Hello" } + ANSI.blue{ "World" }
  str.assert == "\e[31mHello\e[0m\e[34mWorld\e[0m"

In the appropriate context the ANSI::Code module can also be
included, making its methods directly accessible.

  include ANSI::Code

  str = red + "Hello" + blue + "World"
  str.assert == "\e[31mHello\e[34mWorld"

  str = red{ "Hello" } + blue{ "World" }
  str.assert == "\e[31mHello\e[0m\e[34mWorld\e[0m"

Along with the single font colors, the library include background colors.

  str = on_red + "Hello"
  str.assert == "\e[41mHello"

As well as combined color methods.

  str = white_on_red + "Hello"
  str.assert == "\e[37m\e[41mHello"

The ANSI::Code module supports most standard ANSI codes, though
not all platforms support every code, so YMMV.

Version data entries

18 entries across 18 versions & 5 rubygems

Version Path
arcabouco-0.2.13 vendor/bundle/gems/ansi-1.4.3/demo/01_ansicode.rdoc
challah-1.0.0 vendor/bundle/gems/ansi-1.4.3/demo/01_ansicode.rdoc
swipe-rails-0.0.5 vendor/bundle/gems/ansi-1.4.3/demo/01_ansicode.rdoc
challah-1.0.0.beta3 vendor/bundle/gems/ansi-1.4.3/demo/01_ansicode.rdoc
challah-1.0.0.beta2 vendor/bundle/gems/ansi-1.4.3/demo/01_ansicode.rdoc
challah-1.0.0.beta vendor/bundle/gems/ansi-1.4.3/demo/01_ansicode.rdoc
challah-0.9.1.beta.3 vendor/bundle/gems/ansi-1.4.3/demo/01_ansicode.rdoc
challah-0.9.1.beta vendor/bundle/gems/ansi-1.4.3/demo/01_ansicode.rdoc
challah-0.9.0 vendor/bundle/gems/ansi-1.4.3/demo/01_ansicode.rdoc
challah-rolls-0.2.0 vendor/bundle/gems/challah-0.8.3/vendor/bundle/gems/ansi-1.4.3/demo/01_ansicode.rdoc
challah-0.8.3 vendor/bundle/gems/ansi-1.4.3/demo/01_ansicode.rdoc
ansi-1.4.3 demo/01_ansicode.rdoc
challah-0.6.1 vendor/bundle/gems/ansi-1.4.2/qed/01_ansicode.rdoc
challah-0.6.0 vendor/bundle/gems/ansi-1.4.2/qed/01_ansicode.rdoc
ansi-1.4.2 qed/01_ansicode.rdoc
ansi-1.4.1 qed/01_ansicode.rdoc
ansi-1.4.0 qed/01_ansicode.rdoc
ansi-1.3.0 qed/01_ansicode.rdoc