docs/Bovem/ConsoleMethods/StyleHandling/ClassMethods.html
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>
Module: Bovem::ConsoleMethods::StyleHandling::ClassMethods
— Documentation by YARD 0.9.7
</title>
<link rel="stylesheet" href="../../../css/style.css" type="text/css" charset="utf-8" />
<link rel="stylesheet" href="../../../css/common.css" type="text/css" charset="utf-8" />
<script type="text/javascript" charset="utf-8">
pathId = "Bovem::ConsoleMethods::StyleHandling::ClassMethods";
relpath = '../../../';
</script>
<script type="text/javascript" charset="utf-8" src="../../../js/jquery.js"></script>
<script type="text/javascript" charset="utf-8" src="../../../js/app.js"></script>
</head>
<body>
<div class="nav_wrap">
<iframe id="nav" src="../../../class_list.html?1"></iframe>
<div id="resizer"></div>
</div>
<div id="main" tabindex="-1">
<div id="header">
<div id="menu">
<a href="../../../_index.html">Index (C)</a> »
<span class='title'><span class='object_link'><a href="../../../Bovem.html" title="Bovem (module)">Bovem</a></span></span> » <span class='title'><span class='object_link'><a href="../../ConsoleMethods.html" title="Bovem::ConsoleMethods (module)">ConsoleMethods</a></span></span> » <span class='title'><span class='object_link'><a href="../StyleHandling.html" title="Bovem::ConsoleMethods::StyleHandling (module)">StyleHandling</a></span></span>
»
<span class="title">ClassMethods</span>
</div>
<div id="search">
<a class="full_list_link" id="class_list_link"
href="../../../class_list.html">
<svg width="24" height="24">
<rect x="0" y="4" width="24" height="4" rx="1" ry="1"></rect>
<rect x="0" y="12" width="24" height="4" rx="1" ry="1"></rect>
<rect x="0" y="20" width="24" height="4" rx="1" ry="1"></rect>
</svg>
</a>
</div>
<div class="clear"></div>
</div>
<div id="content"><h1>Module: Bovem::ConsoleMethods::StyleHandling::ClassMethods
</h1>
<div class="box_info">
<dl>
<dt>Defined in:</dt>
<dd>lib/bovem/console.rb</dd>
</dl>
</div>
<h2>Overview</h2><div class="docstring">
<div class="discussion">
<p>Class methods for handling styles in the terminal.</p>
</div>
</div>
<div class="tags">
</div>
<h2>
Instance Method Summary
<small><a href="#" class="summary_toggle">collapse</a></small>
</h2>
<ul class="summary">
<li class="public ">
<span class="summary_signature">
<a href="#parse_style-instance_method" title="#parse_style (instance method)">#<strong>parse_style</strong>(style) ⇒ String </a>
</span>
<span class="summary_desc"><div class='inline'><p>Parse a style and returns terminal codes.</p>
</div></span>
</li>
<li class="public ">
<span class="summary_signature">
<a href="#parse_styles-instance_method" title="#parse_styles (instance method)">#<strong>parse_styles</strong>(styles) ⇒ String </a>
</span>
<span class="summary_desc"><div class='inline'><p>Parses a set of styles and returns terminals codes.</p>
</div></span>
</li>
<li class="public ">
<span class="summary_signature">
<a href="#replace_markers-instance_method" title="#replace_markers (instance method)">#<strong>replace_markers</strong>(message, plain = false) ⇒ String </a>
</span>
<span class="summary_desc"><div class='inline'><p>Replaces colors markers in a string.</p>
</div></span>
</li>
<li class="public ">
<span class="summary_signature">
<a href="#replace_term_code-instance_method" title="#replace_term_code (instance method)">#<strong>replace_term_code</strong>(codes, code, modifier = 0) ⇒ String|nil </a>
</span>
<span class="summary_desc"><div class='inline'><p>Replaces a terminal code.</p>
</div></span>
</li>
</ul>
<div id="instance_method_details" class="method_details_list">
<h2>Instance Method Details</h2>
<div class="method_details first">
<h3 class="signature first" id="parse_style-instance_method">
#<strong>parse_style</strong>(style) ⇒ <tt>String</tt>
</h3><div class="docstring">
<div class="discussion">
<p>Parse a style and returns terminal codes.</p>
<p>Supported styles and colors are those in <span class='object_link'><a href="../../../Bovem.html#TERM_COLORS-constant" title="Bovem::TERM_COLORS (constant)">TERM_COLORS</a></span> and <span class='object_link'><a href="../../../Bovem.html#TERM_EFFECTS-constant" title="Bovem::TERM_EFFECTS (constant)">TERM_EFFECTS</a></span>.
You can also prefix colors with <code>bg_</code> (like <code>bg_red</code>) for background colors.</p>
</div>
</div>
<div class="tags">
<p class="tag_title">Parameters:</p>
<ul class="param">
<li>
<span class='name'>style</span>
<span class='type'>(<tt>String</tt>)</span>
—
<div class='inline'><p>The style to parse.</p>
</div>
</li>
</ul>
<p class="tag_title">Returns:</p>
<ul class="return">
<li>
<span class='type'>(<tt>String</tt>)</span>
—
<div class='inline'><p>A string with ANSI color codes.</p>
</div>
</li>
</ul>
</div><table class="source_code">
<tr>
<td>
<pre class="lines">
29
30
31
32
33
34
35
36
37
38
39
40</pre>
</td>
<td>
<pre class="code"><span class="info file"># File 'lib/bovem/console.rb', line 29</span>
<span class='kw'>def</span> <span class='id identifier rubyid_parse_style'>parse_style</span><span class='lparen'>(</span><span class='id identifier rubyid_style'>style</span><span class='rparen'>)</span>
<span class='id identifier rubyid_style'>style</span> <span class='op'>=</span> <span class='id identifier rubyid_style'>style</span><span class='period'>.</span><span class='id identifier rubyid_ensure_string'>ensure_string</span><span class='period'>.</span><span class='id identifier rubyid_strip'>strip</span><span class='period'>.</span><span class='id identifier rubyid_parameterize'>parameterize</span>
<span class='kw'>if</span> <span class='id identifier rubyid_style'>style</span><span class='period'>.</span><span class='id identifier rubyid_present?'>present?</span>
<span class='const'><span class='object_link'><a href="../../../Bovem.html" title="Bovem (module)">Bovem</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="../../Console.html" title="Bovem::Console (class)">Console</a></span></span><span class='period'>.</span><span class='id identifier rubyid_replace_term_code'>replace_term_code</span><span class='lparen'>(</span><span class='const'><span class='object_link'><a href="../../../Bovem.html" title="Bovem (module)">Bovem</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="../../../Bovem.html#TERM_EFFECTS-constant" title="Bovem::TERM_EFFECTS (constant)">TERM_EFFECTS</a></span></span><span class='comma'>,</span> <span class='id identifier rubyid_style'>style</span><span class='comma'>,</span> <span class='int'>0</span><span class='rparen'>)</span> <span class='op'>||</span>
<span class='const'><span class='object_link'><a href="../../../Bovem.html" title="Bovem (module)">Bovem</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="../../Console.html" title="Bovem::Console (class)">Console</a></span></span><span class='period'>.</span><span class='id identifier rubyid_replace_term_code'>replace_term_code</span><span class='lparen'>(</span><span class='const'><span class='object_link'><a href="../../../Bovem.html" title="Bovem (module)">Bovem</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="../../../Bovem.html#TERM_COLORS-constant" title="Bovem::TERM_COLORS (constant)">TERM_COLORS</a></span></span><span class='comma'>,</span> <span class='id identifier rubyid_style'>style</span><span class='comma'>,</span> <span class='int'>30</span><span class='rparen'>)</span> <span class='op'>||</span>
<span class='const'><span class='object_link'><a href="../../../Bovem.html" title="Bovem (module)">Bovem</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="../../Console.html" title="Bovem::Console (class)">Console</a></span></span><span class='period'>.</span><span class='id identifier rubyid_replace_term_code'>replace_term_code</span><span class='lparen'>(</span><span class='const'><span class='object_link'><a href="../../../Bovem.html" title="Bovem (module)">Bovem</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="../../../Bovem.html#TERM_COLORS-constant" title="Bovem::TERM_COLORS (constant)">TERM_COLORS</a></span></span><span class='comma'>,</span> <span class='id identifier rubyid_style'>style</span><span class='period'>.</span><span class='id identifier rubyid_gsub'>gsub</span><span class='lparen'>(</span><span class='tstring'><span class='regexp_beg'>/</span><span class='tstring_content'>^bg_</span><span class='regexp_end'>/</span></span><span class='comma'>,</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_end'>"</span></span><span class='rparen'>)</span><span class='comma'>,</span> <span class='int'>40</span><span class='rparen'>)</span> <span class='op'>||</span>
<span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_end'>"</span></span>
<span class='kw'>else</span>
<span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_end'>"</span></span>
<span class='kw'>end</span>
<span class='kw'>end</span></pre>
</td>
</tr>
</table>
</div>
<div class="method_details ">
<h3 class="signature " id="parse_styles-instance_method">
#<strong>parse_styles</strong>(styles) ⇒ <tt>String</tt>
</h3><div class="docstring">
<div class="discussion">
<p>Parses a set of styles and returns terminals codes.
Supported styles and colors are those in <span class='object_link'><a href="../../../Bovem.html#TERM_COLORS-constant" title="Bovem::TERM_COLORS (constant)">TERM_COLORS</a></span> and <span class='object_link'><a href="../../../Bovem.html#TERM_EFFECTS-constant" title="Bovem::TERM_EFFECTS (constant)">TERM_EFFECTS</a></span>.
You can also prefix colors with <code>bg_</code> (like <code>bg_red</code>) for background colors.</p>
</div>
</div>
<div class="tags">
<p class="tag_title">Parameters:</p>
<ul class="param">
<li>
<span class='name'>styles</span>
<span class='type'>(<tt>String</tt>)</span>
—
<div class='inline'><p>The styles to parse.</p>
</div>
</li>
</ul>
<p class="tag_title">Returns:</p>
<ul class="return">
<li>
<span class='type'>(<tt>String</tt>)</span>
—
<div class='inline'><p>A string with ANSI color codes.</p>
</div>
</li>
</ul>
</div><table class="source_code">
<tr>
<td>
<pre class="lines">
48
49
50</pre>
</td>
<td>
<pre class="code"><span class="info file"># File 'lib/bovem/console.rb', line 48</span>
<span class='kw'>def</span> <span class='id identifier rubyid_parse_styles'>parse_styles</span><span class='lparen'>(</span><span class='id identifier rubyid_styles'>styles</span><span class='rparen'>)</span>
<span class='id identifier rubyid_styles'>styles</span><span class='period'>.</span><span class='id identifier rubyid_split'>split</span><span class='lparen'>(</span><span class='tstring'><span class='regexp_beg'>/</span><span class='tstring_content'>\s*[\s,-]\s*</span><span class='regexp_end'>/</span></span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_map'>map</span> <span class='lbrace'>{</span> <span class='op'>|</span><span class='id identifier rubyid_s'>s</span><span class='op'>|</span> <span class='id identifier rubyid_parse_style'>parse_style</span><span class='lparen'>(</span><span class='id identifier rubyid_s'>s</span><span class='rparen'>)</span> <span class='rbrace'>}</span><span class='period'>.</span><span class='id identifier rubyid_join'>join</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_end'>"</span></span><span class='rparen'>)</span>
<span class='kw'>end</span></pre>
</td>
</tr>
</table>
</div>
<div class="method_details ">
<h3 class="signature " id="replace_markers-instance_method">
#<strong>replace_markers</strong>(message, plain = false) ⇒ <tt>String</tt>
</h3><div class="docstring">
<div class="discussion">
<p>Replaces colors markers in a string.</p>
<p>You can specify markers by enclosing in <code>{mark=[style]}</code> and <code>{/mark}</code> tags.
Separate styles with spaces, dashes or commas. Nesting markers is supported.</p>
<p>Example:</p>
<p><code>ruby
Bovem::Console.new.replace_markers("{mark=bright bg_red}{mark=green}Hello world!{/mark}{/mark}")
# => "\e[1m\e[41m\e[32mHello world!\e[1m\e[41m\e[0m"
</code></p>
</div>
</div>
<div class="tags">
<p class="tag_title">Parameters:</p>
<ul class="param">
<li>
<span class='name'>message</span>
<span class='type'>(<tt>String</tt>)</span>
—
<div class='inline'><p>The message to analyze.</p>
</div>
</li>
<li>
<span class='name'>plain</span>
<span class='type'>(<tt>Boolean</tt>)</span>
<em class="default">(defaults to: <tt>false</tt>)</em>
—
<div class='inline'><p>If ignore (cleanify) color markers into the message.</p>
</div>
</li>
</ul>
<p class="tag_title">Returns:</p>
<ul class="return">
<li>
<span class='type'>(<tt>String</tt>)</span>
—
<div class='inline'><p>The replaced message.</p>
</div>
</li>
</ul>
<p class="tag_title">See Also:</p>
<ul class="see">
<li><span class='object_link'><a href="#parse_style-instance_method" title="Bovem::ConsoleMethods::StyleHandling::ClassMethods#parse_style (method)">#parse_style</a></span></li>
</ul>
</div><table class="source_code">
<tr>
<td>
<pre class="lines">
80
81
82
83
84
85
86
87
88
89
90
91</pre>
</td>
<td>
<pre class="code"><span class="info file"># File 'lib/bovem/console.rb', line 80</span>
<span class='kw'>def</span> <span class='id identifier rubyid_replace_markers'>replace_markers</span><span class='lparen'>(</span><span class='id identifier rubyid_message'>message</span><span class='comma'>,</span> <span class='id identifier rubyid_plain'>plain</span> <span class='op'>=</span> <span class='kw'>false</span><span class='rparen'>)</span>
<span class='id identifier rubyid_stack'>stack</span> <span class='op'>=</span> <span class='lbracket'>[</span><span class='rbracket'>]</span>
<span class='id identifier rubyid_message'>message</span><span class='period'>.</span><span class='id identifier rubyid_ensure_string'>ensure_string</span><span class='period'>.</span><span class='id identifier rubyid_gsub'>gsub</span><span class='lparen'>(</span><span class='tstring'><span class='regexp_beg'>/</span><span class='tstring_content'>((\{mark=([a-z\-_\s,]+)\})|(\{\/mark\}))</span><span class='regexp_end'>/mi</span></span><span class='rparen'>)</span> <span class='kw'>do</span>
<span class='kw'>if</span> <span class='gvar'>$LAST_MATCH_INFO</span><span class='lbracket'>[</span><span class='int'>1</span><span class='rbracket'>]</span> <span class='op'>==</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>{/mark}</span><span class='tstring_end'>"</span></span> <span class='comment'># If it is a tag, pop from the latest opened.
</span> <span class='id identifier rubyid_stack'>stack</span><span class='period'>.</span><span class='id identifier rubyid_pop'>pop</span>
<span class='id identifier rubyid_plain'>plain</span> <span class='op'>||</span> <span class='id identifier rubyid_stack'>stack</span><span class='period'>.</span><span class='id identifier rubyid_blank?'>blank?</span> <span class='op'>?</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_end'>"</span></span> <span class='op'>:</span> <span class='const'><span class='object_link'><a href="../../../Bovem.html" title="Bovem (module)">Bovem</a></span></span><span class='op'>::</span><span class='const'><span class='object_link'><a href="../../Console.html" title="Bovem::Console (class)">Console</a></span></span><span class='period'>.</span><span class='id identifier rubyid_parse_styles'>parse_styles</span><span class='lparen'>(</span><span class='id identifier rubyid_stack'>stack</span><span class='period'>.</span><span class='id identifier rubyid_last'>last</span><span class='rparen'>)</span>
<span class='kw'>else</span>
<span class='id identifier rubyid_add_style'>add_style</span><span class='lparen'>(</span><span class='gvar'>$LAST_MATCH_INFO</span><span class='lbracket'>[</span><span class='int'>3</span><span class='rbracket'>]</span><span class='comma'>,</span> <span class='id identifier rubyid_plain'>plain</span><span class='comma'>,</span> <span class='id identifier rubyid_stack'>stack</span><span class='rparen'>)</span>
<span class='kw'>end</span>
<span class='kw'>end</span>
<span class='kw'>end</span></pre>
</td>
</tr>
</table>
</div>
<div class="method_details ">
<h3 class="signature " id="replace_term_code-instance_method">
#<strong>replace_term_code</strong>(codes, code, modifier = 0) ⇒ <tt>String|nil</tt>
</h3><div class="docstring">
<div class="discussion">
<p>Replaces a terminal code.</p>
</div>
</div>
<div class="tags">
<p class="tag_title">Parameters:</p>
<ul class="param">
<li>
<span class='name'>codes</span>
<span class='type'>(<tt>Array</tt>)</span>
—
<div class='inline'><p>The valid list of codes.</p>
</div>
</li>
<li>
<span class='name'>code</span>
<span class='type'>(<tt>String</tt>)</span>
—
<div class='inline'><p>The code to lookup.</p>
</div>
</li>
<li>
<span class='name'>modifier</span>
<span class='type'>(<tt>Fixnum</tt>)</span>
<em class="default">(defaults to: <tt>0</tt>)</em>
—
<div class='inline'><p>The modifier to apply to the code.</p>
</div>
</li>
</ul>
<p class="tag_title">Returns:</p>
<ul class="return">
<li>
<span class='type'>(<tt>String|nil</tt>)</span>
—
<div class='inline'><p>The terminal code or <code>nil</code> if the code was not found.</p>
</div>
</li>
</ul>
</div><table class="source_code">
<tr>
<td>
<pre class="lines">
59
60
61
62</pre>
</td>
<td>
<pre class="code"><span class="info file"># File 'lib/bovem/console.rb', line 59</span>
<span class='kw'>def</span> <span class='id identifier rubyid_replace_term_code'>replace_term_code</span><span class='lparen'>(</span><span class='id identifier rubyid_codes'>codes</span><span class='comma'>,</span> <span class='id identifier rubyid_code'>code</span><span class='comma'>,</span> <span class='id identifier rubyid_modifier'>modifier</span> <span class='op'>=</span> <span class='int'>0</span><span class='rparen'>)</span>
<span class='id identifier rubyid_sym'>sym</span> <span class='op'>=</span> <span class='id identifier rubyid_code'>code</span><span class='period'>.</span><span class='id identifier rubyid_to_sym'>to_sym</span>
<span class='id identifier rubyid_codes'>codes</span><span class='period'>.</span><span class='id identifier rubyid_include?'>include?</span><span class='lparen'>(</span><span class='id identifier rubyid_sym'>sym</span><span class='rparen'>)</span> <span class='op'>?</span> <span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>\e[</span><span class='embexpr_beg'>#{</span><span class='id identifier rubyid_modifier'>modifier</span> <span class='op'>+</span> <span class='id identifier rubyid_codes'>codes</span><span class='lbracket'>[</span><span class='id identifier rubyid_sym'>sym</span><span class='rbracket'>]</span><span class='embexpr_end'>}</span><span class='tstring_content'>m</span><span class='tstring_end'>"</span></span> <span class='op'>:</span> <span class='kw'>nil</span>
<span class='kw'>end</span></pre>
</td>
</tr>
</table>
</div>
</div>
</div>
<div id="footer">
Generated on Thu Jan 12 16:10:58 2017 by
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
0.9.7 (ruby-2.3.0).
</div>
</div>
</body>
</html>