all repos — h3rald @ 764957a4dced82d3d132f113fcbd68f9dff5995f

The sources of https://h3rald.com

contents/rawline.html

 1
 2
 3
 4
 5
 6
 7
 8
 9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
-----
title: "RawLine"
content-type: project
subtitle: "A pure-ruby alternative to ReadLine"
github: rawline
status: On Hold
version: 0.3.2
-----
<nav class="project-links">
<p><a href="http://rawline.rubyforge.org"><span class="caps">DOCUMENTATION</span></a> | <a href="http://rubyforge.org/projects/rawline"><span class="caps">DOWNLOAD</span></a> | <a href="http://github.com/h3rald/rawline/tree/master"><span class="caps">SOURCE</span></a> | <a href="http://h3rald.lighthouseapp.com/projects/26374-rawline/overview"><span class="caps">TRACKING</span></a></p>
</nav>
<ul class="project-data">
	<li>Project Status: <strong>On Hold</strong></li>
	<li>Version: <strong>0.3.2</strong></li>
</ul>
<p>RawLine is a 100% Ruby alternative to the ReadLine library, providing some of its most popular features such as:</p>
<ul>
	<li>Basic line editing operations</li>
	<li>Word completion</li>
	<li>History Management</li>
	<li>Custom key/key sequences bindings</li>
</ul>
<h3>Installation</h3>
<p>The simplest method to install RawLine is to install the gem:</p>
<div class='text'><pre><code>gem install rawline</code></pre></div><h3>Usage</h3>
<p>Editor initialization:</p>
<div class='ruby'><pre><code>require 'rawline'
editor = RawLine::Editor.new</code></pre></div><p>Key binding:</p>
<div class='ruby'><pre><code>editor.bind(:ctrl_z) { editor.undo }
editor.bind(:up_arrow) { editor.history_back }
editor.bind(:ctrl_x) { puts "Exiting..."; exit }</code></pre></div><p>Setup word completion</p>
<div class='ruby'><pre><code>editor.completion_proc = lambda do |word|
	if word
		['select', 'update', 'delete', 'debug', 'destroy'].find_all  { |e| e.match(/^#{Regexp.escape(word)}/) }
	end
end

editor.completion_append_string = " "</code></pre></div><p>Read input:</p>
<div class='ruby'><pre><code>editor.read("=&gt; ", true)</code></pre></div><h3>Replacing Readline</h3>
<p>Simply include the RawLine (or Rawline) module:</p>
<div class='ruby'><pre><code>include Rawline</code></pre></div><p>…and you’ll get:</p>
<div class='ruby'><pre><code>readline(prompt, add_history) # RawLine::Editor#read(prompt, add_history)
HISTORY # RawLine::Editor#history
FILENAME_COMPLETION_PROC # Rawline::Editor#filename_completion_proc
# ...</code></pre></div><p>but also:</p>
<div class='ruby'><pre><code>Rawline.editor # RawLine::Editor</code></pre></div><p>&#8230;which opens a world of endless possibilities! ;-)</p>
<h3>Latest Updates</h3>
<ul><li><a href="/articles/real-world-rawline-usage/">Real-world Rawline usage</a> &mdash; <time class="timeago" datetime="2009-03-07T03:54:00Z">Saturday, 07 March 2009</time></li>
<li><a href="/articles/rawline-030/">RawLine 0.3.0 released — now with Readline emulation</a> &mdash; <time class="timeago" datetime="2009-03-01T06:47:00Z">Sunday, 01 March 2009</time></li>
<li><a href="/articles/rawline-020/">New Release: RawLine 0.2.0</a> &mdash; <time class="timeago" datetime="2008-04-02T03:33:00Z">Wednesday, 02 April 2008</time></li>
<li><a href="/articles/inline-name-change/">InLine name change: what&#8217;s your opinion?</a> &mdash; <time class="timeago" datetime="2008-03-27T05:30:00Z">Thursday, 27 March 2008</time></li>
<li><a href="/articles/inline-introduction/">RawLine &#8211; a 100% Ruby solution for console inline editing</a> &mdash; <time class="timeago" datetime="2008-03-10T05:59:00Z">Monday, 10 March 2008</time></li>
</ul>