| 1 | <HTML> |
| 2 | <HEAD> |
| 3 | <TITLE>ANSI for RUBY</TITLE> |
| 4 | |
| 5 | <META NAME="description" CONTENT="ANSI codes for your Ruby code!"> |
| 6 | |
| 7 | <LINK rel="shortcut icon" href="assets/images/ruby.png"/> |
| 8 | |
| 9 | <LINK type="text/css" rel="stylesheet" href="assets/styles/reset.css" /> |
| 10 | <LINK type="text/css" rel="stylesheet" href="assets/styles/tag.css" /> |
| 11 | <LINK type="text/css" rel="stylesheet" href="assets/styles/id.css" /> |
| 12 | |
| 13 | <SCRIPT language="javascript" type="text/javascript" src="assets/scripts/jquery.js"></SCRIPT> |
| 14 | <SCRIPT language="javascript" type="text/javascript" src="assets/scripts/highlight.js"></SCRIPT> |
| 15 | |
| 16 | <SCRIPT type="text/javascript"> |
| 17 | $(document).ready(function() { |
| 18 | $('pre.ruby').wrapInner('<code></code>'); |
| 19 | hljs.tabReplace = ' '; |
| 20 | hljs.initHighlightingOnLoad('ruby'); |
| 21 | }); |
| 22 | </SCRIPT> |
| 23 | |
| 24 | <LINK type="text/css" rel="stylesheet" href="assets/styles/highlight.css" /> |
| 25 | |
| 26 | <style> |
| 27 | #rubyworks{ position: fixed; bottom: 0; right: 3px; padding: 0; opacity: 0.2; } |
| 28 | </style> |
| 29 | </HEAD> |
| 30 | <BODY> |
| 31 | |
| 32 | <div id="header"> |
| 33 | <div class="title"> |
| 34 | <h2>Ruby's</h2> |
| 35 | <h1>ANSI</h1> |
| 36 | </div> |
| 37 | </div> |
| 38 | |
| 39 | <table id="nav"> |
| 40 | <tr><td> |
| 41 | <a href="https://rubydoc.info/gems/ansi/file/DEMO.md"> |
| 42 | <img src="assets/images/book.png" /><br/> |
| 43 | Demonstrandum |
| 44 | </a> |
| 45 | </td><td> |
| 46 | <a href="https://rubydoc.info/gems/ansi"> |
| 47 | <img src="assets/images/gears.png" /><br/> |
| 48 | Documentation |
| 49 | </a> |
| 50 | </td><td> |
| 51 | <a href="https://github.com/rubyworks/ansi/"> |
| 52 | <img src="assets/images/github.png" /><br/> |
| 53 | Development |
| 54 | </a> |
| 55 | </td></tr> |
| 56 | </table> |
| 57 | |
| 58 | <div id="doc"> |
| 59 | <p>The Ruby ANSI project is a brilliant collection of ANSI escape code |
| 60 | related libraries enabling ANSI code based colorization and stylization |
| 61 | of console output in a variety of formats and layouts.</p> |
| 62 | |
| 63 | <p>Included in the library are the Code module, which is the heart of the system, |
| 64 | a Mixin module for including color methods into your own classes, a Logger, |
| 65 | a ProgressBar, a String subclass and more. The library also includes a Terminal |
| 66 | module which provides information about the current output device.</p> |
| 67 | |
| 68 | <br/> |
| 69 | |
| 70 | <div style="text-align: center;"> |
| 71 | <a href="#" onclick="$('#readme').toggle();">Click Here to Learn More</a> |
| 72 | </div> |
| 73 | </div> |
| 74 | |
| 75 | <div class="centered"> |
| 76 | |
| 77 | <div id="readme" style="display: none;"> |
| 78 | |
| 79 | <div class="section"> |
| 80 | <p>There are a number of modules and classes provided by the ANSI package. |
| 81 | Below is a small sampling of some of these. To get an even better understanding |
| 82 | of the available modules and classes and their capabilities, have a look at the |
| 83 | <a href="https://github.com/rubyworks/ansi/tree/master/demo">QED Demonstrandum</a>.</p> |
| 84 | </div> |
| 85 | |
| 86 | <div class="section" id="section_code"><h3>ANSI::Code</h3> |
| 87 | <p>At the heart of all the provided libraries lies the ANSI::Code module which |
| 88 | defines ANSI codes as constants and methods. For example:</p> |
| 89 | |
| 90 | <pre class="ruby"> |
| 91 | require 'ansi/code' |
| 92 | |
| 93 | include ANSI::Code |
| 94 | |
| 95 | red + "Hello" + " " + blue + "World" + clear |
| 96 | </pre> |
| 97 | |
| 98 | <pre> |
| 99 | <span style="color: red">Hello</span> <span style="color: green">World</span> |
| 100 | </pre> |
| 101 | |
| 102 | <p>Or in block form...</p> |
| 103 | |
| 104 | <pre class="ruby"> |
| 105 | puts red{ "Hello" } + " " + green{ "World" } |
| 106 | </pre> |
| 107 | |
| 108 | <pre> |
| 109 | <span style="color: red">Hello</span> <span style="color: green">World</span> |
| 110 | </pre> |
| 111 | |
| 112 | <p>Rather than include <tt>ANSI::Code</tt>, these methods can also be called as module |
| 113 | methods. Either as <tt>ANSI::Code.red</tt> or just <tt>ANSI.red</tt>.</p> |
| 114 | |
| 115 | <p>The methods defined by this module are used throughout the rest of the |
| 116 | system.</p> |
| 117 | </div> |
| 118 | |
| 119 | <div class="section" id="section_progressbar"><h3>ANSI::ProgressBar</h3> |
| 120 | <p>The <tt>ANSI::ProgressBar</tt> class is great to convey the progress |
| 121 | of long running process.</p> |
| 122 | |
| 123 | <pre class="ruby"> |
| 124 | require 'ansi/progressbar' |
| 125 | |
| 126 | pbar = ANSI::Progressbar.new("Test Bar", 100) |
| 127 | |
| 128 | 100.times do |i| |
| 129 | sleep 0.01 |
| 130 | pbar.inc |
| 131 | end |
| 132 | pbar.finish |
| 133 | </pre> |
| 134 | |
| 135 | <pre> |
| 136 | Test Bar: 100% |||||||||||||||||||||||||||||||||||||||||||| Time: 00:00:11 |
| 137 | </pre> |
| 138 | |
| 139 | <p>As with the rest of the ANSI classes, ANSI codes can be used to spice up the |
| 140 | progress bar output.</p> |
| 141 | </div> |
| 142 | |
| 143 | <div class="section" id="section_string"><h3>ANSI::String</h3> |
| 144 | <p>The <tt>ANSI::String</tt> class provides a specialized String subclass ideally suited for ANSI |
| 145 | color manipulation.</p> |
| 146 | |
| 147 | <pre class="ruby"> |
| 148 | require 'ansi/string' |
| 149 | |
| 150 | flower1 = ANSI::String.new("Roses") |
| 151 | flower2 = ANSI::String.new("Violets") |
| 152 | |
| 153 | puts flower1.red + " are red and, " + flower2.blue + " are blue." |
| 154 | </pre> |
| 155 | |
| 156 | <pre> |
| 157 | <span style="color: red;">Roses</span> are red, and <span style="color: lightblue;">Violets</span> are blue. |
| 158 | </pre> |
| 159 | |
| 160 | <p>The <tt>ANSI::String</tt> class is mostly a String subclass with |
| 161 | the <tt>ANSI::Mixin</tt> module mixed-in.</p> |
| 162 | </div> |
| 163 | |
| 164 | <div class="section" id="section_columns"><h3>ANSI::Columns</h3> |
| 165 | <p>The <tt>ANSI::Columns</tt> class provides easy way to create columnar output.</p> |
| 166 | |
| 167 | <pre class="ruby"> |
| 168 | require 'ansi/columns' |
| 169 | |
| 170 | list = %w{a b c d e f g h i j k l} |
| 171 | |
| 172 | columns = ANSI::Columns.new(list) |
| 173 | |
| 174 | puts columns.to_s(4) |
| 175 | </pre> |
| 176 | |
| 177 | <pre> |
| 178 | a d g j |
| 179 | b e h k |
| 180 | c f i l |
| 181 | </pre> |
| 182 | |
| 183 | <p>A block can be passed to the constructor to apply ANSI codes to each entry.</p> |
| 184 | </div> |
| 185 | |
| 186 | <div class="section" id="section_table"><h3>ANSI::Table</h3> |
| 187 | <p>The <tt>ANSI::Table</tt> class makes quick work of tables.</p> |
| 188 | |
| 189 | <pre class="ruby"> |
| 190 | require 'ansi/table' |
| 191 | |
| 192 | data = [ |
| 193 | [ 10, 20, 30 ], |
| 194 | [ 20, 10, 20 ], |
| 195 | [ 50, 40, 20 ] |
| 196 | ] |
| 197 | |
| 198 | table = ANSI::Table.new(data) |
| 199 | |
| 200 | puts table |
| 201 | </pre> |
| 202 | |
| 203 | <pre> |
| 204 | +----+----+----+ |
| 205 | | 10 | 20 | 30 | |
| 206 | | 20 | 10 | 20 | |
| 207 | | 50 | 40 | 20 | |
| 208 | +----+----+----+ |
| 209 | </pre> |
| 210 | |
| 211 | <p>As with the <tt>Columns</tt> class, a block passed to the constructor can be |
| 212 | used to apply ANSI codes to each cell.</p> |
| 213 | </div> |
| 214 | |
| 215 | </div> |
| 216 | |
| 217 | <div id="footer"> |
| 218 | <div class="copyright"> |
| 219 | Copyright © 2010 <a href="https://rubyworks.github.io">Rubyworks</a> · |
| 220 | Background Image Copyright 2006 <a href="http://www.flickr.com/photos/26233461@N00/124396361/#/">Simon Kenny</a> |
| 221 | </div> |
| 222 | </div> |
| 223 | |
| 224 | </div> |
| 225 | |
| 226 | <div id="rubyworks"> |
| 227 | <a href="https://rubyworks.github.io"> |
| 228 | <img src="https://rubyworks.github.io/assets/images/seal.png" height="175px" /> |
| 229 | </a> |
| 230 | </div> |
| 231 | |
| 232 | </BODY> |
| 233 | </HTML> |