<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>dan.thoughts &#187; console</title>
	<atom:link href="http://blog.sosedoff.com/tag/console/feed/" rel="self" type="application/rss+xml" />
	<link>http://blog.sosedoff.com</link>
	<description>Web-development, PHP, Ruby, Sinatra, Merb, Rails, MySQL, SQLite, Web Services.</description>
	<lastBuildDate>Wed, 25 Jan 2012 18:54:45 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.4</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Debugging PHP applications in terminal</title>
		<link>http://blog.sosedoff.com/2010/07/03/debugging-php-applications-in-terminal/</link>
		<comments>http://blog.sosedoff.com/2010/07/03/debugging-php-applications-in-terminal/#comments</comments>
		<pubDate>Sat, 03 Jul 2010 05:45:39 +0000</pubDate>
		<dc:creator>Dan Sosedoff</dc:creator>
				<category><![CDATA[PHP]]></category>
		<category><![CDATA[Programming]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[Web Development]]></category>
		<category><![CDATA[console]]></category>
		<category><![CDATA[debugging]]></category>
		<category><![CDATA[eventmachine]]></category>
		<category><![CDATA[server]]></category>

		<guid isPermaLink="false">http://blog.sosedoff.com/?p=251</guid>
		<description><![CDATA[Most of Ruby web frameworks have terminal logging in development environments. It makes application debugging process much easier than using file logging. Especially for AJAX requests. Of course there is simple solution &#8211; use Firebug and javascript console. Unfortunately it is not that convenient. 
So, one day i came up with idea to make the [...]]]></description>
			<content:encoded><![CDATA[<p>Most of Ruby web frameworks have terminal logging in development environments. It makes application debugging process much easier than using file logging. Especially for AJAX requests. Of course there is simple solution &#8211; use Firebug and javascript console. Unfortunately it is not that convenient. </p>
<p>So, one day i came up with idea to make the same ruby-like style of application logging, even with colorized output.<br />
I decided to use <a href="http://eventmachine.rubyforge.org/">EventMachine</a> library as a server platform. And API is based on JSON packets, via <a href="http://flori.github.com/json/">json/pure</a>. Simple, isnt it?</p>
<p>And i called it DebugServer. Pretty understandable <img src='http://blog.sosedoff.com/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<h3>Installation</h3>
<p>To install just type</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ <span style="color: #c20cb9; font-weight: bold;">sudo</span> gem <span style="color: #c20cb9; font-weight: bold;">install</span> debugserver</pre></div></div>

<p>And for information type:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;">$ debugserver <span style="color: #660033;">-i</span></pre></div></div>

<pre>
Usage: debugserver [options]
    -h, --host HOSTNAME              Server hostname
    -p, --port PORT                  Server port
    -i, --info                       Get usage information
</pre>
<p>By default it will start on localhost:9000. </p>
<h3>Usage in PHP</h3>
<p>First, download library from GitHub repository: <a href="http://github.com/sosedoff/debugclient-php">http://github.com/sosedoff/debugclient-php</a></p>
<p>And then:</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">// place it into app initialization file</span>
<span style="color: #000088;">$debug</span> <span style="color: #339933;">=</span> DebugClient<span style="color: #339933;">::</span><span style="color: #004000;">instance</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
<span style="color: #000088;">$debug</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">connect</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// .... and write it to terminal output</span>
<span style="color: #000088;">$obj</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span>
  <span style="color: #0000ff;">'id'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">rand</span><span style="color: #009900;">&#40;</span><span style="color: #cc66cc;">0</span><span style="color: #339933;">,</span> <span style="color: #208080;">0xFFFF</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">,</span>
  <span style="color: #0000ff;">'name'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #0000ff;">'Sample name'</span><span style="color: #339933;">,</span>
  <span style="color: #0000ff;">'time'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #990000;">strftime</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'%m-%d-%Y'</span><span style="color: #339933;">,</span> <span style="color: #990000;">time</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// these functions are globally defined</span>
debug_clear<span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span> <span style="color: #666666; font-style: italic;">// clear terminal</span>
debug<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'This is a plain text message.'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
debug_info<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'This is an informational message.'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
debug_warning<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'This is a warning message.'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
debug_error<span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'This is an error message.'</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
debug_dump<span style="color: #009900;">&#40;</span><span style="color: #000088;">$obj</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
<span style="color: #666666; font-style: italic;">// optional</span>
<span style="color: #000088;">$debug</span><span style="color: #339933;">-&gt;</span><span style="color: #004000;">close</span><span style="color: #009900;">&#40;</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span></pre></div></div>

<p>Results:<br />
<img src="http://blog.sosedoff.com/wp-content/uploads/2010/07/debugserver.png" alt="Output" /></p>
<h3>Sources</h3>
<p>DebugServer: <a href="http://github.com/sosedoff/debugserver">http://github.com/sosedoff/debugserver</a><br />
PHP Client: <a href="http://github.com/sosedoff/debugclient-php">http://github.com/sosedoff/debugclient-php</a></p>
]]></content:encoded>
			<wfw:commentRss>http://blog.sosedoff.com/2010/07/03/debugging-php-applications-in-terminal/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Making colorized console output with Ruby</title>
		<link>http://blog.sosedoff.com/2010/06/01/making-colorized-console-output-with-ruby/</link>
		<comments>http://blog.sosedoff.com/2010/06/01/making-colorized-console-output-with-ruby/#comments</comments>
		<pubDate>Wed, 02 Jun 2010 03:23:04 +0000</pubDate>
		<dc:creator>Dan Sosedoff</dc:creator>
				<category><![CDATA[Programming]]></category>
		<category><![CDATA[Ruby]]></category>
		<category><![CDATA[ANSI]]></category>
		<category><![CDATA[colors]]></category>
		<category><![CDATA[console]]></category>
		<category><![CDATA[terminal]]></category>

		<guid isPermaLink="false">http://blog.sosedoff.com/?p=214</guid>
		<description><![CDATA[If you develop some console application you might want your output be more informative, have different colors for operations or logging purposes. It is possible to do with general ANSI escape codes, which are supported by most common console terminals.
The ASCII escape structure is pretty simple. It begins with &#8220;ESC&#8221; symbol, which is code 27 [...]]]></description>
			<content:encoded><![CDATA[<p>If you develop some console application you might want your output be more informative, have different colors for operations or logging purposes. It is possible to do with general <a href="http://en.wikipedia.org/wiki/ANSI_escape_code">ANSI escape code</a>s, which are supported by most common console terminals.</p>
<p>The ASCII escape structure is pretty simple. It begins with &#8220;<strong>ESC&#8221;</strong> symbol, which is code 27 in ASCII table. Then <strong>&#8220;[&#8221; </strong>symbol. Parameters that goes after &#8220;<strong>[</strong>&#8221; symbol are separated by &#8220;<strong>;</strong>&#8221; and finally ends with closing sequence: &#8220;<strong>ESC[0m</strong>&#8220;.</p>
<p>You can extend basic ruby String class with following code:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#9966CC; font-weight:bold;">class</span> <span style="color:#CC0066; font-weight:bold;">String</span>
    <span style="color:#008000; font-style:italic;"># colorize functions</span>
    <span style="color:#9966CC; font-weight:bold;">def</span> red; colorize<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF; font-weight:bold;">self</span>, <span style="color:#996600;">&quot;<span style="color:#000099;">\e</span>[1m<span style="color:#000099;">\e</span>[31m&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span>; <span style="color:#9966CC; font-weight:bold;">end</span>
    <span style="color:#9966CC; font-weight:bold;">def</span> green; colorize<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF; font-weight:bold;">self</span>, <span style="color:#996600;">&quot;<span style="color:#000099;">\e</span>[1m<span style="color:#000099;">\e</span>[32m&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span>; <span style="color:#9966CC; font-weight:bold;">end</span>
    <span style="color:#9966CC; font-weight:bold;">def</span> dark_green; colorize<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF; font-weight:bold;">self</span>, <span style="color:#996600;">&quot;<span style="color:#000099;">\e</span>[32m&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span>; <span style="color:#9966CC; font-weight:bold;">end</span>
    <span style="color:#9966CC; font-weight:bold;">def</span> yellow; colorize<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF; font-weight:bold;">self</span>, <span style="color:#996600;">&quot;<span style="color:#000099;">\e</span>[1m<span style="color:#000099;">\e</span>[33m&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span>; <span style="color:#9966CC; font-weight:bold;">end</span>
    <span style="color:#9966CC; font-weight:bold;">def</span> blue; colorize<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF; font-weight:bold;">self</span>, <span style="color:#996600;">&quot;<span style="color:#000099;">\e</span>[1m<span style="color:#000099;">\e</span>[34m&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span>; <span style="color:#9966CC; font-weight:bold;">end</span>
    <span style="color:#9966CC; font-weight:bold;">def</span> dark_blue; colorize<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF; font-weight:bold;">self</span>, <span style="color:#996600;">&quot;<span style="color:#000099;">\e</span>[34m&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span>; <span style="color:#9966CC; font-weight:bold;">end</span>
    <span style="color:#9966CC; font-weight:bold;">def</span> pur; colorize<span style="color:#006600; font-weight:bold;">&#40;</span><span style="color:#0000FF; font-weight:bold;">self</span>, <span style="color:#996600;">&quot;<span style="color:#000099;">\e</span>[1m<span style="color:#000099;">\e</span>[35m&quot;</span><span style="color:#006600; font-weight:bold;">&#41;</span>; <span style="color:#9966CC; font-weight:bold;">end</span>
    <span style="color:#9966CC; font-weight:bold;">def</span> colorize<span style="color:#006600; font-weight:bold;">&#40;</span>text, color_code<span style="color:#006600; font-weight:bold;">&#41;</span> <span style="color:#996600;">&quot;#{color_code}#{text}<span style="color:#000099;">\e</span>[0m&quot;</span> ; <span style="color:#9966CC; font-weight:bold;">end</span>
<span style="color:#9966CC; font-weight:bold;">end</span></pre></div></div>

<p>And sample usage code:</p>

<div class="wp_syntax"><div class="code"><pre class="ruby" style="font-family:monospace;"><span style="color:#CC0066; font-weight:bold;">puts</span> <span style="color:#996600;">&quot;Starting some job...&quot;</span>.<span style="color:#9900CC;">blue</span>
<span style="color:#CC0066; font-weight:bold;">puts</span> <span style="color:#996600;">&quot;Processing thing 1 [#{&quot;</span>OK<span style="color:#996600;">&quot;.green}]&quot;</span>
<span style="color:#CC0066; font-weight:bold;">puts</span> <span style="color:#996600;">&quot;Processing thing 2 [#{&quot;</span><span style="color:#CC0066; font-weight:bold;">FAIL</span><span style="color:#996600;">&quot;.red}]&quot;</span>
<span style="color:#CC0066; font-weight:bold;">puts</span> <span style="color:#996600;">&quot;Oooops! This is a warning!&quot;</span>.<span style="color:#9900CC;">yellow</span>
<span style="color:#CC0066; font-weight:bold;">puts</span> <span style="color:#996600;">&quot;Another color!&quot;</span>.<span style="color:#9900CC;">pur</span></pre></div></div>

<p>The output:</p>
<p><a href="http://blog.sosedoff.com/wp-content/uploads/2010/06/Screenshot.png"><img class="alignnone size-full wp-image-215" title="colored console" src="http://blog.sosedoff.com/wp-content/uploads/2010/06/Screenshot.png" alt="colored console" width="267" height="76" /></a></p>
<p>Nice and useful.</p>
]]></content:encoded>
			<wfw:commentRss>http://blog.sosedoff.com/2010/06/01/making-colorized-console-output-with-ruby/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

