File: C:/Ruby27-x64/share/doc/ruby/html/Readline.html
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>module Readline - RDoc Documentation</title>
<script type="text/javascript">
var rdoc_rel_prefix = "./";
var index_rel_prefix = "./";
</script>
<script src="./js/navigation.js" defer></script>
<script src="./js/search.js" defer></script>
<script src="./js/search_index.js" defer></script>
<script src="./js/searcher.js" defer></script>
<script src="./js/darkfish.js" defer></script>
<link href="./css/fonts.css" rel="stylesheet">
<link href="./css/rdoc.css" rel="stylesheet">
<body id="top" role="document" class="module">
<nav role="navigation">
<div id="project-navigation">
<div id="home-section" role="region" title="Quick navigation" class="nav-section">
<h2>
<a href="./index.html" rel="home">Home</a>
</h2>
<div id="table-of-contents-navigation">
<a href="./table_of_contents.html#pages">Pages</a>
<a href="./table_of_contents.html#classes">Classes</a>
<a href="./table_of_contents.html#methods">Methods</a>
</div>
</div>
<div id="search-section" role="search" class="project-section initially-hidden">
<form action="#" method="get" accept-charset="utf-8">
<div id="search-field-wrapper">
<input id="search-field" role="combobox" aria-label="Search"
aria-autocomplete="list" aria-controls="search-results"
type="text" name="search" placeholder="Search" spellcheck="false"
title="Type to search, Up and Down to navigate, Enter to load">
</div>
<ul id="search-results" aria-label="Search Results"
aria-busy="false" aria-expanded="false"
aria-atomic="false" class="initially-hidden"></ul>
</form>
</div>
</div>
<div id="class-metadata">
<!-- Method Quickref -->
<div id="method-list-section" class="nav-section">
<h3>Methods</h3>
<ul class="link-list" role="directory">
<li ><a href="#method-c-basic_quote_characters">::basic_quote_characters</a>
<li ><a href="#method-c-basic_quote_characters-3D">::basic_quote_characters=</a>
<li ><a href="#method-c-basic_word_break_characters">::basic_word_break_characters</a>
<li ><a href="#method-c-basic_word_break_characters-3D">::basic_word_break_characters=</a>
<li ><a href="#method-c-completer_quote_characters">::completer_quote_characters</a>
<li ><a href="#method-c-completer_quote_characters-3D">::completer_quote_characters=</a>
<li ><a href="#method-c-completer_word_break_characters">::completer_word_break_characters</a>
<li ><a href="#method-c-completer_word_break_characters-3D">::completer_word_break_characters=</a>
<li ><a href="#method-c-completion_append_character">::completion_append_character</a>
<li ><a href="#method-c-completion_append_character-3D">::completion_append_character=</a>
<li ><a href="#method-c-completion_case_fold">::completion_case_fold</a>
<li ><a href="#method-c-completion_case_fold-3D">::completion_case_fold=</a>
<li ><a href="#method-c-completion_proc">::completion_proc</a>
<li ><a href="#method-c-completion_proc-3D">::completion_proc=</a>
<li ><a href="#method-c-completion_quote_character">::completion_quote_character</a>
<li ><a href="#method-c-delete_text">::delete_text</a>
<li ><a href="#method-c-emacs_editing_mode">::emacs_editing_mode</a>
<li ><a href="#method-c-emacs_editing_mode-3F">::emacs_editing_mode?</a>
<li ><a href="#method-c-filename_quote_characters">::filename_quote_characters</a>
<li ><a href="#method-c-filename_quote_characters-3D">::filename_quote_characters=</a>
<li ><a href="#method-c-get_screen_size">::get_screen_size</a>
<li ><a href="#method-c-input-3D">::input=</a>
<li ><a href="#method-c-insert_text">::insert_text</a>
<li ><a href="#method-c-line_buffer">::line_buffer</a>
<li ><a href="#method-c-output-3D">::output=</a>
<li ><a href="#method-c-point">::point</a>
<li ><a href="#method-c-point-3D">::point=</a>
<li ><a href="#method-c-pre_input_hook">::pre_input_hook</a>
<li ><a href="#method-c-pre_input_hook-3D">::pre_input_hook=</a>
<li ><a href="#method-c-quoting_detection_proc">::quoting_detection_proc</a>
<li ><a href="#method-c-quoting_detection_proc-3D">::quoting_detection_proc=</a>
<li ><a href="#method-c-readline">::readline</a>
<li ><a href="#method-c-redisplay">::redisplay</a>
<li ><a href="#method-c-refresh_line">::refresh_line</a>
<li ><a href="#method-c-set_screen_size">::set_screen_size</a>
<li ><a href="#method-c-special_prefixes">::special_prefixes</a>
<li ><a href="#method-c-special_prefixes-3D">::special_prefixes=</a>
<li ><a href="#method-c-vi_editing_mode">::vi_editing_mode</a>
<li ><a href="#method-c-vi_editing_mode-3F">::vi_editing_mode?</a>
</ul>
</div>
</div>
</nav>
<main role="main" aria-labelledby="module-Readline">
<h1 id="module-Readline" class="module">
module Readline
</h1>
<section class="description">
<p>The <a href="Readline.html"><code>Readline</code></a> module provides interface for GNU <a href="Readline.html"><code>Readline</code></a>. This module defines a number of methods to facilitate completion and accesses input history from the Ruby interpreter. This module supported Edit Line(libedit) too. libedit is compatible with GNU <a href="Readline.html"><code>Readline</code></a>.</p>
<dl class="rdoc-list note-list"><dt>GNU <a href="Readline.html"><code>Readline</code></a>
<dd>
<p><a href="http://www.gnu.org/directory/readline.html">www.gnu.org/directory/readline.html</a></p>
</dd><dt>libedit
<dd>
<p><a href="http://www.thrysoee.dk/editline">www.thrysoee.dk/editline</a>/</p>
</dd></dl>
<p>Reads one inputted line with line edit by <a href="Readline.html#method-c-readline"><code>Readline.readline</code></a> method. At this time, the facilitatation completion and the key bind like Emacs can be operated like GNU <a href="Readline.html"><code>Readline</code></a>.</p>
<pre class="ruby"><span class="ruby-identifier">require</span> <span class="ruby-string">"readline"</span>
<span class="ruby-keyword">while</span> <span class="ruby-identifier">buf</span> = <span class="ruby-constant">Readline</span>.<span class="ruby-identifier">readline</span>(<span class="ruby-string">"> "</span>, <span class="ruby-keyword">true</span>)
<span class="ruby-identifier">p</span> <span class="ruby-identifier">buf</span>
<span class="ruby-keyword">end</span>
</pre>
<p>The content that the user input can be recorded to the history. The history can be accessed by <a href="Readline.html#HISTORY"><code>Readline::HISTORY</code></a> constant.</p>
<pre class="ruby"><span class="ruby-identifier">require</span> <span class="ruby-string">"readline"</span>
<span class="ruby-keyword">while</span> <span class="ruby-identifier">buf</span> = <span class="ruby-constant">Readline</span>.<span class="ruby-identifier">readline</span>(<span class="ruby-string">"> "</span>, <span class="ruby-keyword">true</span>)
<span class="ruby-identifier">p</span> <span class="ruby-constant">Readline</span><span class="ruby-operator">::</span><span class="ruby-constant">HISTORY</span>.<span class="ruby-identifier">to_a</span>
<span class="ruby-identifier">print</span>(<span class="ruby-string">"-> "</span>, <span class="ruby-identifier">buf</span>, <span class="ruby-string">"\n"</span>)
<span class="ruby-keyword">end</span>
</pre>
<p>Documented by Kouji Takao <kouji dot takao at gmail dot com>.</p>
</section>
<section id="5Buntitled-5D" class="documentation-section">
<section class="constants-list">
<header>
<h3>Constants</h3>
</header>
<dl>
<dt id="FILENAME_COMPLETION_PROC">FILENAME_COMPLETION_PROC
<dd><p>The <a href="Object.html"><code>Object</code></a> with the call method that is a completion for filename. This is sets by <a href="Readline.html#method-c-completion_proc-3D"><code>Readline.completion_proc=</code></a> method.</p>
<dt id="HISTORY">HISTORY
<dd><p>The history buffer. It extends <a href="Enumerable.html"><code>Enumerable</code></a> module, so it behaves just like an array. For example, gets the fifth content that the user input by <a href="4">HISTORY</a>.</p>
<dt id="USERNAME_COMPLETION_PROC">USERNAME_COMPLETION_PROC
<dd><p>The <a href="Object.html"><code>Object</code></a> with the call method that is a completion for usernames. This is sets by <a href="Readline.html#method-c-completion_proc-3D"><code>Readline.completion_proc=</code></a> method.</p>
<dt id="VERSION">VERSION
<dd><p>Version string of GNU <a href="Readline.html"><code>Readline</code></a> or libedit.</p>
</dl>
</section>
<section id="public-class-5Buntitled-5D-method-details" class="method-section">
<header>
<h3>Public Class Methods</h3>
</header>
<div id="method-c-basic_quote_characters" class="method-detail ">
<div class="method-heading">
<span class="method-callseq">
basic_quote_characters → string
</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<p>Gets a list of quote characters which can cause a word break.</p>
<p>Raises <a href="NotImplementedError.html"><code>NotImplementedError</code></a> if the using readline library does not support.</p>
<div class="method-source-code" id="basic_quote_characters-source">
<pre>static VALUE
readline_s_get_basic_quote_characters(VALUE self)
{
if (rl_basic_quote_characters == NULL)
return Qnil;
return rb_locale_str_new_cstr(rl_basic_quote_characters);
}</pre>
</div>
</div>
</div>
<div id="method-c-basic_quote_characters-3D" class="method-detail ">
<div class="method-heading">
<span class="method-callseq">
basic_quote_characters = string
</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<p>Sets a list of quote characters which can cause a word break.</p>
<p>Raises <a href="NotImplementedError.html"><code>NotImplementedError</code></a> if the using readline library does not support.</p>
<div class="method-source-code" id="basic_quote_characters-3D-source">
<pre>static VALUE
readline_s_set_basic_quote_characters(VALUE self, VALUE str)
{
static char *basic_quote_characters = NULL;
OutputStringValue(str);
if (basic_quote_characters == NULL) {
basic_quote_characters =
ALLOC_N(char, RSTRING_LEN(str) + 1);
}
else {
REALLOC_N(basic_quote_characters, char, RSTRING_LEN(str) + 1);
}
strncpy(basic_quote_characters,
RSTRING_PTR(str), RSTRING_LEN(str));
basic_quote_characters[RSTRING_LEN(str)] = '\0';
rl_basic_quote_characters = basic_quote_characters;
return self;
}</pre>
</div>
</div>
</div>
<div id="method-c-basic_word_break_characters" class="method-detail ">
<div class="method-heading">
<span class="method-callseq">
basic_word_break_characters → string
</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<p>Gets the basic list of characters that signal a break between words for the completer routine.</p>
<p>Raises <a href="NotImplementedError.html"><code>NotImplementedError</code></a> if the using readline library does not support.</p>
<div class="method-source-code" id="basic_word_break_characters-source">
<pre>static VALUE
readline_s_get_basic_word_break_characters(VALUE self)
{
if (rl_basic_word_break_characters == NULL)
return Qnil;
return rb_locale_str_new_cstr(rl_basic_word_break_characters);
}</pre>
</div>
</div>
</div>
<div id="method-c-basic_word_break_characters-3D" class="method-detail ">
<div class="method-heading">
<span class="method-callseq">
basic_word_break_characters = string
</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<p>Sets the basic list of characters that signal a break between words for the completer routine. The default is the characters which break words for completion in Bash: “ tn"\'`@$><=;|&{(”.</p>
<p>Raises <a href="NotImplementedError.html"><code>NotImplementedError</code></a> if the using readline library does not support.</p>
<div class="method-source-code" id="basic_word_break_characters-3D-source">
<pre>static VALUE
readline_s_set_basic_word_break_characters(VALUE self, VALUE str)
{
static char *basic_word_break_characters = NULL;
OutputStringValue(str);
if (basic_word_break_characters == NULL) {
basic_word_break_characters =
ALLOC_N(char, RSTRING_LEN(str) + 1);
}
else {
REALLOC_N(basic_word_break_characters, char, RSTRING_LEN(str) + 1);
}
strncpy(basic_word_break_characters,
RSTRING_PTR(str), RSTRING_LEN(str));
basic_word_break_characters[RSTRING_LEN(str)] = '\0';
rl_basic_word_break_characters = basic_word_break_characters;
return self;
}</pre>
</div>
</div>
</div>
<div id="method-c-completer_quote_characters" class="method-detail ">
<div class="method-heading">
<span class="method-callseq">
completer_quote_characters → string
</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<p>Gets a list of characters which can be used to quote a substring of the line.</p>
<p>Raises <a href="NotImplementedError.html"><code>NotImplementedError</code></a> if the using readline library does not support.</p>
<div class="method-source-code" id="completer_quote_characters-source">
<pre>static VALUE
readline_s_get_completer_quote_characters(VALUE self)
{
if (rl_completer_quote_characters == NULL)
return Qnil;
return rb_locale_str_new_cstr(rl_completer_quote_characters);
}</pre>
</div>
</div>
</div>
<div id="method-c-completer_quote_characters-3D" class="method-detail ">
<div class="method-heading">
<span class="method-callseq">
completer_quote_characters = string
</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<p>Sets a list of characters which can be used to quote a substring of the line. Completion occurs on the entire substring, and within the substring <a href="Readline.html#method-c-completer_word_break_characters"><code>Readline.completer_word_break_characters</code></a> are treated as any other character, unless they also appear within this list.</p>
<p>Raises <a href="NotImplementedError.html"><code>NotImplementedError</code></a> if the using readline library does not support.</p>
<div class="method-source-code" id="completer_quote_characters-3D-source">
<pre>static VALUE
readline_s_set_completer_quote_characters(VALUE self, VALUE str)
{
static char *completer_quote_characters = NULL;
OutputStringValue(str);
if (completer_quote_characters == NULL) {
completer_quote_characters =
ALLOC_N(char, RSTRING_LEN(str) + 1);
}
else {
REALLOC_N(completer_quote_characters, char, RSTRING_LEN(str) + 1);
}
strncpy(completer_quote_characters, RSTRING_PTR(str), RSTRING_LEN(str));
completer_quote_characters[RSTRING_LEN(str)] = '\0';
rl_completer_quote_characters = completer_quote_characters;
return self;
}</pre>
</div>
</div>
</div>
<div id="method-c-completer_word_break_characters" class="method-detail ">
<div class="method-heading">
<span class="method-callseq">
completer_word_break_characters → string
</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<p>Gets the basic list of characters that signal a break between words for rl_complete_internal().</p>
<p>Raises <a href="NotImplementedError.html"><code>NotImplementedError</code></a> if the using readline library does not support.</p>
<div class="method-source-code" id="completer_word_break_characters-source">
<pre>static VALUE
readline_s_get_completer_word_break_characters(VALUE self)
{
if (rl_completer_word_break_characters == NULL)
return Qnil;
return rb_locale_str_new_cstr(rl_completer_word_break_characters);
}</pre>
</div>
</div>
</div>
<div id="method-c-completer_word_break_characters-3D" class="method-detail ">
<div class="method-heading">
<span class="method-callseq">
completer_word_break_characters = string
</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<p>Sets the basic list of characters that signal a break between words for rl_complete_internal(). The default is the value of <a href="Readline.html#method-c-basic_word_break_characters"><code>Readline.basic_word_break_characters</code></a>.</p>
<p>Raises <a href="NotImplementedError.html"><code>NotImplementedError</code></a> if the using readline library does not support.</p>
<div class="method-source-code" id="completer_word_break_characters-3D-source">
<pre>static VALUE
readline_s_set_completer_word_break_characters(VALUE self, VALUE str)
{
static char *completer_word_break_characters = NULL;
OutputStringValue(str);
if (completer_word_break_characters == NULL) {
completer_word_break_characters =
ALLOC_N(char, RSTRING_LEN(str) + 1);
}
else {
REALLOC_N(completer_word_break_characters, char, RSTRING_LEN(str) + 1);
}
strncpy(completer_word_break_characters,
RSTRING_PTR(str), RSTRING_LEN(str));
completer_word_break_characters[RSTRING_LEN(str)] = '\0';
rl_completer_word_break_characters = completer_word_break_characters;
return self;
}</pre>
</div>
</div>
</div>
<div id="method-c-completion_append_character" class="method-detail ">
<div class="method-heading">
<span class="method-callseq">
completion_append_character → char
</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<p>Returns a string containing a character to be appended on completion. The default is a space (“ ”).</p>
<p>Raises <a href="NotImplementedError.html"><code>NotImplementedError</code></a> if the using readline library does not support.</p>
<div class="method-source-code" id="completion_append_character-source">
<pre>static VALUE
readline_s_get_completion_append_character(VALUE self)
{
char buf[1];
if (rl_completion_append_character == '\0')
return Qnil;
buf[0] = (char) rl_completion_append_character;
return rb_locale_str_new(buf, 1);
}</pre>
</div>
</div>
</div>
<div id="method-c-completion_append_character-3D" class="method-detail ">
<div class="method-heading">
<span class="method-callseq">
completion_append_character = char
</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<p>Specifies a character to be appended on completion. Nothing will be appended if an empty string (“”) or nil is specified.</p>
<p>For example:</p>
<pre class="ruby"><span class="ruby-identifier">require</span> <span class="ruby-string">"readline"</span>
<span class="ruby-constant">Readline</span>.<span class="ruby-identifier">readline</span>(<span class="ruby-string">"> "</span>, <span class="ruby-keyword">true</span>)
<span class="ruby-constant">Readline</span>.<span class="ruby-identifier">completion_append_character</span> = <span class="ruby-string">" "</span>
</pre>
<p>Result:</p>
<pre>>
Input "/var/li".
> /var/li
Press TAB key.
> /var/lib
Completes "b" and appends " ". So, you can continuously input "/usr".
> /var/lib /usr</pre>
<p>NOTE: Only one character can be specified. When “string” is specified, sets only “s” that is the first.</p>
<pre class="ruby"><span class="ruby-identifier">require</span> <span class="ruby-string">"readline"</span>
<span class="ruby-constant">Readline</span>.<span class="ruby-identifier">completion_append_character</span> = <span class="ruby-string">"string"</span>
<span class="ruby-identifier">p</span> <span class="ruby-constant">Readline</span>.<span class="ruby-identifier">completion_append_character</span> <span class="ruby-comment"># => "s"</span>
</pre>
<p>Raises <a href="NotImplementedError.html"><code>NotImplementedError</code></a> if the using readline library does not support.</p>
<div class="method-source-code" id="completion_append_character-3D-source">
<pre>static VALUE
readline_s_set_completion_append_character(VALUE self, VALUE str)
{
if (NIL_P(str)) {
rl_completion_append_character = '\0';
}
else {
OutputStringValue(str);
if (RSTRING_LEN(str) == 0) {
rl_completion_append_character = '\0';
} else {
rl_completion_append_character = RSTRING_PTR(str)[0];
}
}
return self;
}</pre>
</div>
</div>
</div>
<div id="method-c-completion_case_fold" class="method-detail ">
<div class="method-heading">
<span class="method-callseq">
completion_case_fold → bool
</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<p>Returns true if completion ignores case. If no, returns false.</p>
<p>NOTE: Returns the same object that is specified by <a href="Readline.html#method-c-completion_case_fold-3D"><code>Readline.completion_case_fold=</code></a> method.</p>
<pre class="ruby"><span class="ruby-identifier">require</span> <span class="ruby-string">"readline"</span>
<span class="ruby-constant">Readline</span>.<span class="ruby-identifier">completion_case_fold</span> = <span class="ruby-string">"This is a String."</span>
<span class="ruby-identifier">p</span> <span class="ruby-constant">Readline</span>.<span class="ruby-identifier">completion_case_fold</span> <span class="ruby-comment"># => "This is a String."</span>
</pre>
<div class="method-source-code" id="completion_case_fold-source">
<pre>static VALUE
readline_s_get_completion_case_fold(VALUE self)
{
return rb_attr_get(mReadline, completion_case_fold);
}</pre>
</div>
</div>
</div>
<div id="method-c-completion_case_fold-3D" class="method-detail ">
<div class="method-heading">
<span class="method-callseq">
completion_case_fold = bool
</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<p>Sets whether or not to ignore case on completion.</p>
<div class="method-source-code" id="completion_case_fold-3D-source">
<pre>static VALUE
readline_s_set_completion_case_fold(VALUE self, VALUE val)
{
return rb_ivar_set(mReadline, completion_case_fold, val);
}</pre>
</div>
</div>
</div>
<div id="method-c-completion_proc" class="method-detail ">
<div class="method-heading">
<span class="method-callseq">
completion_proc → proc
</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<p>Returns the completion <a href="Proc.html"><code>Proc</code></a> object.</p>
<div class="method-source-code" id="completion_proc-source">
<pre>static VALUE
readline_s_get_completion_proc(VALUE self)
{
return rb_attr_get(mReadline, completion_proc);
}</pre>
</div>
</div>
</div>
<div id="method-c-completion_proc-3D" class="method-detail ">
<div class="method-heading">
<span class="method-callseq">
completion_proc = proc
</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<p>Specifies a <a href="Proc.html"><code>Proc</code></a> object <code>proc</code> to determine completion behavior. It should take input string and return an array of completion candidates.</p>
<p>The default completion is used if <code>proc</code> is nil.</p>
<p>The <a href="String.html"><code>String</code></a> that is passed to the <a href="Proc.html"><code>Proc</code></a> depends on the <a href="Readline.html#method-c-completer_word_break_characters"><code>Readline.completer_word_break_characters</code></a> property. By default the word under the cursor is passed to the <a href="Proc.html"><code>Proc</code></a>. For example, if the input is “foo bar” then only “bar” would be passed to the completion <a href="Proc.html"><code>Proc</code></a>.</p>
<p>Upon successful completion the <a href="Readline.html#method-c-completion_append_character"><code>Readline.completion_append_character</code></a> will be appended to the input so the user can start working on their next argument.</p>
<h1 id="method-c-completion_proc-3D-label-Examples">Examples<span><a href="#method-c-completion_proc-3D-label-Examples">¶</a> <a href="#top">↑</a></span></h1>
<h2 id="method-c-completion_proc-3D-label-Completion+for+a+Static+List">Completion for a Static List<span><a href="#method-c-completion_proc-3D-label-Completion+for+a+Static+List">¶</a> <a href="#top">↑</a></span></h2>
<pre class="ruby"><span class="ruby-identifier">require</span> <span class="ruby-string">'readline'</span>
<span class="ruby-constant">LIST</span> = [
<span class="ruby-string">'search'</span>, <span class="ruby-string">'download'</span>, <span class="ruby-string">'open'</span>,
<span class="ruby-string">'help'</span>, <span class="ruby-string">'history'</span>, <span class="ruby-string">'quit'</span>,
<span class="ruby-string">'url'</span>, <span class="ruby-string">'next'</span>, <span class="ruby-string">'clear'</span>,
<span class="ruby-string">'prev'</span>, <span class="ruby-string">'past'</span>
].<span class="ruby-identifier">sort</span>
<span class="ruby-identifier">comp</span> = <span class="ruby-identifier">proc</span> { <span class="ruby-operator">|</span><span class="ruby-identifier">s</span><span class="ruby-operator">|</span> <span class="ruby-constant">LIST</span>.<span class="ruby-identifier">grep</span>(<span class="ruby-regexp">/^#{Regexp.escape(s)}/</span>) }
<span class="ruby-constant">Readline</span>.<span class="ruby-identifier">completion_append_character</span> = <span class="ruby-string">" "</span>
<span class="ruby-constant">Readline</span>.<span class="ruby-identifier">completion_proc</span> = <span class="ruby-identifier">comp</span>
<span class="ruby-keyword">while</span> <span class="ruby-identifier">line</span> = <span class="ruby-constant">Readline</span>.<span class="ruby-identifier">readline</span>(<span class="ruby-string">'> '</span>, <span class="ruby-keyword">true</span>)
<span class="ruby-identifier">p</span> <span class="ruby-identifier">line</span>
<span class="ruby-keyword">end</span>
</pre>
<h2 id="method-c-completion_proc-3D-label-Completion+For+Directory+Contents">Completion For Directory Contents<span><a href="#method-c-completion_proc-3D-label-Completion+For+Directory+Contents">¶</a> <a href="#top">↑</a></span></h2>
<pre class="ruby"><span class="ruby-identifier">require</span> <span class="ruby-string">'readline'</span>
<span class="ruby-constant">Readline</span>.<span class="ruby-identifier">completion_append_character</span> = <span class="ruby-string">" "</span>
<span class="ruby-constant">Readline</span>.<span class="ruby-identifier">completion_proc</span> = <span class="ruby-constant">Proc</span>.<span class="ruby-identifier">new</span> <span class="ruby-keyword">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">str</span><span class="ruby-operator">|</span>
<span class="ruby-constant">Dir</span>[<span class="ruby-identifier">str</span><span class="ruby-string">+'*'</span>].<span class="ruby-identifier">grep</span>(<span class="ruby-regexp">/^#{Regexp.escape(str)}/</span>)
<span class="ruby-keyword">end</span>
<span class="ruby-keyword">while</span> <span class="ruby-identifier">line</span> = <span class="ruby-constant">Readline</span>.<span class="ruby-identifier">readline</span>(<span class="ruby-string">'> '</span>, <span class="ruby-keyword">true</span>)
<span class="ruby-identifier">p</span> <span class="ruby-identifier">line</span>
<span class="ruby-keyword">end</span>
</pre>
<h1 id="method-c-completion_proc-3D-label-Autocomplete+strategies">Autocomplete strategies<span><a href="#method-c-completion_proc-3D-label-Autocomplete+strategies">¶</a> <a href="#top">↑</a></span></h1>
<p>When working with auto-complete there are some strategies that work well. To get some ideas you can take a look at the <a href="https://git.ruby-lang.org/ruby.git/tree/lib/irb/completion.rb">completion.rb</a> file for irb.</p>
<p>The common strategy is to take a list of possible completions and filter it down to those completions that start with the user input. In the above examples <a href="Enumerable.html#method-i-grep"><code>Enumerator.grep</code></a> is used. The input is escaped to prevent <a href="Regexp.html"><code>Regexp</code></a> special characters from interfering with the matching.</p>
<p>It may also be helpful to use the <a href="Abbrev.html"><code>Abbrev</code></a> library to generate completions.</p>
<p>Raises <a href="ArgumentError.html"><code>ArgumentError</code></a> if <code>proc</code> does not respond to the call method.</p>
<div class="method-source-code" id="completion_proc-3D-source">
<pre>static VALUE
readline_s_set_completion_proc(VALUE self, VALUE proc)
{
mustbe_callable(proc);
return rb_ivar_set(mReadline, completion_proc, proc);
}</pre>
</div>
</div>
</div>
<div id="method-c-completion_quote_character" class="method-detail ">
<div class="method-heading">
<span class="method-callseq">
completion_quote_character → char
</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<p>When called during a completion (e.g. from within your <a href="Readline.html#method-c-completion_proc"><code>completion_proc</code></a>), it will return a string containing the character used to quote the argument being completed, or nil if the argument is unquoted.</p>
<p>When called at other times, it will always return nil.</p>
<p>Note that <a href="Readline.html#method-c-completer_quote_characters"><code>Readline.completer_quote_characters</code></a> must be set, or this method will always return nil.</p>
<div class="method-source-code" id="completion_quote_character-source">
<pre>static VALUE
readline_s_get_completion_quote_character(VALUE self)
{
char buf[1];
if (rl_completion_quote_character == '\0')
return Qnil;
buf[0] = (char) rl_completion_quote_character;
return rb_locale_str_new(buf, 1);
}</pre>
</div>
</div>
</div>
<div id="method-c-delete_text" class="method-detail ">
<div class="method-heading">
<span class="method-callseq">
delete_text([start[, length]]) → self
</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-heading">
<span class="method-callseq">
delete_text(start..end) → self
</span>
</div>
<div class="method-heading">
<span class="method-callseq">
delete_text() → self
</span>
</div>
<div class="method-description">
<p>Delete text between start and end in the current line.</p>
<p>See GNU Readline's rl_delete_text function.</p>
<p>Raises <a href="NotImplementedError.html"><code>NotImplementedError</code></a> if the using readline library does not support.</p>
<div class="method-source-code" id="delete_text-source">
<pre>static VALUE
readline_s_delete_text(int argc, VALUE *argv, VALUE self)
{
rb_check_arity(argc, 0, 2);
if (rl_line_buffer) {
const char *p, *ptr = rl_line_buffer;
long beg = 0, len = strlen(ptr);
const char *end = ptr + len;
rb_encoding *enc = rb_locale_encoding();
if (argc == 2) {
beg = NUM2LONG(argv[0]);
len = NUM2LONG(argv[1]);
num_pos:
p = str_subpos(ptr, end, beg, &len, enc);
if (!p) rb_raise(rb_eArgError, "invalid index");
beg = p - ptr;
}
else if (argc == 1) {
len = rb_enc_strlen(ptr, ptr + len, enc);
if (!rb_range_beg_len(argv[0], &beg, &len, len, 1)) {
beg = NUM2LONG(argv[0]);
goto num_pos;
}
}
rl_delete_text(rb_long2int(beg), rb_long2int(beg + len));
}
return self;
}</pre>
</div>
</div>
</div>
<div id="method-c-emacs_editing_mode" class="method-detail ">
<div class="method-heading">
<span class="method-callseq">
emacs_editing_mode → nil
</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<p>Specifies Emacs editing mode. The default is this mode. See the manual of GNU <a href="Readline.html"><code>Readline</code></a> for details of Emacs editing mode.</p>
<p>Raises <a href="NotImplementedError.html"><code>NotImplementedError</code></a> if the using readline library does not support.</p>
<div class="method-source-code" id="emacs_editing_mode-source">
<pre>static VALUE
readline_s_emacs_editing_mode(VALUE self)
{
rl_emacs_editing_mode(1,0);
return Qnil;
}</pre>
</div>
</div>
</div>
<div id="method-c-emacs_editing_mode-3F" class="method-detail ">
<div class="method-heading">
<span class="method-callseq">
emacs_editing_mode? → bool
</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<p>Returns true if emacs mode is active. Returns false if not.</p>
<p>Raises <a href="NotImplementedError.html"><code>NotImplementedError</code></a> if the using readline library does not support.</p>
<div class="method-source-code" id="emacs_editing_mode-3F-source">
<pre>static VALUE
readline_s_emacs_editing_mode_p(VALUE self)
{
return rl_editing_mode == 1 ? Qtrue : Qfalse;
}</pre>
</div>
</div>
</div>
<div id="method-c-filename_quote_characters" class="method-detail ">
<div class="method-heading">
<span class="method-callseq">
filename_quote_characters → string
</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<p>Gets a list of characters that cause a filename to be quoted by the completer when they appear in a completed filename.</p>
<p>Raises <a href="NotImplementedError.html"><code>NotImplementedError</code></a> if the using readline library does not support.</p>
<div class="method-source-code" id="filename_quote_characters-source">
<pre>static VALUE
readline_s_get_filename_quote_characters(VALUE self)
{
if (rl_filename_quote_characters == NULL)
return Qnil;
return rb_locale_str_new_cstr(rl_filename_quote_characters);
}</pre>
</div>
</div>
</div>
<div id="method-c-filename_quote_characters-3D" class="method-detail ">
<div class="method-heading">
<span class="method-callseq">
filename_quote_characters = string
</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<p>Sets a list of characters that cause a filename to be quoted by the completer when they appear in a completed filename. The default is nil.</p>
<p>Raises <a href="NotImplementedError.html"><code>NotImplementedError</code></a> if the using readline library does not support.</p>
<div class="method-source-code" id="filename_quote_characters-3D-source">
<pre>static VALUE
readline_s_set_filename_quote_characters(VALUE self, VALUE str)
{
static char *filename_quote_characters = NULL;
OutputStringValue(str);
if (filename_quote_characters == NULL) {
filename_quote_characters =
ALLOC_N(char, RSTRING_LEN(str) + 1);
}
else {
REALLOC_N(filename_quote_characters, char, RSTRING_LEN(str) + 1);
}
strncpy(filename_quote_characters, RSTRING_PTR(str), RSTRING_LEN(str));
filename_quote_characters[RSTRING_LEN(str)] = '\0';
rl_filename_quote_characters = filename_quote_characters;
return self;
}</pre>
</div>
</div>
</div>
<div id="method-c-get_screen_size" class="method-detail ">
<div class="method-heading">
<span class="method-callseq">
get_screen_size → [rows, columns]
</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<p>Returns the terminal's rows and columns.</p>
<p>See GNU Readline's rl_get_screen_size function.</p>
<p>Raises <a href="NotImplementedError.html"><code>NotImplementedError</code></a> if the using readline library does not support.</p>
<div class="method-source-code" id="get_screen_size-source">
<pre>static VALUE
readline_s_get_screen_size(VALUE self)
{
int rows, columns;
VALUE res;
rl_get_screen_size(&rows, &columns);
res = rb_ary_new();
rb_ary_push(res, INT2NUM(rows));
rb_ary_push(res, INT2NUM(columns));
return res;
}</pre>
</div>
</div>
</div>
<div id="method-c-input-3D" class="method-detail ">
<div class="method-heading">
<span class="method-callseq">
input = input
</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<p>Specifies a <a href="File.html"><code>File</code></a> object <code>input</code> that is input stream for <a href="Readline.html#method-c-readline"><code>Readline.readline</code></a> method.</p>
<div class="method-source-code" id="input-3D-source">
<pre>static VALUE
readline_s_set_input(VALUE self, VALUE input)
{
rb_io_t *ifp;
int fd;
FILE *f;
if (NIL_P(input)) {
clear_rl_instream();
}
else {
Check_Type(input, T_FILE);
GetOpenFile(input, ifp);
clear_rl_instream();
fd = rb_cloexec_dup(ifp->fd);
if (fd == -1)
rb_sys_fail("dup");
f = fdopen(fd, "r");
if (f == NULL) {
int save_errno = errno;
close(fd);
rb_syserr_fail(save_errno, "fdopen");
}
rl_instream = readline_rl_instream = f;
readline_instream = input;
}
return input;
}</pre>
</div>
</div>
</div>
<div id="method-c-insert_text" class="method-detail ">
<div class="method-heading">
<span class="method-callseq">
insert_text(string) → self
</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<p>Insert text into the line at the current cursor position.</p>
<p>See GNU Readline's rl_insert_text function.</p>
<p>Raises <a href="NotImplementedError.html"><code>NotImplementedError</code></a> if the using readline library does not support.</p>
<div class="method-source-code" id="insert_text-source">
<pre>static VALUE
readline_s_insert_text(VALUE self, VALUE str)
{
OutputStringValue(str);
rl_insert_text(RSTRING_PTR(str));
return self;
}</pre>
</div>
</div>
</div>
<div id="method-c-line_buffer" class="method-detail ">
<div class="method-heading">
<span class="method-callseq">
line_buffer → string
</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<p>Returns the full line that is being edited. This is useful from within the complete_proc for determining the context of the completion request.</p>
<p>The length of <code>Readline.line_buffer</code> and GNU Readline's rl_end are same.</p>
<p>Raises <a href="NotImplementedError.html"><code>NotImplementedError</code></a> if the using readline library does not support.</p>
<div class="method-source-code" id="line_buffer-source">
<pre>static VALUE
readline_s_get_line_buffer(VALUE self)
{
if (rl_line_buffer == NULL)
return Qnil;
return rb_locale_str_new_cstr(rl_line_buffer);
}</pre>
</div>
</div>
</div>
<div id="method-c-output-3D" class="method-detail ">
<div class="method-heading">
<span class="method-callseq">
output = output
</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<p>Specifies a <a href="File.html"><code>File</code></a> object <code>output</code> that is output stream for <a href="Readline.html#method-c-readline"><code>Readline.readline</code></a> method.</p>
<div class="method-source-code" id="output-3D-source">
<pre>static VALUE
readline_s_set_output(VALUE self, VALUE output)
{
rb_io_t *ofp;
int fd;
FILE *f;
if (NIL_P(output)) {
clear_rl_outstream();
}
else {
Check_Type(output, T_FILE);
GetOpenFile(output, ofp);
clear_rl_outstream();
fd = rb_cloexec_dup(ofp->fd);
if (fd == -1)
rb_sys_fail("dup");
f = fdopen(fd, "w");
if (f == NULL) {
int save_errno = errno;
close(fd);
rb_syserr_fail(save_errno, "fdopen");
}
rl_outstream = readline_rl_outstream = f;
readline_outstream = output;
}
return output;
}</pre>
</div>
</div>
</div>
<div id="method-c-point" class="method-detail ">
<div class="method-heading">
<span class="method-callseq">
point → int
</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<p>Returns the index of the current cursor position in <code>Readline.line_buffer</code>.</p>
<p>The index in <code>Readline.line_buffer</code> which matches the start of input-string passed to <a href="Readline.html#method-c-completion_proc"><code>completion_proc</code></a> is computed by subtracting the length of input-string from <code>Readline.point</code>.</p>
<pre class="ruby"><span class="ruby-identifier">start</span> = (<span class="ruby-identifier">the</span> <span class="ruby-identifier">length</span> <span class="ruby-identifier">of</span> <span class="ruby-identifier">input</span><span class="ruby-operator">-</span><span class="ruby-identifier">string</span>) <span class="ruby-operator">-</span> <span class="ruby-constant">Readline</span>.<span class="ruby-identifier">point</span>
</pre>
<p>Raises <a href="NotImplementedError.html"><code>NotImplementedError</code></a> if the using readline library does not support.</p>
<div class="method-source-code" id="point-source">
<pre>static VALUE
readline_s_get_point(VALUE self)
{
return INT2NUM(rl_point);
}</pre>
</div>
</div>
</div>
<div id="method-c-point-3D" class="method-detail ">
<div class="method-heading">
<span class="method-callseq">
point = int
</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<p><a href="Set.html"><code>Set</code></a> the index of the current cursor position in <code>Readline.line_buffer</code>.</p>
<p>Raises <a href="NotImplementedError.html"><code>NotImplementedError</code></a> if the using readline library does not support.</p>
<p>See <code>Readline.point</code>.</p>
<div class="method-source-code" id="point-3D-source">
<pre>static VALUE
readline_s_set_point(VALUE self, VALUE pos)
{
rl_point = NUM2INT(pos);
return pos;
}</pre>
</div>
</div>
</div>
<div id="method-c-pre_input_hook" class="method-detail ">
<div class="method-heading">
<span class="method-callseq">
pre_input_hook → proc
</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<p>Returns a <a href="Proc.html"><code>Proc</code></a> object <code>proc</code> to call after the first prompt has been printed and just before readline starts reading input characters. The default is nil.</p>
<p>Raises <a href="NotImplementedError.html"><code>NotImplementedError</code></a> if the using readline library does not support.</p>
<div class="method-source-code" id="pre_input_hook-source">
<pre>static VALUE
readline_s_get_pre_input_hook(VALUE self)
{
return rb_attr_get(mReadline, id_pre_input_hook);
}</pre>
</div>
</div>
</div>
<div id="method-c-pre_input_hook-3D" class="method-detail ">
<div class="method-heading">
<span class="method-callseq">
pre_input_hook = proc
</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<p>Specifies a <a href="Proc.html"><code>Proc</code></a> object <code>proc</code> to call after the first prompt has been printed and just before readline starts reading input characters.</p>
<p>See GNU Readline's rl_pre_input_hook variable.</p>
<p>Raises <a href="ArgumentError.html"><code>ArgumentError</code></a> if <code>proc</code> does not respond to the call method.</p>
<p>Raises <a href="NotImplementedError.html"><code>NotImplementedError</code></a> if the using readline library does not support.</p>
<div class="method-source-code" id="pre_input_hook-3D-source">
<pre>static VALUE
readline_s_set_pre_input_hook(VALUE self, VALUE proc)
{
mustbe_callable(proc);
return rb_ivar_set(mReadline, id_pre_input_hook, proc);
}</pre>
</div>
</div>
</div>
<div id="method-c-quoting_detection_proc" class="method-detail ">
<div class="method-heading">
<span class="method-callseq">
quoting_detection_proc → proc
</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<p>Returns the quoting detection <a href="Proc.html"><code>Proc</code></a> object.</p>
<div class="method-source-code" id="quoting_detection_proc-source">
<pre>static VALUE
readline_s_get_quoting_detection_proc(VALUE self)
{
return rb_attr_get(mReadline, quoting_detection_proc);
}</pre>
</div>
</div>
</div>
<div id="method-c-quoting_detection_proc-3D" class="method-detail ">
<div class="method-heading">
<span class="method-callseq">
quoting_detection_proc = proc
</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<p>Specifies a <a href="Proc.html"><code>Proc</code></a> object <code>proc</code> to determine if a character in the user's input is escaped. It should take the user's input and the index of the character in question as input, and return a boolean (true if the specified character is escaped).</p>
<p><a href="Readline.html"><code>Readline</code></a> will only call this proc with characters specified in <code>completer_quote_characters</code>, to discover if they indicate the end of a quoted argument, or characters specified in <code>completer_word_break_characters</code>, to discover if they indicate a break between arguments.</p>
<p>If <code>completer_quote_characters</code> is not set, or if the user input doesn't contain one of the <code>completer_quote_characters</code> or a ++ character, <a href="Readline.html"><code>Readline</code></a> will not attempt to use this proc at all.</p>
<p>Raises <a href="ArgumentError.html"><code>ArgumentError</code></a> if <code>proc</code> does not respond to the call method.</p>
<div class="method-source-code" id="quoting_detection_proc-3D-source">
<pre>static VALUE
readline_s_set_quoting_detection_proc(VALUE self, VALUE proc)
{
mustbe_callable(proc);
return rb_ivar_set(mReadline, quoting_detection_proc, proc);
}</pre>
</div>
</div>
</div>
<div id="method-c-readline" class="method-detail ">
<div class="method-heading">
<span class="method-callseq">
readline(prompt = "", add_hist = false) → string or nil
</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<p>Shows the <code>prompt</code> and reads the inputted line with line editing. The inputted line is added to the history if <code>add_hist</code> is true.</p>
<p>Returns nil when the inputted line is empty and user inputs EOF (Presses ^D on UNIX).</p>
<p>Raises <a href="IOError.html"><code>IOError</code></a> exception if one of below conditions are satisfied.</p>
<ol><li>
<p>stdin was closed.</p>
</li><li>
<p>stdout was closed.</p>
</li></ol>
<p>This method supports thread. Switches the thread context when waits inputting line.</p>
<p>Supports line edit when inputs line. Provides VI and Emacs editing mode. Default is Emacs editing mode.</p>
<p>NOTE: Terminates ruby interpreter and does not return the terminal status after user pressed '^C' when wait inputting line. Give 3 examples that avoid it.</p>
<ul><li>
<p>Catches the <a href="Interrupt.html"><code>Interrupt</code></a> exception by pressed ^C after returns terminal status:</p>
<pre>require "readline"
stty_save = `stty -g`.chomp
begin
while buf = Readline.readline
p buf
end
rescue Interrupt
system("stty", stty_save)
exit
end
end
end</pre>
</li><li>
<p>Catches the INT signal by pressed ^C after returns terminal status:</p>
<pre class="ruby"><span class="ruby-identifier">require</span> <span class="ruby-string">"readline"</span>
<span class="ruby-identifier">stty_save</span> = <span class="ruby-string">`stty -g`</span>.<span class="ruby-identifier">chomp</span>
<span class="ruby-identifier">trap</span>(<span class="ruby-string">"INT"</span>) { <span class="ruby-identifier">system</span> <span class="ruby-string">"stty"</span>, <span class="ruby-identifier">stty_save</span>; <span class="ruby-identifier">exit</span> }
<span class="ruby-keyword">while</span> <span class="ruby-identifier">buf</span> = <span class="ruby-constant">Readline</span>.<span class="ruby-identifier">readline</span>
<span class="ruby-identifier">p</span> <span class="ruby-identifier">buf</span>
<span class="ruby-keyword">end</span>
</pre>
</li><li>
<p>Ignores pressing ^C:</p>
<pre class="ruby"><span class="ruby-identifier">require</span> <span class="ruby-string">"readline"</span>
<span class="ruby-identifier">trap</span>(<span class="ruby-string">"INT"</span>, <span class="ruby-string">"SIG_IGN"</span>)
<span class="ruby-keyword">while</span> <span class="ruby-identifier">buf</span> = <span class="ruby-constant">Readline</span>.<span class="ruby-identifier">readline</span>
<span class="ruby-identifier">p</span> <span class="ruby-identifier">buf</span>
<span class="ruby-keyword">end</span>
</pre>
</li></ul>
<p>Can make as follows with <a href="Readline.html#HISTORY"><code>Readline::HISTORY</code></a> constant. It does not record to the history if the inputted line is empty or the same it as last one.</p>
<pre class="ruby"><span class="ruby-identifier">require</span> <span class="ruby-string">"readline"</span>
<span class="ruby-keyword">while</span> <span class="ruby-identifier">buf</span> = <span class="ruby-constant">Readline</span>.<span class="ruby-identifier">readline</span>(<span class="ruby-string">"> "</span>, <span class="ruby-keyword">true</span>)
<span class="ruby-comment"># p Readline::HISTORY.to_a</span>
<span class="ruby-constant">Readline</span><span class="ruby-operator">::</span><span class="ruby-constant">HISTORY</span>.<span class="ruby-identifier">pop</span> <span class="ruby-keyword">if</span> <span class="ruby-regexp">/^\s*$/</span> <span class="ruby-operator">=~</span> <span class="ruby-identifier">buf</span>
<span class="ruby-keyword">begin</span>
<span class="ruby-keyword">if</span> <span class="ruby-constant">Readline</span><span class="ruby-operator">::</span><span class="ruby-constant">HISTORY</span>[<span class="ruby-constant">Readline</span><span class="ruby-operator">::</span><span class="ruby-constant">HISTORY</span>.<span class="ruby-identifier">length</span><span class="ruby-value">-2</span>] <span class="ruby-operator">==</span> <span class="ruby-identifier">buf</span>
<span class="ruby-constant">Readline</span><span class="ruby-operator">::</span><span class="ruby-constant">HISTORY</span>.<span class="ruby-identifier">pop</span>
<span class="ruby-keyword">end</span>
<span class="ruby-keyword">rescue</span> <span class="ruby-constant">IndexError</span>
<span class="ruby-keyword">end</span>
<span class="ruby-comment"># p Readline::HISTORY.to_a</span>
<span class="ruby-identifier">print</span> <span class="ruby-string">"-> "</span>, <span class="ruby-identifier">buf</span>, <span class="ruby-string">"\n"</span>
<span class="ruby-keyword">end</span>
</pre>
<div class="method-source-code" id="readline-source">
<pre>static VALUE
readline_readline(int argc, VALUE *argv, VALUE self)
{
VALUE tmp, add_hist, result;
char *prompt = NULL;
char *buff;
int status;
if (rb_scan_args(argc, argv, "02", &tmp, &add_hist) > 0) {
OutputStringValue(tmp);
#if USE_INSERT_IGNORE_ESCAPE
tmp = insert_ignore_escape(self, tmp);
rb_str_locktmp(tmp);
#endif
prompt = RSTRING_PTR(tmp);
}
prepare_readline();
#ifdef _WIN32
rl_prep_terminal(1);
#endif
buff = (char*)rb_protect(readline_get, (VALUE)prompt, &status);
#if USE_INSERT_IGNORE_ESCAPE
if (prompt) {
rb_str_unlocktmp(tmp);
}
#endif
if (status) {
#if defined HAVE_RL_CLEANUP_AFTER_SIGNAL
/* restore terminal mode and signal handler*/
#if defined HAVE_RL_FREE_LINE_STATE
rl_free_line_state();
#endif
rl_cleanup_after_signal();
#elif defined HAVE_RL_DEPREP_TERM_FUNCTION
/* restore terminal mode */
if (rl_deprep_term_function != NULL) /* NULL in libedit. [ruby-dev:29116] */
(*rl_deprep_term_function)();
else
#else
rl_deprep_terminal();
#endif
rb_jump_tag(status);
}
if (RTEST(add_hist) && buff) {
add_history(buff);
}
if (buff) {
result = rb_locale_str_new_cstr(buff);
}
else
result = Qnil;
if (buff) free(buff);
return result;
}</pre>
</div>
</div>
</div>
<div id="method-c-redisplay" class="method-detail ">
<div class="method-heading">
<span class="method-callseq">
redisplay → self
</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<p>Change what's displayed on the screen to reflect the current contents.</p>
<p>See GNU Readline's rl_redisplay function.</p>
<p>Raises <a href="NotImplementedError.html"><code>NotImplementedError</code></a> if the using readline library does not support.</p>
<div class="method-source-code" id="redisplay-source">
<pre>static VALUE
readline_s_redisplay(VALUE self)
{
rl_redisplay();
return self;
}</pre>
</div>
</div>
</div>
<div id="method-c-refresh_line" class="method-detail ">
<div class="method-heading">
<span class="method-callseq">
refresh_line → nil
</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<p>Clear the current input line.</p>
<div class="method-source-code" id="refresh_line-source">
<pre>static VALUE
readline_s_refresh_line(VALUE self)
{
prepare_readline();
rl_refresh_line(0, 0);
return Qnil;
}</pre>
</div>
</div>
</div>
<div id="method-c-set_screen_size" class="method-detail ">
<div class="method-heading">
<span class="method-callseq">
set_screen_size(rows, columns) → self
</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<p><a href="Set.html"><code>Set</code></a> terminal size to <code>rows</code> and <code>columns</code>.</p>
<p>See GNU Readline's rl_set_screen_size function.</p>
<p>Raises <a href="NotImplementedError.html"><code>NotImplementedError</code></a> if the using readline library does not support.</p>
<div class="method-source-code" id="set_screen_size-source">
<pre>static VALUE
readline_s_set_screen_size(VALUE self, VALUE rows, VALUE columns)
{
rl_set_screen_size(NUM2INT(rows), NUM2INT(columns));
return self;
}</pre>
</div>
</div>
</div>
<div id="method-c-special_prefixes" class="method-detail ">
<div class="method-heading">
<span class="method-callseq">
special_prefixes → string
</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<p>Gets the list of characters that are word break characters, but should be left in text when it is passed to the completion function.</p>
<p>See GNU Readline's rl_special_prefixes variable.</p>
<p>Raises <a href="NotImplementedError.html"><code>NotImplementedError</code></a> if the using readline library does not support.</p>
<div class="method-source-code" id="special_prefixes-source">
<pre>static VALUE
readline_s_get_special_prefixes(VALUE self)
{
VALUE str;
if (rl_special_prefixes == NULL) return Qnil;
str = rb_ivar_get(mReadline, id_special_prefixes);
if (!NIL_P(str)) {
str = rb_str_dup_frozen(str);
rb_obj_reveal(str, rb_cString);
}
return str;
}</pre>
</div>
</div>
</div>
<div id="method-c-special_prefixes-3D" class="method-detail ">
<div class="method-heading">
<span class="method-callseq">
special_prefixes = string
</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<p>Sets the list of characters that are word break characters, but should be left in text when it is passed to the completion function. Programs can use this to help determine what kind of completing to do. For instance, Bash sets this variable to “$@” so that it can complete shell variables and hostnames.</p>
<p>See GNU Readline's rl_special_prefixes variable.</p>
<p>Raises <a href="NotImplementedError.html"><code>NotImplementedError</code></a> if the using readline library does not support.</p>
<div class="method-source-code" id="special_prefixes-3D-source">
<pre>static VALUE
readline_s_set_special_prefixes(VALUE self, VALUE str)
{
if (!NIL_P(str)) {
OutputStringValue(str);
str = rb_str_dup_frozen(str);
rb_obj_hide(str);
}
rb_ivar_set(mReadline, id_special_prefixes, str);
if (NIL_P(str)) {
rl_special_prefixes = NULL;
}
else {
rl_special_prefixes = RSTRING_PTR(str);
}
return self;
}</pre>
</div>
</div>
</div>
<div id="method-c-vi_editing_mode" class="method-detail ">
<div class="method-heading">
<span class="method-callseq">
vi_editing_mode → nil
</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<p>Specifies VI editing mode. See the manual of GNU <a href="Readline.html"><code>Readline</code></a> for details of VI editing mode.</p>
<p>Raises <a href="NotImplementedError.html"><code>NotImplementedError</code></a> if the using readline library does not support.</p>
<div class="method-source-code" id="vi_editing_mode-source">
<pre>static VALUE
readline_s_vi_editing_mode(VALUE self)
{
rl_vi_editing_mode(1,0);
return Qnil;
}</pre>
</div>
</div>
</div>
<div id="method-c-vi_editing_mode-3F" class="method-detail ">
<div class="method-heading">
<span class="method-callseq">
vi_editing_mode? → bool
</span>
<span class="method-click-advice">click to toggle source</span>
</div>
<div class="method-description">
<p>Returns true if vi mode is active. Returns false if not.</p>
<p>Raises <a href="NotImplementedError.html"><code>NotImplementedError</code></a> if the using readline library does not support.</p>
<div class="method-source-code" id="vi_editing_mode-3F-source">
<pre>static VALUE
readline_s_vi_editing_mode_p(VALUE self)
{
return rl_editing_mode == 0 ? Qtrue : Qfalse;
}</pre>
</div>
</div>
</div>
</section>
</section>
</main>
<footer id="validator-badges" role="contentinfo">
<p><a href="https://validator.w3.org/check/referer">Validate</a>
<p>Generated by <a href="https://ruby.github.io/rdoc/">RDoc</a> 6.2.1.1.
<p>Based on <a href="http://deveiate.org/projects/Darkfish-RDoc/">Darkfish</a> by <a href="http://deveiate.org">Michael Granger</a>.
</footer>