<?xml version="1.0" encoding="UTF-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
  <id>http://www.h3rald.com/</id>
  <title>H3RALD - Tag 'rawline' (Atom Feed)</title>
  <updated>2009-03-07T03:54:00Z</updated>
  <link rel="alternate" href="http://www.h3rald.com"/>
  <link rel="self" href="http://www.h3rald.com/tags/rawline/atom/"/>
  <author>
    <name>Fabio Cevasco</name>
    <uri>http://www.h3rald.com</uri>
  </author>
  <entry>
    <id>tag:www.h3rald.com,2009-03-06:/articles/real-world-rawline-usage/</id>
    <title>Real-world Rawline usage</title>
    <published>2009-03-07T03:54:00Z</published>
    <updated>2009-09-06T18:10:55Z</updated>
    <link rel="alternate" href="http://www.h3rald.com/articles/real-world-rawline-usage/"/>
    <category term="ruby" scheme="http://www.h3rald.com/tags/ruby/"/>
    <category term="rawline" scheme="http://www.h3rald.com/tags/rawline/"/>
    <content type="html">
<![CDATA[
<p>So I finally decided to update <a href="/rawline">RawLine</a> last week, and I added a more Readline-like <span class="caps">API</span>. When I first started the project, I was determined <em>not</em> to do that, because the current Readline wrapper shipped with Ruby is not very Ruby-ish: it&#8217;s a wrapper, after all!</p>
<p>The good thing of having a new <span class="caps">API</span> compatible with Readline is that now people can use RawLine in their Readline-powered scripts, with very minor modifications.</p>
<p>Let&#8217;s have a look at some examples (they are also shipped with <a href="http://rubyforge.org/projects/rawline">Rawline v0.3.1</a>):<br />
h3. Rush</p>
<p><a href="http://rush.heroku.com">Rush</a> is an excellent gem which provides a cross-platform shell environment, entirely written in Ruby.<br />
Being a shell, it obviously uses Readline for tab completion, and that does the job on Linux. On Windows though, things aren&#8217;t that easy:</p>
<ul>
	<li>text gets garbled if you write long lines</li>
	<li>you can&#8217;t type certain characters if they use some key modifiers like <RIGHT-ALT>, etc.</li>
</ul>
<p>RawLine doesn&#8217;t have these problems (that&#8217;s the very reason why I created it), so here&#8217;s a simple script which launches a Rawline-enabled Rush shell:</p>
<div class="CodeRay">
  <div class="code"><pre><span class="line-numbers"> <a href="#n1" name="n1">1</a></span>require <span class="string"><span class="delimiter">'</span><span class="content">rubygems</span><span class="delimiter">'</span></span>
<span class="line-numbers"> <a href="#n2" name="n2">2</a></span>require <span class="string"><span class="delimiter">'</span><span class="content">rush</span><span class="delimiter">'</span></span>
<span class="line-numbers"> <a href="#n3" name="n3">3</a></span>require <span class="string"><span class="delimiter">'</span><span class="content">rawline</span><span class="delimiter">'</span></span>
<span class="line-numbers"> <a href="#n4" name="n4">4</a></span>
<span class="line-numbers"> <a href="#n5" name="n5">5</a></span><span class="keyword">class</span> <span class="class">RawlineRush</span> &lt; <span class="constant">Rush</span>::<span class="constant">Shell</span>
<span class="line-numbers"> <a href="#n6" name="n6">6</a></span>
<span class="line-numbers"> <a href="#n7" name="n7">7</a></span>  <span class="keyword">def</span> <span class="function">initialize</span>
<span class="line-numbers"> <a href="#n8" name="n8">8</a></span>    <span class="constant">Rawline</span>.basic_word_break_characters = <span class="string"><span class="delimiter">&quot;</span><span class="delimiter">&quot;</span></span> 
<span class="line-numbers"> <a href="#n9" name="n9">9</a></span>    <span class="constant">Rawline</span>.completion_proc = completion_proc
<span class="line-numbers"><strong><a href="#n10" name="n10">10</a></strong></span>    <span class="keyword">super</span>
<span class="line-numbers"><a href="#n11" name="n11">11</a></span>  <span class="keyword">end</span>
<span class="line-numbers"><a href="#n12" name="n12">12</a></span>
<span class="line-numbers"><a href="#n13" name="n13">13</a></span>  <span class="keyword">def</span> <span class="function">run</span>
<span class="line-numbers"><a href="#n14" name="n14">14</a></span>    loop <span class="keyword">do</span>
<span class="line-numbers"><a href="#n15" name="n15">15</a></span>      cmd = <span class="constant">Rawline</span>.readline(<span class="string"><span class="delimiter">'</span><span class="content">rawline_rush&gt; </span><span class="delimiter">'</span></span>)
<span class="line-numbers"><a href="#n16" name="n16">16</a></span>      finish <span class="keyword">if</span> cmd.nil? <span class="keyword">or</span> cmd == <span class="string"><span class="delimiter">'</span><span class="content">exit</span><span class="delimiter">'</span></span>
<span class="line-numbers"><a href="#n17" name="n17">17</a></span>      <span class="keyword">next</span> <span class="keyword">if</span> cmd == <span class="string"><span class="delimiter">&quot;</span><span class="delimiter">&quot;</span></span>
<span class="line-numbers"><a href="#n18" name="n18">18</a></span>      <span class="constant">Rawline</span>::<span class="constant">HISTORY</span>.push(cmd)
<span class="line-numbers"><a href="#n19" name="n19">19</a></span>      execute(cmd)
<span class="line-numbers"><strong><a href="#n20" name="n20">20</a></strong></span>    <span class="keyword">end</span>
<span class="line-numbers"><a href="#n21" name="n21">21</a></span>  <span class="keyword">end</span>
<span class="line-numbers"><a href="#n22" name="n22">22</a></span><span class="keyword">end</span>
<span class="line-numbers"><a href="#n23" name="n23">23</a></span>
<span class="line-numbers"><a href="#n24" name="n24">24</a></span>shell = <span class="constant">RawlineRush</span>.new.run
</pre></div>
</div>

<p>What happens here? Nothing much really, all I had to do was:</p>
<ol>
	<li>Derive a new class from Rush::Shell</li>
	<li>Set <code>Rawline.basic_word_break_characters</code> to the same value used in the original Rush code</li>
	<li>Set <code>Rawline.completion_proc</code> to <em>the same</em> completion Proc used in the original Rush code</li>
	<li>Rewrite the original <code>run</code> replacing <code>Readline</code> with <code>Rawline</code></li>
</ol>
<p>And it works as it was intended to, i.e. typing <code>root['b&lt;TAB&gt;</code> will expand to <code>root['bin/</code>, etc.<br />
Note that I didn&#8217;t write the completion Proc from scratch: it was already there.</p>
<h3><span class="caps">IRB</span></h3>
<p>After trying out Rush, the next logical step was trying <span class="caps">IRB</span> itself: I could never use it properly on Windows, and that was really frustrating.<br />
After a few minutes trying to figure out how to start <span class="caps">IRB</span> programmatically, I quickly came up with a similar example:</p>
<div class="CodeRay">
  <div class="code"><pre><span class="line-numbers"> <a href="#n1" name="n1">1</a></span>require <span class="string"><span class="delimiter">'</span><span class="content">irb</span><span class="delimiter">'</span></span>
<span class="line-numbers"> <a href="#n2" name="n2">2</a></span>require <span class="string"><span class="delimiter">'</span><span class="content">irb/completion</span><span class="delimiter">'</span></span>
<span class="line-numbers"> <a href="#n3" name="n3">3</a></span>require <span class="string"><span class="delimiter">'</span><span class="content">rubygems</span><span class="delimiter">'</span></span>
<span class="line-numbers"> <a href="#n4" name="n4">4</a></span>require <span class="string"><span class="delimiter">'</span><span class="content">rawline</span><span class="delimiter">'</span></span>
<span class="line-numbers"> <a href="#n5" name="n5">5</a></span>
<span class="line-numbers"> <a href="#n6" name="n6">6</a></span><span class="constant">Rawline</span>.basic_word_break_characters= <span class="string"><span class="delimiter">&quot;</span><span class="content"> </span><span class="char">\t</span><span class="char">\n</span><span class="char">\&quot;</span><span class="char">\\</span><span class="content">'`&gt;&lt;;|&amp;{(</span><span class="delimiter">&quot;</span></span> 
<span class="line-numbers"> <a href="#n7" name="n7">7</a></span><span class="constant">Rawline</span>.completion_append_character = <span class="predefined-constant">nil</span>
<span class="line-numbers"> <a href="#n8" name="n8">8</a></span><span class="constant">Rawline</span>.completion_proc = <span class="constant">IRB</span>::<span class="constant">InputCompletor</span>::<span class="constant">CompletionProc</span>
<span class="line-numbers"> <a href="#n9" name="n9">9</a></span>
<span class="line-numbers"><strong><a href="#n10" name="n10">10</a></strong></span><span class="keyword">class</span> <span class="class">RawlineInputMethod</span> &lt; <span class="constant">IRB</span>::<span class="constant">ReadlineInputMethod</span>
<span class="line-numbers"><a href="#n11" name="n11">11</a></span>  include <span class="constant">Rawline</span>
<span class="line-numbers"><a href="#n12" name="n12">12</a></span>  <span class="keyword">def</span> <span class="function">gets</span>
<span class="line-numbers"><a href="#n13" name="n13">13</a></span>    <span class="keyword">if</span> l = readline(<span class="instance-variable">@prompt</span>, <span class="predefined-constant">false</span>)
<span class="line-numbers"><a href="#n14" name="n14">14</a></span>      <span class="constant">HISTORY</span>.push(l) <span class="keyword">if</span> !l.empty?
<span class="line-numbers"><a href="#n15" name="n15">15</a></span>      <span class="instance-variable">@line</span>[<span class="instance-variable">@line_no</span> += <span class="integer">1</span>] = l + <span class="string"><span class="delimiter">&quot;</span><span class="char">\n</span><span class="delimiter">&quot;</span></span>
<span class="line-numbers"><a href="#n16" name="n16">16</a></span>    <span class="keyword">else</span>
<span class="line-numbers"><a href="#n17" name="n17">17</a></span>      <span class="instance-variable">@eof</span> = <span class="predefined-constant">true</span>
<span class="line-numbers"><a href="#n18" name="n18">18</a></span>      l
<span class="line-numbers"><a href="#n19" name="n19">19</a></span>    <span class="keyword">end</span>
<span class="line-numbers"><strong><a href="#n20" name="n20">20</a></strong></span>  <span class="keyword">end</span>
<span class="line-numbers"><a href="#n21" name="n21">21</a></span><span class="keyword">end</span>
<span class="line-numbers"><a href="#n22" name="n22">22</a></span>
<span class="line-numbers"><a href="#n23" name="n23">23</a></span><span class="keyword">module</span> <span class="class">IRB</span>
<span class="line-numbers"><a href="#n24" name="n24">24</a></span>  <span class="instance-variable">@CONF</span>[<span class="symbol">:SCRIPT</span>] = <span class="constant">RawlineInputMethod</span>.new
<span class="line-numbers"><a href="#n25" name="n25">25</a></span><span class="keyword">end</span>
<span class="line-numbers"><a href="#n26" name="n26">26</a></span><span class="constant">IRB</span>.start
</pre></div>
</div>

<p>In this case, Rawline is included in the <code>RawlineInputMethod</code> class, derived from the original <code>ReadlineInputMethod</code> class, i.e. the class <span class="caps">IRB</span> uses to define (guess&#8230;) how to input characters.<br />
Again, all I had to do was set a few Rawline variables to match the ones used in Readline, and then redefine the function used to get characters. All done.</p>
<p>It works as expected (only with inline completion, of course): typing <code>"test".ma&lt;TAB&gt;</code> will give you <code>"test".map</code>, <code>"test".match</code>, etc.</p>
<p>You also get all Rawline key mappings for free (<span class="caps">CTRL</span>-K to clear the line, <span class="caps">CTRL</span>-U and <span class="caps">CTRL</span>-R to undo and redo, etc.), and you can define your own.</p>]]>
    </content>
  </entry>
  <entry>
    <id>tag:www.h3rald.com,2009-02-28:/articles/rawline-030/</id>
    <title>RawLine 0.3.0 released &#8212; now with Readline emulation</title>
    <published>2009-03-01T06:47:00Z</published>
    <updated>2009-09-06T18:10:54Z</updated>
    <link rel="alternate" href="http://www.h3rald.com/articles/rawline-030/"/>
    <category term="ruby" scheme="http://www.h3rald.com/tags/ruby/"/>
    <category term="opensource" scheme="http://www.h3rald.com/tags/opensource/"/>
    <category term="rawline" scheme="http://www.h3rald.com/tags/rawline/"/>
    <content type="html">
<![CDATA[
<p><a href="/rawline">RawLine</a> 0.3.0 has been <a href="http://rubyforge.org/projects/rawline">released</a>. This new milestones fixes some minor bugs and adds some new functionalities, must notably:</p>
<ul>
	<li>Ruby 1.9 support</li>
	<li>A filename completion function</li>
	<li>A new <span class="caps">API</span> very similar to the one exposed by the Ruby wrapper for <span class="caps">GNU</span> Readline</li>
</ul>
<p>Some of you asked for Readline compatibility/emulation and that was actually not too difficult to implement: all the bricks were already there, I just had to put them together in the right place.</p>
<p>The <code>RawLine</code> module (you can spell it &#8220;Rawline&#8221; as well, if you wish) now behaves like <code>Readline</code>. This means that you can now use RawLine like this (taken from examples/readline_emulation.rb):</p>
<div class="CodeRay">
  <div class="code"><pre><span class="line-numbers"> <a href="#n1" name="n1">1</a></span>include <span class="constant">Rawline</span>
<span class="line-numbers"> <a href="#n2" name="n2">2</a></span>
<span class="line-numbers"> <a href="#n3" name="n3">3</a></span>puts <span class="string"><span class="delimiter">&quot;</span><span class="content">*** Readline Emulation Test Shell ***</span><span class="delimiter">&quot;</span></span>
<span class="line-numbers"> <a href="#n4" name="n4">4</a></span>puts <span class="string"><span class="delimiter">&quot;</span><span class="content"> * Press CTRL+X to exit</span><span class="delimiter">&quot;</span></span>
<span class="line-numbers"> <a href="#n5" name="n5">5</a></span>puts <span class="string"><span class="delimiter">&quot;</span><span class="content"> * Press &lt;TAB&gt; for file completion</span><span class="delimiter">&quot;</span></span>
<span class="line-numbers"> <a href="#n6" name="n6">6</a></span>
<span class="line-numbers"> <a href="#n7" name="n7">7</a></span><span class="constant">Rawline</span>.editor.bind(<span class="symbol">:ctrl_x</span>) { puts; puts <span class="string"><span class="delimiter">&quot;</span><span class="content">Exiting...</span><span class="delimiter">&quot;</span></span>; exit }
<span class="line-numbers"> <a href="#n8" name="n8">8</a></span>
<span class="line-numbers"> <a href="#n9" name="n9">9</a></span><span class="constant">Dir</span>.chdir <span class="string"><span class="delimiter">'</span><span class="content">..</span><span class="delimiter">'</span></span>
<span class="line-numbers"><strong><a href="#n10" name="n10">10</a></strong></span>
<span class="line-numbers"><a href="#n11" name="n11">11</a></span>loop <span class="keyword">do</span>
<span class="line-numbers"><a href="#n12" name="n12">12</a></span>  puts <span class="string"><span class="delimiter">&quot;</span><span class="content">You typed: [</span><span class="inline"><span class="inline-delimiter">#{</span>readline(<span class="string"><span class="delimiter">&quot;</span><span class="content">=&gt; </span><span class="delimiter">&quot;</span></span>, <span class="predefined-constant">true</span>).chomp!<span class="inline-delimiter">}</span></span><span class="content">]</span><span class="delimiter">&quot;</span></span>
<span class="line-numbers"><a href="#n13" name="n13">13</a></span><span class="keyword">end</span>
</pre></div>
</div>

<p>Basically you get a <code>readline</code> method, a <code>HISTORY</code> constant like the one exposed by Readline (Rawline&#8217;s is a RawLine::HistoryBuffer object though &mdash; much more manageable), and a <code>FILENAME_COMPLETION_PROC</code> constant, which provides basic filename completion. Here it is:</p>
<div class="CodeRay">
  <div class="code"><pre><span class="line-numbers"> <a href="#n1" name="n1">1</a></span><span class="keyword">def</span> <span class="function">filename_completion_proc</span>
<span class="line-numbers"> <a href="#n2" name="n2">2</a></span>      lambda <span class="keyword">do</span> |word|
<span class="line-numbers"> <a href="#n3" name="n3">3</a></span>        dirs = <span class="instance-variable">@line</span>.text.split(<span class="string"><span class="delimiter">'</span><span class="content">/</span><span class="delimiter">'</span></span>)
<span class="line-numbers"> <a href="#n4" name="n4">4</a></span>          path = <span class="instance-variable">@line</span>.text.match(<span class="regexp"><span class="delimiter">/</span><span class="content">^</span><span class="char">\/</span><span class="content">|[a-zA-Z]:</span><span class="char">\/</span><span class="delimiter">/</span></span>) ? <span class="string"><span class="delimiter">&quot;</span><span class="content">/</span><span class="delimiter">&quot;</span></span> : <span class="constant">Dir</span>.pwd+<span class="string"><span class="delimiter">&quot;</span><span class="content">/</span><span class="delimiter">&quot;</span></span>
<span class="line-numbers"> <a href="#n5" name="n5">5</a></span>        <span class="keyword">if</span> dirs.length == <span class="integer">0</span> <span class="keyword">then</span> <span class="comment"># starting directory</span>
<span class="line-numbers"> <a href="#n6" name="n6">6</a></span>          dir = path
<span class="line-numbers"> <a href="#n7" name="n7">7</a></span>        <span class="keyword">else</span>
<span class="line-numbers"> <a href="#n8" name="n8">8</a></span>          dirs.delete(dirs.last) <span class="keyword">unless</span> <span class="constant">File</span>.directory?(path+dirs.join(<span class="string"><span class="delimiter">'</span><span class="content">/</span><span class="delimiter">'</span></span>))
<span class="line-numbers"> <a href="#n9" name="n9">9</a></span>          dir = path+dirs.join(<span class="string"><span class="delimiter">'</span><span class="content">/</span><span class="delimiter">'</span></span>)
<span class="line-numbers"><strong><a href="#n10" name="n10">10</a></strong></span>        <span class="keyword">end</span>
<span class="line-numbers"><a href="#n11" name="n11">11</a></span>        <span class="constant">Dir</span>.entries(dir).select { |e| (e =~ <span class="regexp"><span class="delimiter">/</span><span class="content">^</span><span class="char">\.</span><span class="delimiter">/</span></span> &amp;&amp; <span class="instance-variable">@match_hidden_files</span> &amp;&amp; word == <span class="string"><span class="delimiter">'</span><span class="delimiter">'</span></span>) || (e =~ <span class="regexp"><span class="delimiter">/</span><span class="content">^</span><span class="inline"><span class="inline-delimiter">#{</span>word<span class="inline-delimiter">}</span></span><span class="delimiter">/</span></span> &amp;&amp; e !~ <span class="regexp"><span class="delimiter">/</span><span class="content">^</span><span class="char">\.</span><span class="delimiter">/</span></span>) }
<span class="line-numbers"><a href="#n12" name="n12">12</a></span>      <span class="keyword">end</span>
<span class="line-numbers"><a href="#n13" name="n13">13</a></span>    <span class="keyword">end</span>
</pre></div>
</div>

<p>You can find this function as part of the <code>RawLine::Editor</code> class. The result is not exactly the same Readline, because completion matches are not displayed underneath the line but inline and can be cycled through &mdash; which is one of Readline&#8217;s completion modes anyway.</p>
<p>A few methods of the <code>RawLine::Editor</code> class can now be accessed directly from the <code>RawLine</code> module, like with Readline:</p>
<ul>
	<li><code>Rawline.completion_proc</code> &mdash; the Proc object used for <span class="caps">TAB</span> completion (defaults to FILENAME_COMPLETION_PROC).</li>
	<li><code>Rawline.completion_matches</code> &mdash; an array of completion matches.</li>
	<li><code>Rawline.completion_append_char</code> &mdash; a character to append after a successful completion.</li>
	<li><code>Rawline.basic_word_break_characters</code> &mdash; a String listing all the characters used as word separators.</li>
	<li><code>Rawline.completer_word_break_characters</code> &mdash; same as above.</li>
	<li><code>Rawline.library_version</code> &mdash; the current version of the Rawline library.</li>
	<li><code>Rawline.clear_history</code> &mdash; to clear the current history.</li>
	<li><code>Rawline.match_hidden_files</code> &mdash; whether FILENAME_COMPLETION_PROC matches hidden files and folders or not.</li>
</ul>
<p>I bet you didn&#8217;t know these methods were even in the Readline wrapper, did you? Probably because of lack of documentation.<br />
Anyhow, another very important difference beween Rawline and Readline is <code>Rawline.editor</code>, i.e. the default instance of RawLine::Editor used by the Rawline module itself.</p>
<p>This makes things easier if you want more control over the line which is being edited and the previously-edited lines. Sure, <code>Readline#completion_proc</code> exposes the current <em>word</em> being typed before hitting tab, and so does <code>Rawline#completion_proc</code> the difference is that if you access <code>Rawline.editor.line</code> you get a <code>RawLine::Line</code> object with all the information you could possibly need about the current line: the position of the cursor, the text, the order the characters were entered, etc. etc. <br />
Now you can imagine why it took me a few minutes to write the <code>filename_completion_proc</code> method (and why it will take you even less time to write your own similar method if you wanna do something different): you can access not only the last word being typed but also the current <em>and previous</em> lines (through <code>Rawline.editor.history</code> or just <code>Rawline::HISTORY</code>)!</p>
<p>It must be said, as usual, that Rawline is <em>not</em> a complete replacement for the Readline library yet (and it will probably never be, as Readline is huge!), but it&#8217;s a good cross-platform, more Ruby-esque alternative to what&#8217;s currently available by the Readline wrapper for Ruby.</p>
<p>It&#8217;s not as fast, of course, especially when completing long words, but it&#8217;s quite usable. The following libraries are not required but recommended:</p>
<ul>
	<li><code>win32console</code> (on Windows)</li>
	<li><code>termios</code> (on *nix)</li>
</ul>
<p>They basically make Rawline faster. If you don&#8217;t use them, Rawline will fall back on its pure-Ruby implementation to move left and right (i.e. printing backspaces and spaces character codes instead of <span class="caps">ASCII</span> escape codes).</p>
<p>Unfortunately, there&#8217;s no <code>vi_editing_mode</code> or <code>emacs_editing_mode</code> yet (for time constraints: they <em>can</em> be implemented!) but patches are very welcome. Also, if you need more features, all you have to do is ask :-)</p>
<p>P.S.: Check out the new <a href="/rawline">Project Page</a> and especially its Resources section!</p>]]>
    </content>
  </entry>
  <entry>
    <id>tag:www.h3rald.com,2008-04-01:/articles/rawline-020/</id>
    <title>New Release: RawLine 0.2.0</title>
    <published>2008-04-02T03:33:00Z</published>
    <updated>2009-09-06T18:10:53Z</updated>
    <link rel="alternate" href="http://www.h3rald.com/articles/rawline-020/"/>
    <category term="ruby" scheme="http://www.h3rald.com/tags/ruby/"/>
    <category term="programming" scheme="http://www.h3rald.com/tags/programming/"/>
    <category term="opensource" scheme="http://www.h3rald.com/tags/opensource/"/>
    <category term="rawline" scheme="http://www.h3rald.com/tags/rawline/"/>
    <content type="html">
<![CDATA[
<p><del>InLine</del> RawLine 0.2.0 is out!</p>
<p>*Raw*Line is the new name for InLine, in case you didn&#8217;t guess. The name was changed to avoid name collision problems with the RubyInline project.</p>
<p>Here&#8217;s what&#8217;s new:</p>
<ul>
	<li>Added /examples and /test directory to gem.</li>
	<li>Escape codes can now be used in prompt.</li>
	<li>It is now possible to use bind(key, &amp;block) with a String as key, even if the corresponding escape sequence is not defined.</li>
	<li>Added Editor#write_line(string) to print a any string (and &#8220;hit return&#8221;).</li>
	<li>Library name changed to &#8220;RawLine&#8221; to avoid name collision issues (Bug <a href="http://rubyforge.org/tracker/?func=detail&amp;aid=18879&amp;group_id=5622&amp;atid=21788">18879</a>).</li>
	<li>Provided alternative implementation for left and right arrows if terminal<br />
supports escape sequences (on Windows, it requires the Win32Console gem).</li>
</ul>
<p>In particular, I decided to provide an &#8220;optimized implementation&#8221; for the left and right arrows using escape sequences rather than shameful hacks. This is now possible because the Win32Console gem now enables <span class="caps">ANSI</span> escape sequences on Windows as well (weehee!).</p>
<p>So:</p>
<ul>
	<li>If you&#8217;re on *nix all good, your terminal is smart and can understand escape sequences =&gt; the new implementation will be used.</li>
	<li>If you&#8217;re on Windows and you installed Win32Console, your termnal is smart and can understand escape sequences =&gt; the new implementation will be used.</li>
	<li>If you&#8217;re on Windows and you didn&#8217;t install Win32Console, then your terminal is stupid and it doesn&#8217;t understand escape sequences, so the old implementation will be used.</li>
</ul>
<p>The new implementation is significantly faster than the old one, on Windows at least, and the cursor now blinks properly when left or right arrows are pressed.</p>
<p>I re-emplemented only cursor movement because I&#8217;m still having some problems in getting the delete/insert escapes to work properly (or better: how I want them to work!).</p>]]>
    </content>
  </entry>
  <entry>
    <id>tag:www.h3rald.com,2008-03-26:/articles/inline-name-change/</id>
    <title>InLine name change: what's your opinion?</title>
    <published>2008-03-27T05:30:00Z</published>
    <updated>2009-09-06T18:10:52Z</updated>
    <link rel="alternate" href="http://www.h3rald.com/articles/inline-name-change/"/>
    <category term="ruby" scheme="http://www.h3rald.com/tags/ruby/"/>
    <category term="programming" scheme="http://www.h3rald.com/tags/programming/"/>
    <category term="opensource" scheme="http://www.h3rald.com/tags/opensource/"/>
    <category term="rawline" scheme="http://www.h3rald.com/tags/rawline/"/>
    <content type="html">
<![CDATA[
<p>I&#8217;ve been kindly asked by the lead developer of <a href="http://www.zenspider.com/ZSS/Products/RubyInline/">RubyInLine</a> to change the name of my <a href="http://rubyforge.org/projects/inline/">InLine</a> project, due to potential confusion and conflicts.</p>
<p>This makes sense, and I&#8217;m ready to change the name of my project, although I&#8217;m not that good at choosing original and <em>smart</em> names, so well, any suggestion is more than welcome!</p>
<p>I was thinking of something like:</p>
<ul>
	<li>RawLine</li>
	<li>EditLine</li>
	<li>RawInput</li>
	<li>RubyInput</li>
	<li>RubyLine</li>
</ul>
<p>I personally think that <strong>RawLine</strong> is probably the best option, but please, if have any better idea just speak up!</p>
<p>P.S.: &#8220;RedLine&#8221; is taken, unfortunately, otherwise it would have been my first choice since the beginning.</p>]]>
    </content>
  </entry>
  <entry>
    <id>tag:www.h3rald.com,2008-03-09:/articles/inline-introduction/</id>
    <title>RawLine - a 100% Ruby solution for console inline editing</title>
    <published>2008-03-10T05:59:00Z</published>
    <updated>2009-09-06T18:10:51Z</updated>
    <link rel="alternate" href="http://www.h3rald.com/articles/inline-introduction/"/>
    <category term="ruby" scheme="http://www.h3rald.com/tags/ruby/"/>
    <category term="programming" scheme="http://www.h3rald.com/tags/programming/"/>
    <category term="opensource" scheme="http://www.h3rald.com/tags/opensource/"/>
    <category term="rawline" scheme="http://www.h3rald.com/tags/rawline/"/>
    <content type="html">
<![CDATA[
<p>One of the many things I like about Ruby is its cross-platform nature: as a general rule, Ruby code runs on everything which supports Ruby, regardless of its architecture and platform (yes, there are quite a few exceptions, but let&#8217;s accept this generalization for now).</p>
<p>More specifically, I liked the fact that I could use the <a href="http://tiswww.case.edu/php/chet/readline/rltop.html"><span class="caps">GNU</span> Readline library</a> with Ruby seamlessly on both Windows and Linux.<br />
Readline offers quite a lot of features which are useful for those people like me who enjoy creating command-line scripts, in a nutshell, it provides:</p>
<ul>
	<li>File/Word completion</li>
	<li>History support</li>
	<li>Custom key bindings which can be modified via .inputrc</li>
	<li>Emacs and Vi edit modes</li>
</ul>
<p>Basically it makes your command-line interface fast and powerful, and that&#8217;s not an overstatement. Ruby&#8217;s own <span class="caps">IRB</span> can be enhanced by enabling readline and completion, and it works great &#8212; at least on *nix systems.</p>
<p>For some weird reason, some people had problems with Readline on Windows: in particular, things get nasty when you start editing long lines. Text gets garbled, the cursor goes up one or two lines and doesn&#8217;t come back, and other similar leprechaun&#8217;s tricks, which are not that funny after a while.</p>
<p>Apparently there&#8217;s no alternative to Readline in the Ruby world. If you wan&#8217;t tab completion that&#8217;s it, you&#8217;re stuck. Would it be difficult to implement <em>some</em> of Readline functionality natively in Ruby? Maybe, but the problem is that for some reason the Ruby Standard Library doesn&#8217;t have low level methods to operate on keystrokes&#8230;</p>
<p>&#8230;but luckily, the <a href="http://highline.rubyforge.org/">HighLine</a> gem does! James Edward Gray II keeps pointing out here and here that HighLine&#8217;s own <code>get_character</code> method does just that: it returns the corresponding character code(s) right when a key is pressed, unlike <code>IO#gets()</code> which waits for the user to press <span class="caps">ENTER</span>.</p>
<p>Believe it or not, that tiny method can do wonders&#8230;h2. Reverse-engineering escape codes</p>
<p>So here&#8217;s a little script which uses <code>get_character()</code> in an endless loop, diligently printing the character codes corresponding to a keystroke:</p>
<div class="CodeRay">
  <div class="code"><pre><span class="line-numbers"> <a href="#n1" name="n1">1</a></span><span class="doctype">#!/usr/local/bin/ruby -w</span>
<span class="line-numbers"> <a href="#n2" name="n2">2</a></span>
<span class="line-numbers"> <a href="#n3" name="n3">3</a></span>require <span class="string"><span class="delimiter">'</span><span class="content">rubygems</span><span class="delimiter">'</span></span>
<span class="line-numbers"> <a href="#n4" name="n4">4</a></span>require <span class="string"><span class="delimiter">'</span><span class="content">highline/system_extensions</span><span class="delimiter">'</span></span>
<span class="line-numbers"> <a href="#n5" name="n5">5</a></span>
<span class="line-numbers"> <a href="#n6" name="n6">6</a></span>include <span class="constant">HighLine</span>::<span class="constant">SystemExtensions</span>
<span class="line-numbers"> <a href="#n7" name="n7">7</a></span>
<span class="line-numbers"> <a href="#n8" name="n8">8</a></span>puts <span class="string"><span class="delimiter">&quot;</span><span class="content">Press a key to view the corresponding ASCII code(s) (or CTRL-X to exit).</span><span class="delimiter">&quot;</span></span>
<span class="line-numbers"> <a href="#n9" name="n9">9</a></span>
<span class="line-numbers"><strong><a href="#n10" name="n10">10</a></strong></span>loop <span class="keyword">do</span>
<span class="line-numbers"><a href="#n11" name="n11">11</a></span>
<span class="line-numbers"><a href="#n12" name="n12">12</a></span>  print <span class="string"><span class="delimiter">&quot;</span><span class="content">=&gt; </span><span class="delimiter">&quot;</span></span>
<span class="line-numbers"><a href="#n13" name="n13">13</a></span>  char = get_character
<span class="line-numbers"><a href="#n14" name="n14">14</a></span>  <span class="keyword">case</span> char
<span class="line-numbers"><a href="#n15" name="n15">15</a></span>  <span class="keyword">when</span> <span class="integer">?\C-x</span>: print <span class="string"><span class="delimiter">&quot;</span><span class="content">Exiting...</span><span class="delimiter">&quot;</span></span>; exit;
<span class="line-numbers"><a href="#n16" name="n16">16</a></span>  <span class="keyword">else</span> puts <span class="string"><span class="delimiter">&quot;</span><span class="inline"><span class="inline-delimiter">#{</span>char.chr<span class="inline-delimiter">}</span></span><span class="content"> [</span><span class="inline"><span class="inline-delimiter">#{</span>char<span class="inline-delimiter">}</span></span><span class="content">] (hex: </span><span class="inline"><span class="inline-delimiter">#{</span>char.to_s(<span class="integer">16</span>)<span class="inline-delimiter">}</span></span><span class="content">)</span><span class="delimiter">&quot;</span></span>;
<span class="line-numbers"><a href="#n17" name="n17">17</a></span>  <span class="keyword">end</span>
<span class="line-numbers"><a href="#n18" name="n18">18</a></span>  
<span class="line-numbers"><a href="#n19" name="n19">19</a></span><span class="keyword">end</span>
</pre></div>
</div>

<p>A pretty harmless little thing. Try to run it and press some keys, and see what you get:</p>
<div style="font-family: Monospace">
<p>Press a key to view the corresponding <span class="caps">ASCII</span> code(s) (or <span class="caps">CTRL</span>-X to exit).</p>
<p>=&gt; a <sup class="footnote" id="fnr96"><a href="#fn96">96</a></sup> (hex: 61)</p>
<p>=&gt; 1 <sup class="footnote" id="fnr49"><a href="#fn49">49</a></sup> (hex: 31)</p>
<p>=&gt; Q <sup class="footnote" id="fnr81"><a href="#fn81">81</a></sup> (hex: 51)</p>
<p>=&gt; &alpha; <sup class="footnote" id="fnr224"><a href="#fn224">224</a></sup> (hex: e0)</p>
<p>=&gt; K <sup class="footnote" id="fnr75"><a href="#fn75">75</a></sup> (hex: 4b)</p>
</div>
<p>Hang on, what are the last two codes? <em>A left arrow key on Windows</em>, apparently.</p>
<p><strong>Welcome to the wonderful world of input escape sequences!</strong></p>
<p>To cut a long story short, both Windows and *nix system &#8220;terminals&#8221; translate special keystrokes into sequences of two or more codes. This applies to things like <span class="caps">DEL</span>, <span class="caps">INSERT</span>, arrows, etc. etc.<br />
For some ideas, check out:</p>
<ul>
	<li><a href="http://www.microsoft.com/whdc/device/input/Scancode.mspx">Windows Scancodes</a> (Thanks <a href="http://64.223.189.234/node/92">Huff</a>)</li>
	<li><a href="http://www.connectrf.com/Documents/vt220.html">VT220 Terminal Input Sequences</a> (Thanks <a href="http://www.grayproductions.net/">James</a>)</li>
</ul>
<p>Let&#8217;s now assume that we&#8217;re smart and we can write a program which can parse keystroke properly, including handling different input escape sequences according to the OS, what can it be used for?<br />
Well:</p>
<ul>
	<li>For normal characters, just print them back to the screen (<code>get_character</code> doesn&#8217;t print anything, it &#8220;steals&#8221; the keystroke)</li>
	<li>For special characters, do something nice!</li>
</ul>
<p>We could setup <span class="caps">TAB</span> to auto-complete the current word according to an array of matches, or bind the up arrow to load the last line typed in by the user, for example, that&#8217;s basically something Readline does, right?</p>
<h2>RawLine: how it works and what it does</h2>
<p>I created a small project on RubyForge called <a href="http://rubyforge.org/projects/rawline/">RawLine</a> (not to be confused with RubyInline, a completely different thing altogether, sorry about that) to play around with the possibilities offered by the <code>get_character</code> method. The library is just a preview of things which can be done, but it&#8217;s already usable, provided that you&#8217;re brave enough to try it out, that is.</p>
<p>The basic idea behind RawLine is to be able to parse keystrokes properly on different platforms and re-bind them to a set of predefined, cross-platform actions or a user-defined code block.</p>
<h3>Basic line-editing operations</h3>
<p>The first challenge was to re-invent the wheel, i.e. re-bind keystrokes to their typical actions: a left arrow moves the cursor left, a backspace deletes the character at the left of the cursor and so on. Yes, because <code>get_characters</code> gives you the right character codes at the price of <em>cancelling their normal effects</em>, which is a great thing, as you&#8217;ll soon find out.</p>
<p>Printing a character on the screen was one of the easiest tasks (at first). <code>IO#putc</code> does the job pretty well: it prints a character out.<br />
What about moving left? Easy: print a non-descructive backspace (\b) and hope it is really not destructive. I did some tests and it seems to do as it&#8217;s told and move the cursor back by one position.</p>
<p>Moving right was a little trickier: the easiest thing I found was to re-print the character under the cursor, which will then move the cursor forward (as naive as it may seem, it does the job!). If there&#8217;s nothing under the cursor, then we must be at the end of the line and it shouldn&#8217;t move anywhere, so there we go.</p>
<p>What if I move left a bit and then start typing normal characters? Well, everything is rewritten of course: this will be our &#8220;character replace mode&#8221;. Unfortunately users don&#8217;t like this behavior that much, so what I did was this:</p>
<ol>
	<li>Copy all characters from the one at the left of the cursor till the end of the line</li>
	<li>Print the character to be inserted</li>
	<li>Re-print the previously-copied characters</li>
	<li>Move the cursor back at the right place</li>
</ol>
<p>Again, a primitive solution which works seamlessly on all platforms, and yes, it&#8217;s fast enough that you don&#8217;t notice the difference.</p>
<p>As you may have guessed, this of course means that I always had to keep track of:</p>
<ul>
	<li>The cursor position within the line</li>
	<li>The text currently printed to the screen</li>
</ul>
<p>Backspace and delete were implemented in a similar way, you can figure it out yourself or look at the source code: I won&#8217;t bore you any further!</p>
<h3>History management</h3>
<p>The next step was to implement a history for both the characters inputted by the user (to allow undoing and redoing operations) and for the whole lines. This was just an ordinary programming exercise: a simple buffer with some extra controls here and there, nothing too scary.</p>
<p>So every &#8220;modification&#8221; to the current line being typed is saved in a line history buffer and all the lines entered are saved in another history buffer. All is left is to allow users to navigate through these buffers back and forth. <br />
Nothing impossible: all I had to do was keeping track of the current element of the history being retrieved and then overwrite the current line with a new line stored in the buffer? How&#8217;s this line overwriting done? Same old:</p>
<ol>
	<li>Move the cursor to the beginnig of the line</li>
	<li>Print X spaces, where X is the line length, so that the characters are no longer displayed in the console</li>
	<li>Move the cursor back to the beginning of the line</li>
	<li>Print the new line.</li>
</ol>
<p>Easy and naive, as usual. But again, it works well enough.</p>
<h3>Word completion</h3>
<p>The other challange was word completion. The current implementation can be summarized as follows:</p>
<ul>
	<li>If <span class="caps">TAB</span> (or another character, if you wish) is pressed, call a user-defined <code>completion_proc</code> method which returns an array and show the first element of the array (in this case I actually used a cyclic RawLine::HistoryBuffer, not an array)</li>
	<li>If the user presses <span class="caps">TAB</span> again, show another match, and so <em>ad infinitum</em> if the user keeps pressing <span class="caps">TAB</span>.</li>
	<li>If the user presses another key, accept the default completion and move on.</li>
</ul>
<p>Obviously this means that:</p>
<ul>
	<li>RawLine has to keep track of the current &#8220;word&#8221;. A word is everything separated by a user defined <code>word_separator</code>, which can obviously modified at runtime, with care.</li>
	<li>Regarding the <code>completion_proc</code>, typically you may want to return only the elements matching the word which is currently being written, so that&#8217;s given as default parameter for your proc. Exactly like with ReadLine, the only difference is that you can access other things like <em>the whole line</em> and <em>the whole history</em> in real time, which can be really handy at times!</li>
</ul>
<p>Here&#8217;s a simple example:</p>
<div class="CodeRay">
  <div class="code"><pre><span class="line-numbers"><a href="#n1" name="n1">1</a></span>editor.completion_proc = lambda <span class="keyword">do</span> |word|
<span class="line-numbers"><a href="#n2" name="n2">2</a></span>  <span class="keyword">if</span> word
<span class="line-numbers"><a href="#n3" name="n3">3</a></span>    [<span class="string"><span class="delimiter">'</span><span class="content">select</span><span class="delimiter">'</span></span>, <span class="string"><span class="delimiter">'</span><span class="content">update</span><span class="delimiter">'</span></span>, <span class="string"><span class="delimiter">'</span><span class="content">delete</span><span class="delimiter">'</span></span>, <span class="string"><span class="delimiter">'</span><span class="content">debug</span><span class="delimiter">'</span></span>, <span class="string"><span class="delimiter">'</span><span class="content">destroy</span><span class="delimiter">'</span></span>].find_all  { |e| e.match(<span class="regexp"><span class="delimiter">/</span><span class="content">^</span><span class="inline"><span class="inline-delimiter">#{</span><span class="constant">Regexp</span>.escape(word)<span class="inline-delimiter">}</span></span><span class="delimiter">/</span></span>) }
<span class="line-numbers"><a href="#n4" name="n4">4</a></span>  <span class="keyword">end</span>
<span class="line-numbers"><a href="#n5" name="n5">5</a></span><span class="keyword">end</span>
</pre></div>
</div>

<h3>Custom key bindings</h3>
<p>All these pretty things are obviously bound to some keystrokes. If the key corresponds to only one code, everything is fine, but because special keys typically aren&#8217;t so it was necessary to implement a mechanism to track an escape key (e.g. 0xE0 and 0 on Windows and \e on Linux) and listen to further characters, in case a known sequence is found. Anyhow, the final result of the method used for character binding is the following:</p>
<p><code>bind(key, &amp;block)</code></p>
<p>Where key can be:</p>
<ul>
	<li>A <code>Fixnum</code> corresponding to a single character code</li>
	<li>An <code>Array</code> of one or more character codes</li>
	<li>A <code>String</code> corresponding to an escape sequence</li>
	<li>A <code>Symbol</code> corresponding to a known escape sequence or key</li>
	<li>A <code>Hash</code> to define a new key or escape sequences</li>
</ul>
<p>So, in the end you can do things like this:</p>
<div class="CodeRay">
  <div class="code"><pre><span class="line-numbers"><a href="#n1" name="n1">1</a></span>editor.bind(<span class="symbol">:left_arrow</span>) { editor.move_left }
<span class="line-numbers"><a href="#n2" name="n2">2</a></span>editor.bind(<span class="string"><span class="delimiter">&quot;</span><span class="char">\e</span><span class="content">test</span><span class="delimiter">&quot;</span></span>) { editor.overwrite_line(<span class="string"><span class="delimiter">&quot;</span><span class="content">Test!!</span><span class="delimiter">&quot;</span></span>) }
<span class="line-numbers"><a href="#n3" name="n3">3</a></span>editor.bind(<span class="integer">?\C-z</span>) { editor.undo }
<span class="line-numbers"><a href="#n4" name="n4">4</a></span>editor.bind([<span class="integer">24</span>]) { exit }
</pre></div>
</div>

<p>Which, for Rubyists, it&#8217;s far sexier and more flexible than editing an .inputrc file.</p>
<h3>How do I use it, anyway?</h3>
<p>A code example is better than a thousand words, right? So here you are:</p>
<div class="CodeRay">
  <div class="code"><pre><span class="line-numbers"> <a href="#n1" name="n1">1</a></span><span class="doctype">#!/usr/local/bin/ruby -w</span>
<span class="line-numbers"> <a href="#n2" name="n2">2</a></span>
<span class="line-numbers"> <a href="#n3" name="n3">3</a></span>require <span class="string"><span class="delimiter">'</span><span class="content">rubygems</span><span class="delimiter">'</span></span>
<span class="line-numbers"> <a href="#n4" name="n4">4</a></span>require <span class="string"><span class="delimiter">'</span><span class="content">rawline</span><span class="delimiter">'</span></span>
<span class="line-numbers"> <a href="#n5" name="n5">5</a></span>
<span class="line-numbers"> <a href="#n6" name="n6">6</a></span>puts <span class="string"><span class="delimiter">&quot;</span><span class="content">*** Inline Editor Test Shell ***</span><span class="delimiter">&quot;</span></span>
<span class="line-numbers"> <a href="#n7" name="n7">7</a></span>puts <span class="string"><span class="delimiter">&quot;</span><span class="content"> * Press CTRL+X to exit</span><span class="delimiter">&quot;</span></span>
<span class="line-numbers"> <a href="#n8" name="n8">8</a></span>puts <span class="string"><span class="delimiter">&quot;</span><span class="content"> * Press CTRL+C to clear command history</span><span class="delimiter">&quot;</span></span>
<span class="line-numbers"> <a href="#n9" name="n9">9</a></span>puts <span class="string"><span class="delimiter">&quot;</span><span class="content"> * Press CTRL+D for line-related information</span><span class="delimiter">&quot;</span></span>
<span class="line-numbers"><strong><a href="#n10" name="n10">10</a></strong></span>puts <span class="string"><span class="delimiter">&quot;</span><span class="content"> * Press CTRL+E to view command history</span><span class="delimiter">&quot;</span></span>
<span class="line-numbers"><a href="#n11" name="n11">11</a></span>
<span class="line-numbers"><a href="#n12" name="n12">12</a></span>editor = <span class="constant">RawLine</span>::<span class="constant">Editor</span>.new
<span class="line-numbers"><a href="#n13" name="n13">13</a></span>
<span class="line-numbers"><a href="#n14" name="n14">14</a></span>editor.bind(<span class="symbol">:ctrl_c</span>) { editor.clear_history }
<span class="line-numbers"><a href="#n15" name="n15">15</a></span>editor.bind(<span class="symbol">:ctrl_d</span>) { editor.debug_line }
<span class="line-numbers"><a href="#n16" name="n16">16</a></span>editor.bind(<span class="symbol">:ctrl_e</span>) { editor.show_history }
<span class="line-numbers"><a href="#n17" name="n17">17</a></span>editor.bind(<span class="symbol">:ctrl_x</span>) { puts; puts <span class="string"><span class="delimiter">&quot;</span><span class="content">Exiting...</span><span class="delimiter">&quot;</span></span>; exit }
<span class="line-numbers"><a href="#n18" name="n18">18</a></span>
<span class="line-numbers"><a href="#n19" name="n19">19</a></span>editor.completion_proc = lambda <span class="keyword">do</span> |word|
<span class="line-numbers"><strong><a href="#n20" name="n20">20</a></strong></span>  <span class="keyword">if</span> word
<span class="line-numbers"><a href="#n21" name="n21">21</a></span>    [<span class="string"><span class="delimiter">'</span><span class="content">select</span><span class="delimiter">'</span></span>, <span class="string"><span class="delimiter">'</span><span class="content">update</span><span class="delimiter">'</span></span>, <span class="string"><span class="delimiter">'</span><span class="content">delete</span><span class="delimiter">'</span></span>, <span class="string"><span class="delimiter">'</span><span class="content">debug</span><span class="delimiter">'</span></span>, <span class="string"><span class="delimiter">'</span><span class="content">destroy</span><span class="delimiter">'</span></span>].find_all  { |e| e.match(<span class="regexp"><span class="delimiter">/</span><span class="content">^</span><span class="inline"><span class="inline-delimiter">#{</span><span class="constant">Regexp</span>.escape(word)<span class="inline-delimiter">}</span></span><span class="delimiter">/</span></span>) }
<span class="line-numbers"><a href="#n22" name="n22">22</a></span>  <span class="keyword">end</span>
<span class="line-numbers"><a href="#n23" name="n23">23</a></span><span class="keyword">end</span>
<span class="line-numbers"><a href="#n24" name="n24">24</a></span>
<span class="line-numbers"><a href="#n25" name="n25">25</a></span>loop <span class="keyword">do</span>
<span class="line-numbers"><a href="#n26" name="n26">26</a></span>  puts <span class="string"><span class="delimiter">&quot;</span><span class="content">You typed: [</span><span class="inline"><span class="inline-delimiter">#{</span>editor.read(<span class="string"><span class="delimiter">&quot;</span><span class="content">=&gt; </span><span class="delimiter">&quot;</span></span>).chomp!<span class="inline-delimiter">}</span></span><span class="content">]</span><span class="delimiter">&quot;</span></span>
<span class="line-numbers"><a href="#n27" name="n27">27</a></span><span class="keyword">end</span>
</pre></div>
</div>

<p>This example can be found in examples/rawline_shell.rb within the RawLine source code or gem package.</p>
<h2>Current status and availability</h2>
<p>I currently <a href="http://rubyforge.org/forum/forum.php?forum_id=22543">released</a> RawLine 0.1.0 on <a href="http://rubyforge.org/projects/rawline">SourceForge</a>, and it can be installed via:</p>
<p><code>gem install -r rawline</code></p>
<p>The RDoc documentation is available <a href="http://rawline.rubyforge.org/">here</a>.</p>
<p>Feel free to try it out. First of all try the <code>rawline_shell.rb</code> example, and see if it works on your machine. If it doesn&#8217;t than maybe you try re-binding some keys (use <code>key_tester.rb</code> to &#8220;reverse-engineer&#8221; your terminal&#8217;s input escape sequences), and let me know!</p>
<p>Status information and limitations:</p>
<ul>
	<li>It has been tested on Windows (XP, using the usual command prompt) and on Linux (ZenWalk, using <span class="caps">XFCE</span> Terminal).</li>
	<li>It can handle lines no longer than the maximum terminal width &#8211; 2. This is to ensure that the cursor never &#8220;falls down&#8221; to the next line.</li>
	<li>On Windows, the cursor doesn&#8217;t blink immedialy when moving left, but it moves, don&#8217;t worry.</li>
	<li>On Linux, you should really consider installing the <a href="http://raa.ruby-lang.org/project/ruby-termios/">Termios</a> library for a faster experience (otherwise <code>get_character</code> won&#8217;t parse characters correctly if you press and hold a key, and that, trust me, is a real mess!).</li>
	<li>RawLine is very far from being a complete replacement for the ReadLine library, and it is currently in alpha stage.</li>
	<li>Release 0.1.0 has been created after 2 weeks of sporadic coding during lunch breaks and week-ends.</li>
</ul>
<p>For any ideas on where to go from here, comments and feedback, just reply below or send an email to my usual email address.</p>]]>
    </content>
  </entry>
</feed>

