GithubHelp home page GithubHelp logo

rb-readline's Introduction

Description

The readline library provides a pure Ruby implementation of the GNU readline C library, as well as the Readline extension that ships as part of the standard library.

Installation

gem install rb-readline

Or in a Gemfile:

gem 'rb-readline'

Synopsis

require 'readline'

loop do
  line = Readline::readline('> ')
  break if line.nil? || line == 'quit'
  Readline::HISTORY.push(line)
  puts "You typed: #{line}"
end

Compatibility

rb-readline should work on all Unix-like systems and Windows. It is regularly used with MRI 1.8/1.9 and Rubinius. JRuby is not supported and there are no plans to support it in the future - it comes bundled with a Java implementation of Readline.

Motivation

First, building the GNU readline library on MS Windows with Visual C++ is almost impossible. However, certain libraries depend on readline. By providing a pure Ruby version we eliminate the entire compiler compatibility issue.

Second, even on distributions of Windows built with MinGW (that include the readline library for Windows), the behavior was sometimes erratic and would break.

Third, even on certain Unix distributions the GNU readline library is not guaranteed to be installed. Providing a pure Ruby readline eliminates the need to install a C library first. It's also one less link in the dependency chain, meaning we don't need to worry about possible changes in the underlying C library affecting our interface.

Fourth, by making the interface pure Ruby, we increase the likelihood of receiving patches, feature requests, documentation updates, etc from the community at large, since not everyone knows C.

Lastly, the Readline interface that ships as part of the standard library is weak, and only provides a very limited subset of the actual GNU readline library. By providing a pure Ruby implementation we allow 3rd party library authors to write their own interface as they see fit.

Tutorial

For an excellent tutorial on how to use Readline in practice, please see Joseph Pecoraro's examples at http://bogojoker.com/readline/.

You can also take a look at Ruby 1.9 stdlib Readline documentation located at http://rubydoc.info/stdlib/readline/1.9.2/frames

Alternatives

See Rawline for a library that began life in pure Ruby and provides an interface that's probably more comfortable to Ruby programmer. It has certain features that Readline does not. In addition, it provides a Readline compatibility mode.

Authors

  • Park Heesob (C translation, code donated as part of bounty)
  • Daniel Berger (Documentation and testing)
  • Luis Lavena
  • Mark Somerville (Maintainer)
  • Connor Atherton (Maintainer)

rb-readline's People

Contributors

adamleff avatar ahmadsherif avatar camdez avatar connoratherton avatar davelnewton avatar dulao5 avatar endoze avatar graywolf avatar jeffwilliams avatar johnnyshields avatar keram avatar larskanis avatar lowjoel avatar luislavena avatar njvack avatar noig3 avatar phasis68 avatar rctay avatar rdp avatar rocky avatar rosenfeld avatar shirosaki avatar spakman avatar willdeed avatar wwboynton avatar yui-knk avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

rb-readline's Issues

Scrolling through history breaks display with long lines

When scrolling through the history, if we encounter a line that is longer than the terminal width the next (shorter) line in the history will cause a display problem. Often this is that the prompt disappears, but sometimes the entire line is blank.

Resizing the terminal window when in this broken state causes a redisplay which is correct.

Testing of rb-readline (especially on Windows)

rb-readline does not currently have a comprehensive test suite. This is to be expected since it was a direct port from GNU Readline 5.2. Fortunately, it seems that many contributions to rb-readline are also coming in with some tests attached.

I believe this project was created primarily as a method of getting IRB to work reliably under Windows and other platforms where GNU Readline support may be dubious. However (and fortunately), it is also proving useful in cases where the standard Readline binding that Ruby provides is not complete enough.

I have no experience of developing on Windows, but I do want to contribute more to this project and am willing to learn for that purpose.

I have a Windows XP VM installed for testing and always test my changes there using the RubyInstaller project (1.8.7 and 1.9.2, currently). I run rake test then "Start a command prompt with Ruby 1.X", check that my changes seem OK in IRB before creating a patch.

Is there anything else I should be doing?

How do you Windows developers use Ruby on Windows? Specifically, how do you use rb-readline/IRB on Windows?

IndexError line 1775 of rbreadline.rb

The following code causes an IndexError in rbreadline.rb:

require 'readline'
Readline::readline("a\nb\nc\n", true)

This fails under both Linux and Windows with ruby 1.8.6. The test passes with the readline.so binary.

Remove use of @ibuffer_len

Ruby strings are dynamically allocated. We can clean up the code by removing @ibuffer_len and associated checks.

Some prompts cause failure on 1.9

The simplest example is:

iota ~ % ruby -r rbreadline -e 'p RbReadline.readline(" > ")'     
/home/manveru/github/luislavena/rb-readline/lib/rbreadline.rb:8456:in `_rl_find_next_mbchar': undefined method `force_encoding' for nil:NilClass (NoMethodError)
  from /home/manveru/github/luislavena/rb-readline/lib/rbreadline.rb:1694:in `block in expand_prompt'
  from /home/manveru/github/luislavena/rb-readline/lib/rbreadline.rb:1678:in `each'
  from /home/manveru/github/luislavena/rb-readline/lib/rbreadline.rb:1678:in `expand_prompt'
  from /home/manveru/github/luislavena/rb-readline/lib/rbreadline.rb:1767:in `rl_expand_prompt'
  from /home/manveru/github/luislavena/rb-readline/lib/rbreadline.rb:1792:in `rl_set_prompt'
  from /home/manveru/github/luislavena/rb-readline/lib/rbreadline.rb:4726:in `readline'
  from -e:1:in `<main>'

Ruby version is ruby 1.9.2p0 (2010-08-18 revision 29036) [x86_64-linux].

stty invoked wen executing "irb --simple-prompt --rrbconfig"


C:\Documents and Settings\Scarlet Pimpernel>irb --simple-prompt -rrbconfig
E:/Ruby192/lib/ruby/site_ruby/1.9.1/rbreadline.rb:2043:in ``': No such file or d
irectory - stty -a (Errno::ENOENT)
        from E:/Ruby192/lib/ruby/site_ruby/1.9.1/rbreadline.rb:2043:in `rl_tty_s
et_default_bindings'
        from E:/Ruby192/lib/ruby/site_ruby/1.9.1/rbreadline.rb:2056:in `readline
_default_bindings'
        from E:/Ruby192/lib/ruby/site_ruby/1.9.1/rbreadline.rb:2494:in `readline
_initialize_everything'
        from E:/Ruby192/lib/ruby/site_ruby/1.9.1/rbreadline.rb:3726:in `rl_initi
alize'
        from E:/Ruby192/lib/ruby/site_ruby/1.9.1/rbreadline.rb:4720:in `readline
'
        from E:/Ruby192/lib/ruby/site_ruby/1.9.1/readline.rb:40:in `readline'
        from E:/Ruby192/lib/ruby/1.9.1/irb/input-method.rb:115:in `gets'
        from E:/Ruby192/lib/ruby/1.9.1/irb.rb:139:in `block (2 levels) in eval_i
nput'
        from E:/Ruby192/lib/ruby/1.9.1/irb.rb:273:in `signal_status'
        from E:/Ruby192/lib/ruby/1.9.1/irb.rb:138:in `block in eval_input'
        from E:/Ruby192/lib/ruby/1.9.1/irb/ruby-lex.rb:188:in `call'
        from E:/Ruby192/lib/ruby/1.9.1/irb/ruby-lex.rb:188:in `buf_input'
        from E:/Ruby192/lib/ruby/1.9.1/irb/ruby-lex.rb:103:in `getc'
        from E:/Ruby192/lib/ruby/1.9.1/irb/slex.rb:205:in `match_io'
        from E:/Ruby192/lib/ruby/1.9.1/irb/slex.rb:75:in `match'
        from E:/Ruby192/lib/ruby/1.9.1/irb/ruby-lex.rb:286:in `token'
        from E:/Ruby192/lib/ruby/1.9.1/irb/ruby-lex.rb:262:in `lex'
        from E:/Ruby192/lib/ruby/1.9.1/irb/ruby-lex.rb:233:in `block (2 levels)
in each_top_level_statement'
        from E:/Ruby192/lib/ruby/1.9.1/irb/ruby-lex.rb:229:in `loop'
        from E:/Ruby192/lib/ruby/1.9.1/irb/ruby-lex.rb:229:in `block in each_top
_level_statement'
        from E:/Ruby192/lib/ruby/1.9.1/irb/ruby-lex.rb:228:in `catch'
        from E:/Ruby192/lib/ruby/1.9.1/irb/ruby-lex.rb:228:in `each_top_level_st
atement'
        from E:/Ruby192/lib/ruby/1.9.1/irb.rb:155:in `eval_input'
        from E:/Ruby192/lib/ruby/1.9.1/irb.rb:70:in `block in start'
        from E:/Ruby192/lib/ruby/1.9.1/irb.rb:69:in `catch'
        from E:/Ruby192/lib/ruby/1.9.1/irb.rb:69:in `start'
        from E:/Ruby192/bin/irb:12:in `'

This is the complete error message and here are some additional info:

C:\Documents and Settings\Scarlet Pimpernel>ruby -v
ruby 1.9.2p0 (2010-08-18) [i386-mingw32]

C:\Documents and Settings\Scarlet Pimpernel>set TERM
TERM=nutc
TERMCAP=E:\RATIONAL\RATION1\NUTCROOT\etc\termcap
TERMINFO=E:\RATIONAL\RATION
1\NUTCROOT\usr\lib\terminfo

Release version 0.4.1

Since we don't have a project mailing list, I'll post this here.

Are there any blockers or regressions for 0.4.1? I don't know of any.

@luislavena What steps need to be taken to release a new version of rb-readline?

rl_vi_movement_mode raises exception

Either the standard Emacs keymap should not include rl_vi_movement_mode or that method should be a NOOP until issue #21 (Vi keymap) is implemented.

Currently, with the standard keymap, [Esc][Ctrl-j][Esc] will raise an exception.

crash with straight tab

Hello.
Get this:

irb(main):001:0> D:/installs/ruby-1.8.6-p388-i386-mingw32/lib/ruby/site_ruby/1.8/rbreadline.rb:4848:in `[]=': index 0 out of string (IndexError)
        from D:/installs/ruby-1.8.6-p388-i386-mingw32/lib/ruby/site_ruby/1.8/rbreadline.rb:4848:in `rl_delete_text'
        from D:/installs/ruby-1.8.6-p388-i386-mingw32/lib/ruby/site_ruby/1.8/rbreadline.rb:4901:in `_rl_replace_text'
        from D:/installs/ruby-1.8.6-p388-i386-mingw32/lib/ruby/site_ruby/1.8/rbreadline.rb:6341:in `insert_match'
        from D:/installs/ruby-1.8.6-p388-i386-mingw32/lib/ruby/site_ruby/1.8/rbreadline.rb:6709:in `rl_complete_internal'
        from D:/installs/ruby-1.8.6-p388-i386-mingw32/lib/ruby/site_ruby/1.8/rbreadline.rb:6769:in `rl_complete'
        from D:/installs/ruby-1.8.6-p388-i386-mingw32/lib/ruby/site_ruby/1.8/rbreadline.rb:4241:in `send'
        from D:/installs/ruby-1.8.6-p388-i386-mingw32/lib/ruby/site_ruby/1.8/rbreadline.rb:4241:in `_rl_dispatch_subseq'
        from D:/installs/ruby-1.8.6-p388-i386-mingw32/lib/ruby/site_ruby/1.8/rbreadline.rb:4230:in `_rl_dispatch'
         ... 21 levels...
        from D:/installs/ruby-1.8.6-p388-i386-mingw32/lib/ruby/1.8/irb.rb:70:in `start'
        from D:/installs/ruby-1.8.6-p388-i386-mingw32/lib/ruby/1.8/irb.rb:69:in `catch'
        from D:/installs/ruby-1.8.6-p388-i386-mingw32/lib/ruby/1.8/irb.rb:69:in `start'
        from D:/installs/ruby-1.8.6-p388-i386-mingw32/bin/irb:13

When I hit "tab" within irb with nothing entered yet (i.e. first keystroke is tab).
Cheers!

When completion proc returns the token it was asked to complete, a space should be added to end of word, and text should not be deleted

Consider the the following code using readline
require 'rubygems';
require 'rb-readline' # or 'rb-readline/readline' if Rubinius
Readline.completion_proc=Proc.new{|args| [args]}
while ('q' != response=Readline.readline("Huh? ")) do
puts "You sez #{response}?"
end

Now run it and enter tab for tab completion. In C Readline in Ruby or Rubinius you get a space added to the end I guess to indicate that what is before is complete. In rb-readline if there is text it is deleted and no space at the end.

I think this has to do with tests which assume the null string '' evaluates as false which may be the case in C (and Perl) but is not the case in Ruby.

I've not been able to come up with a good test case to test this problem. A suggested patch however will be in a pull request.

adds extra spaces in some terminals

how to reproduce:
use cygwin or msysgit's ssh.exe to ssh to a linux computer which has ruby + rbreadline installed.
within irb type 1000000000 and try to change it to become 1 000 000 000 000 [add spaces]

results in extra spaces being shown:
1000 000 000

even though they're not actually input

> > 1000  000  000
> > SyntaxError: compile error
> > (irb):1: syntax error, unexpected tINTEGER, expecting $end
> > 1000 000 000
> >         ^
> >         from (irb):1

Thanks!
-r

rb-readline with ruby 1.9.3-p0 on Windows cannot display non-ascii characters.

Hi,

I installed rubyinstaller 1.9.3-p0.
I found irb with rb-readline cannot display non-ascii caracters during input like this:
C:\work>irb
irb(main):001:0> a = "������"
=> "가나다"

In ruby-1.9.2-p290, it works as expected.
C:\work>irb
irb(main):001:0> a = "가나다"
=> "가나다"

This issue is due to some changes in rb_w32_write_console of win32.c

To display correct non-ascii characters, line #3807 of rbreadline.rb
@_rl_out_stream.write(string[start,count])
should be
@_rl_out_stream.write(string[start,count].force_encoding(@encoding_name))

Regards,
Park Heesob

Wrong calling convention

rb-readline library has a pretty serious bug though that causes an MSVC instrumented build (I find it easiest to find bugs this way) to blow up. Its uses the cdecl calling convention to call the windows api. That causes the stack to get corrupted. Instead, it should use the stdcall calling convention.

diff --git a/lib/rbreadline.rb b/lib/rbreadline.rb
index 43894aa..b215aff 100644
--- a/lib/rbreadline.rb
+++ b/lib/rbreadline.rb
@@ -4288,7 +4288,7 @@ module RbReadline
def initialize(dllname, func, import, export = "0")
@proto = [import].join.tr("VPpNnLlIi", "0SSI").sub(/^(.)0*$/, '\1')
handle = DLL[dllname] ||= DL.dlopen(dllname)

  •           @func = DL::CFunc.new(handle[func], TYPEMAP[export.tr("VPpNnLlIi", "0SSI")], func)
    
  •           @func = DL::CFunc.new(handle[func], TYPEMAP[export.tr("VPpNnLlIi", "0SSI")], func, :stdcall)
         end
    
         def call(*args)
    

    -- 1.7.0.4.360.g11766c.dirty

seems to fail if run with ENV['TERM'] == 'cygwin'

if I run irb [mingw ruby] from within an msys or cygwin prompt, I get:

c:/ruby/lib/ruby/site_ruby/1.8/rbreadline.rb:1796:in ``': No such file or directory - infocmp -C (Errno::ENOENT)

from c:/ruby/lib/ruby/site_ruby/1.8/rbreadline.rb:1796:in `get_term_capabilities'

from c:/ruby/lib/ruby/site_ruby/1.8/rbreadline.rb:2007:in `_rl_init_terminal_io'

not sure if there's a best way to fix that--for now my fork has a fix that forces you to ignore ENV['TERM'] in doze.

http://github.com/rogerdpack/rb-readline/tree/master
Cheers!
-=r

minor nit pick with 1.9

Currently in 1.8 I discovered it wasn't compatible with the backports gem...

require 'rubygems'
require 'backports'
require 'readline'

=>

C:\dev\ruby\rb-readline>ruby bad.rb
c:/ruby18/lib/ruby/site_ruby/1.8/rbreadline.rb:4405: uninitialized constant RbReadline::Encoding (NameError)
        from c:/ruby18/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require'
        from c:/ruby18/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `require'
        from c:/ruby18/lib/ruby/site_ruby/1.8/readline.rb:8
        from c:/ruby18/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `gem_original_require'
        from c:/ruby18/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:31:in `require'
        from bad.rb:3

this seemed to fix it:
http://github.com/rdp/rb-readline/commit/fc237923fcb95349d689b1027b03f74083bff713

rbreadline misbehaves if ENV['TERM'] is dumb

If ENV['TERM'] is "dumb", then rbreadline throws an error trying to check stty. This can be solved by checking for term.nil? || term == "dumb" in def _rl_init_terminal_io(terminal_name).

Crashes after C-r C-r

Typing Ctrl-r for search backward twice crashes the console with the following stacktrace:


~/foo $ ruby -v
ruby 1.9.2p290 (2011-07-09 revision 32553) [x86_64-linux]
~/foo $ irb
irb(main):001:0> require 'rb-readline'
/home/tils/.rbenv/versions/1.9.2-p290/lib/ruby/gems/1.9.1/gems/rb-readline-0.4.2/lib/readline.rb:447: warning: already initialized constant HISTORY
/home/tils/.rbenv/versions/1.9.2-p290/lib/ruby/gems/1.9.1/gems/rb-readline-0.4.2/lib/readline.rb:476: warning: already initialized constant FILENAME_COMPLETION_PROC
/home/tils/.rbenv/versions/1.9.2-p290/lib/ruby/gems/1.9.1/gems/rb-readline-0.4.2/lib/readline.rb:508: warning: already initialized constant USERNAME_COMPLETION_PROC
/home/tils/.rbenv/versions/1.9.2-p290/lib/ruby/gems/1.9.1/gems/rb-readline-0.4.2/lib/readline.rb:514: warning: already initialized constant VERSION
true
# Typed C-r C-r here
(reverse-i-search)`': /home/tils/.rbenv/versions/1.9.2-p290/lib/ruby/gems/1.9.1/gems/rb-readline-0.4.2/lib/rbreadline.rb:3985:in `include?': can't convert Fixnum into String (TypeError)
        from /home/tils/.rbenv/versions/1.9.2-p290/lib/ruby/gems/1.9.1/gems/rb-readline-0.4.2/lib/rbreadline.rb:3985:in `_rl_isearch_dispatch'
        from /home/tils/.rbenv/versions/1.9.2-p290/lib/ruby/gems/1.9.1/gems/rb-readline-0.4.2/lib/rbreadline.rb:7083:in `rl_search_history'
        from /home/tils/.rbenv/versions/1.9.2-p290/lib/ruby/gems/1.9.1/gems/rb-readline-0.4.2/lib/rbreadline.rb:7054:in `rl_reverse_search_history'
        from /home/tils/.rbenv/versions/1.9.2-p290/lib/ruby/gems/1.9.1/gems/rb-readline-0.4.2/lib/rbreadline.rb:4262:in `_rl_dispatch_subseq'
        from /home/tils/.rbenv/versions/1.9.2-p290/lib/ruby/gems/1.9.1/gems/rb-readline-0.4.2/lib/rbreadline.rb:4251:in `_rl_dispatch'
        from /home/tils/.rbenv/versions/1.9.2-p290/lib/ruby/gems/1.9.1/gems/rb-readline-0.4.2/lib/rbreadline.rb:4669:in `readline_internal_charloop'
        from /home/tils/.rbenv/versions/1.9.2-p290/lib/ruby/gems/1.9.1/gems/rb-readline-0.4.2/lib/rbreadline.rb:4743:in `readline_internal'
        from /home/tils/.rbenv/versions/1.9.2-p290/lib/ruby/gems/1.9.1/gems/rb-readline-0.4.2/lib/rbreadline.rb:4765:in `readline'
        from /home/tils/.rbenv/versions/1.9.2-p290/lib/ruby/gems/1.9.1/gems/rb-readline-0.4.2/lib/readline.rb:40:in `readline'
        from /home/tils/.rbenv/versions/1.9.2-p290/lib/ruby/1.9.1/irb/input-method.rb:115:in `gets'
        from /home/tils/.rbenv/versions/1.9.2-p290/lib/ruby/1.9.1/irb.rb:139:in `block (2 levels) in eval_input'
        from /home/tils/.rbenv/versions/1.9.2-p290/lib/ruby/1.9.1/irb.rb:273:in `signal_status'
        from /home/tils/.rbenv/versions/1.9.2-p290/lib/ruby/1.9.1/irb.rb:138:in `block in eval_input'
        from /home/tils/.rbenv/versions/1.9.2-p290/lib/ruby/1.9.1/irb/ruby-lex.rb:188:in `call'
        from /home/tils/.rbenv/versions/1.9.2-p290/lib/ruby/1.9.1/irb/ruby-lex.rb:188:in `buf_input'
        from /home/tils/.rbenv/versions/1.9.2-p290/lib/ruby/1.9.1/irb/ruby-lex.rb:103:in `getc'
        from /home/tils/.rbenv/versions/1.9.2-p290/lib/ruby/1.9.1/irb/slex.rb:205:in `match_io'
        from /home/tils/.rbenv/versions/1.9.2-p290/lib/ruby/1.9.1/irb/slex.rb:75:in `match'
        from /home/tils/.rbenv/versions/1.9.2-p290/lib/ruby/1.9.1/irb/ruby-lex.rb:286:in `token'
        from /home/tils/.rbenv/versions/1.9.2-p290/lib/ruby/1.9.1/irb/ruby-lex.rb:262:in `lex'
        from /home/tils/.rbenv/versions/1.9.2-p290/lib/ruby/1.9.1/irb/ruby-lex.rb:233:in `block (2 levels) in each_top_level_statement'
        from /home/tils/.rbenv/versions/1.9.2-p290/lib/ruby/1.9.1/irb/ruby-lex.rb:229:in `loop'
        from /home/tils/.rbenv/versions/1.9.2-p290/lib/ruby/1.9.1/irb/ruby-lex.rb:229:in `block in each_top_level_statement'
        from /home/tils/.rbenv/versions/1.9.2-p290/lib/ruby/1.9.1/irb/ruby-lex.rb:228:in `catch'
        from /home/tils/.rbenv/versions/1.9.2-p290/lib/ruby/1.9.1/irb/ruby-lex.rb:228:in `each_top_level_statement'
        from /home/tils/.rbenv/versions/1.9.2-p290/lib/ruby/1.9.1/irb.rb:155:in `eval_input'
        from /home/tils/.rbenv/versions/1.9.2-p290/lib/ruby/1.9.1/irb.rb:70:in `block in start'
        from /home/tils/.rbenv/versions/1.9.2-p290/lib/ruby/1.9.1/irb.rb:69:in `catch'
        from /home/tils/.rbenv/versions/1.9.2-p290/lib/ruby/1.9.1/irb.rb:69:in `start'
        from /home/tils/.rbenv/versions/1.9.2-p290/bin/irb:12:in `<main>'

The error started to occur after I did a system wide upgrade of a lot of operating system packages of my archlinux system. The last system wide upgrade before was a couple of months ago, and I'm unable to guess which component could have this effect. Ruby and gems have stayed at the same version. I can reproduce the error in different terminal emulators (tried konsole and xterm).

the performance of ruby version readline maybe poor?

After opening a irb window,
I typed two quote in irb console first: '',then back my cursor to the middle of quote: 'here is my cursor',then type something else like 'qwertyuiop' quickly,these characters appear in irb console very slowly,and the cpu usage of ruby is 100%!

However,if I just type one quote,then type something else like 'qwertyuiop',and then type another quote,these characters appear in irb console very fast.

here is the screen capture:
http://screenr.com/W4B

Maybe this is an issue with the ruby version readline?

ruby -v
=>ruby 1.8.6 (2009-08-04 patchlevel 383) [i386-mingw32]

My OS is Windows xp,and my page encoding is 936,GBK,after setting it to 850 or 1251,the issue still exists.

Filename completion broken when there are directory components

Currently file name completion works only what you are completing doesn't have file name components. For example if there is a file test.rb and you try to complete on test, that will work, but you won't get a completion for ./test or a completion on /.

I believe this is because completion Readline::rl_filename_completion_function uses @filename which has the full pathname but is comparing on filename components from Dir. So I think all that is needed is simple File.basename.

I've fixed this in https://github.com/rocky/rb-readline . Please review and apply if okay.

Thanks.

[]= : index 0 error in completion method that returns \n

Consider the following program:

require 'rubygems'
require 'rb-readline'
def completion_method(last_token, leading=nil)
  return ["foo\n"]
end
Readline.completion_proc =  method(:completion_method).to_proc
line = Readline.readline('Huh? ', true)

When I run this and hit a tab at the prompt (Huh?) I get a crash. Here is the input and results:

$ ruby /tmp/rlbug2.rb
Huh? **<tab>**  /tmp/rb-readline-0.4.0/lib/rbreadline.rb:4848:in `[]=': index 0 out of string (IndexError)
    from /tmp/rb-readline-0.4.0/lib/rbreadline.rb:4848:in `rl_delete_text'
    from /tmp/rb-readline-0.4.0/lib/rbreadline.rb:4901:in `_rl_replace_text'
    from /tmp/rb-readline-0.4.0/lib/rbreadline.rb:6341:in `insert_match'
    from /tmp/rb-readline-0.4.0/lib/rbreadline.rb:6709:in `rl_complete_internal'
    from /tmp/rb-readline-0.4.0/lib/rbreadline.rb:6769:in `rl_complete'
    from /tmp/rb-readline-0.4.0/lib/rbreadline.rb:4241:in `send'
    from /tmp/rb-readline-0.4.0/lib/rbreadline.rb:4241:in `_rl_dispatch_subseq'
    from /tmp/rb-readline-0.4.0/lib/rbreadline.rb:4230:in `_rl_dispatch'
    from /tmp/rb-readline-0.4.0/lib/rbreadline.rb:4648:in `readline_internal_charloop'
    from /tmp/rb-readline-0.4.0/lib/rbreadline.rb:4722:in `readline_internal'
    from /tmp/rb-readline-0.4.0/lib/rbreadline.rb:4744:in `readline'
    from /tmp/rb-readline-0.4.0/lib/readline.rb:40:in `readline'
    from /tmp/rlbug2.rb:7
$ 

On standard readline what I get is "foo\n" or "foo" is filled out on the command line, and then there is a newline after that.

Doesn't work with CJK Encodings

rbreadline.rb, line 4635

      rl_setstate(RL_STATE_READCMD)
      c = rl_read_key()
      rl_unsetstate(RL_STATE_READCMD)
      # look at input.c:rl_getc() for the circumstances under which this will
      #be returned; punt immediately on read error without converting it to
      #a newline.
      if (c == READERR)
        eof_found = true
        break
      end

READERR = 0xFE.chr, but 0xFE is used by some CJK Encodings. For example, GBK (aka CP936), default encoding in Simplified Chinese Windows, and BIG5 (aka CP950), default encoding in Traditional Chinese Windows.

http://en.wikipedia.org/wiki/GBK#Encoding
http://en.wikipedia.org/wiki/BIG5#A_more_detailed_look_at_the_organization

backspace doesn't work in 1.9 sometimes

Hello.
I noticed that sometimes backspace wasn't working (windows, 1.9.2, rb-readline TRUNK, console2 [might be a factor]). It happens "every so often" and I couldn't figure out how to reliably reproduce it, though it came back every so often.
I traced it down, and it appears the call to
SetConsoleCursorPosition
was failing within that window, with getLastError saying "invalid handle"
this patch resets the handle any time the method calls, and I have tested it out in the "failing environment" and it seems to indeed fix it.
Thanks!
-roger-

Vi movement mode not implemented

Starting rb-readline and hitting escape crashes when set editing-mode vi is in ~/.inputrc.

Backtrace, just starting and hitting escape:

iota ~ % ruby -vr rbreadline -e 'p RbReadline.readline("> ")'
ruby 1.9.2p0 (2010-08-18 revision 29036) [x86_64-linux]
>/home/manveru/github/luislavena/rb-readline/lib/rbreadline.rb:4240:in `_rl_dispatch_subseq': undefined method `rl_vi_movement_mode' for RbReadline:Module (NoMethodError)
  from /home/manveru/github/luislavena/rb-readline/lib/rbreadline.rb:4229:in `_rl_dispatch'
  from /home/manveru/github/luislavena/rb-readline/lib/rbreadline.rb:4639:in `readline_internal_charloop'
  from /home/manveru/github/luislavena/rb-readline/lib/rbreadline.rb:4713:in `readline_internal'
  from /home/manveru/github/luislavena/rb-readline/lib/rbreadline.rb:4735:in `readline'
  from -e:1:in `<main>'

Trying to access Readline.line_buffer before initialization can raise an exception

I think the following will cause an exception:

require 'rb-readline'
RbReadline.rl_line_buffer

What's going on here is that line_buffer starts out nil but is set to the empty string when rl_initialize is called. I've patched this on my fork and added a test case.

However another fix is to set rl_line_buffer to the empty string initially rather than to nil. Dunno.

Irb crash when CTRL+r

Whenever i type CTRL+r IRB on Win32 crashes with :

                                             c:/ruby/lib/ruby/site_ruby/1.8/rbreadline.rb:7220:in `rl_display_search': undefined local variable or method `rl_redisplay_function' for RbReadline:Module (NameError)
    from c:/ruby/lib/ruby/site_ruby/1.8/rbreadline.rb:7032:in `rl_search_history'
    from c:/ruby/lib/ruby/site_ruby/1.8/rbreadline.rb:7015:in `rl_reverse_search_history'
    from c:/ruby/lib/ruby/site_ruby/1.8/rbreadline.rb:4232:in `send'
    from c:/ruby/lib/ruby/site_ruby/1.8/rbreadline.rb:4232:in `_rl_dispatch_subseq'
    from c:/ruby/lib/ruby/site_ruby/1.8/rbreadline.rb:4221:in `_rl_dispatch'
    from c:/ruby/lib/ruby/site_ruby/1.8/rbreadline.rb:4631:in `readline_internal_charloop'
    from c:/ruby/lib/ruby/site_ruby/1.8/rbreadline.rb:4705:in `readline_internal'
    from c:/ruby/lib/ruby/site_ruby/1.8/rbreadline.rb:4727:in `readline'
     ... 18 levels...
    from c:/ruby/lib/ruby/1.8/irb.rb:70:in `start'
    from c:/ruby/lib/ruby/1.8/irb.rb:69:in `catch'
    from c:/ruby/lib/ruby/1.8/irb.rb:69:in `start'
    from c:/ruby/bin/irb.bat:15

My .irbrc file is quite simple :
require 'readline'
require 'rubygems' rescue nil

rbreadline.rb:1796:in ``': No such file or directory - infocmp -C (Errno::ENOENT)

If I use git bash and irb it failed. If I use the standard cmd.exe and irb it seems to be OK.

Ruby 1.9.1-p243, Windows XP SP 3, msysGit 1.6.3.2-preview20090608

$ irb
c:/Ruby18/lib/ruby/site_ruby/1.9.1/rbreadline.rb:1796:in ``': No such file or directory - infocmp -C (Errno::ENOENT)
        from c:/Ruby18/lib/ruby/site_ruby/1.9.1/rbreadline.rb:1796:in `get_term_capabilities'
        from c:/Ruby18/lib/ruby/site_ruby/1.9.1/rbreadline.rb:2005:in `_rl_init_terminal_io'
        from c:/Ruby18/lib/ruby/site_ruby/1.9.1/rbreadline.rb:2491:in `readline_initialize_everything'
        from c:/Ruby18/lib/ruby/site_ruby/1.9.1/rbreadline.rb:3726:in `rl_initialize'
        from c:/Ruby18/lib/ruby/site_ruby/1.9.1/rbreadline.rb:4716:in `readline'
        from c:/Ruby18/lib/ruby/site_ruby/1.9.1/readline.rb:40:in `readline'
        from c:/Ruby18/lib/ruby/1.9.1/irb/input-method.rb:115:in `gets'
        from c:/Ruby18/lib/ruby/1.9.1/irb.rb:131:in `block (2 levels) in eval_input'
        from c:/Ruby18/lib/ruby/1.9.1/irb.rb:263:in `signal_status'
        from c:/Ruby18/lib/ruby/1.9.1/irb.rb:130:in `block in eval_input'
        from c:/Ruby18/lib/ruby/1.9.1/irb/ruby-lex.rb:189:in `call'
        from c:/Ruby18/lib/ruby/1.9.1/irb/ruby-lex.rb:189:in `buf_input'
        from c:/Ruby18/lib/ruby/1.9.1/irb/ruby-lex.rb:103:in `getc'
        from c:/Ruby18/lib/ruby/1.9.1/irb/slex.rb:205:in `match_io'
        from c:/Ruby18/lib/ruby/1.9.1/irb/slex.rb:75:in `match'
        from c:/Ruby18/lib/ruby/1.9.1/irb/ruby-lex.rb:287:in `token'
        from c:/Ruby18/lib/ruby/1.9.1/irb/ruby-lex.rb:263:in `lex'
        from c:/Ruby18/lib/ruby/1.9.1/irb/ruby-lex.rb:234:in `block (2 levels) in each_top_level_statement'
        from c:/Ruby18/lib/ruby/1.9.1/irb/ruby-lex.rb:230:in `loop'
        from c:/Ruby18/lib/ruby/1.9.1/irb/ruby-lex.rb:230:in `block in each_top_level_statement'
        from c:/Ruby18/lib/ruby/1.9.1/irb/ruby-lex.rb:229:in `catch'
        from c:/Ruby18/lib/ruby/1.9.1/irb/ruby-lex.rb:229:in `each_top_level_statement'
        from c:/Ruby18/lib/ruby/1.9.1/irb.rb:145:in `eval_input'
        from c:/Ruby18/lib/ruby/1.9.1/irb.rb:69:in `block in start'
        from c:/Ruby18/lib/ruby/1.9.1/irb.rb:68:in `catch'
        from c:/Ruby18/lib/ruby/1.9.1/irb.rb:68:in `start'
        from c:/Ruby18/bin/irb:12:in `'

BUGS, PERFORMANCE AND PLATFORMS

Hello,

rb-readline is completely unoptimized code, there is a chance that in your platform it behaves painful slow or have some bugs.

rb-readline is used as replacement of GNU Readline as part of RubyInstaller and has been more tested and optimized on Windows than any other platform. The main an sole purpose of the project is to allow a functional IRB console.

Contributions are welcome, and optimizations will be highly appreciated.

String/encoding issue with Ruby 1.9

This was discovered while investigating issue #50 (and uses the same example):

require 'rb-readline'

Readline.completion_proc =  Proc.new { |word| [ "foo\n" ] } 
line = Readline.readline('Huh? ')

Under 1.8.7 and Rubinius 1.2.3, this works as expected. However, under ruby 1.9.2p180 (2011-02-18) [x86_64-linux] (TERM=xterm or gnome), I get this exception when hitting [TAB]:

Huh? foo
 /home/mark/src/rb-readline/lib/rbreadline.rb:3802:in `_rl_col_width': undefined method `force_encoding' for nil:NilClass (NoMethodError)
    from /home/mark/src/rb-readline/lib/rbreadline.rb:1535:in `_rl_move_cursor_relative'
    from /home/mark/src/rb-readline/lib/rbreadline.rb:3602:in `rl_redisplay'
    from /home/mark/src/rb-readline/lib/rbreadline.rb:4614:in `_rl_internal_char_cleanup'
    from /home/mark/src/rb-readline/lib/rbreadline.rb:4675:in `readline_internal_charloop'
    from /home/mark/src/rb-readline/lib/rbreadline.rb:4739:in `readline_internal'
    from /home/mark/src/rb-readline/lib/rbreadline.rb:4761:in `readline'
    from /home/mark/src/rb-readline/lib/readline.rb:40:in `readline'
    from examples/issue-50:4:in `<main>'

My locale is en_GB.utf8.

Add the ability to set the readline buffer

This is needed for more advanced kinds of completions. Suppose I want to expand:

   sh ma

into
show macro

The completion function passes only the last token of the line, In the trepanning debuggers, I use Readline.line_buffer to get at the entire line entered and Readline.line_buffer= to set it after expansion on all tokens is done.

In a forked version of rb-readline, I have made the very small changes needed. So please consider pulling from this.

Line display messed up after exiting i-search with cursor keys

With this program under 1.8.7, 1.9.2 and RBX:

require 'rb-readline'

cyan = "\e[0;36m"
reset = "\e[0m"
prompt = "#{cyan}screwy#{reset} % "

loop do
  Readline.readline(prompt, true)
end

When I input:

hello<Enter>
[Ctrl-r]hel[Right-arrow]

Things are messed up:

% ruby -I lib/ examples/issue-53
screwy % hello
screwy %arch)`hel': hello

Loading ruby-debug under Rails trigger 1.9 Encoding loading in rbreadline

requiring ruby-debug in a Rails application triggers a constant missing under Ruby 1.8.7:


rake aborted!
uninitialized constant RbReadline::Encoding
C:/Users/Luis/.gem/ruby/x86-mingw32/1.8/gems/activesupport-2.3.5/lib/active_support/dependencies.rb:440:in `load_missing_constant'
C:/Users/Luis/.gem/ruby/x86-mingw32/1.8/gems/activesupport-2.3.5/lib/active_support/dependencies.rb:80:in `const_missing'
C:/Users/Luis/Tools/Ruby/ruby-1.8.7-p302-i386-mingw32/lib/ruby/site_ruby/1.8/rbreadline.rb:4404
C:/Users/Luis/.gem/ruby/x86-mingw32/1.8/gems/activesupport-2.3.5/lib/active_support/dependencies.rb:156:in `require'
C:/Users/Luis/.gem/ruby/x86-mingw32/1.8/gems/activesupport-2.3.5/lib/active_support/dependencies.rb:156:in `require'
C:/Users/Luis/.gem/ruby/x86-mingw32/1.8/gems/activesupport-2.3.5/lib/active_support/dependencies.rb:521:in `new_constants_in'
C:/Users/Luis/.gem/ruby/x86-mingw32/1.8/gems/activesupport-2.3.5/lib/active_support/dependencies.rb:156:in `require'
C:/Users/Luis/Tools/Ruby/ruby-1.8.7-p302-i386-mingw32/lib/ruby/site_ruby/1.8/readline.rb:8
C:/Users/Luis/.gem/ruby/x86-mingw32/1.8/gems/activesupport-2.3.5/lib/active_support/dependencies.rb:156:in `require'
C:/Users/Luis/.gem/ruby/x86-mingw32/1.8/gems/activesupport-2.3.5/lib/active_support/dependencies.rb:156:in `require'
C:/Users/Luis/.gem/ruby/x86-mingw32/1.8/gems/activesupport-2.3.5/lib/active_support/dependencies.rb:521:in `new_constants_in'
C:/Users/Luis/.gem/ruby/x86-mingw32/1.8/gems/activesupport-2.3.5/lib/active_support/dependencies.rb:156:in `require'
C:/Users/Luis/.bundle/ruby/1.8/gems/ruby-debug-0.10.3/cli/ruby-debug/interface.rb:92

Seem the issue is triggered by this:
http://github.com/luislavena/rb-readline/blob/master/lib/rbreadline.rb#L4402-4405

It should be checking Ruby 1.9 for real, not the available methods.

cursor can go invisible in linux

At least for me in Linux, if you hit the right arrow too much, your input becomes invisible until you hit the left arrow again for quite awhile.
Thanks.
-r

Readline.completion_append_character and MRI 1.8/1.9 compliance

I tried running the Ruby 1.8.7 readline unit test on master and there is a discrepancy in the what happens when one assigns the empty string '' or nil to Readline.completion_append_character.

I created branch 1.8-unit-test which adds the test and corrects Readline.completion_append_character=() to behave as it does in MRI 1.8 and 1.9.

Call to arms

Not sure this should be asked here since you guys are busy with rb-readline but I am trying to get coolline to work as expected for background processes and was thinking maybe you guys have had to solve this yourselves.

Would someone please check Mon-Ouie/coolline#7 and tell me if that's not possible to fix. It sounds to me like a problem you must have had to solve at some point. How did you solve it?

Rawline

Not really an issue, I abuse this as some sort of non commit specific comment function:

Cool project, but did you check out rawline first? If so, how does this differ? (Note: I'm not involved at all in rawline).

Implement HISTORY.clear (Ruby trunk)

Right now testing against Ruby-trunk fails:

C:/Users/Luis/Projects/oss/ruby/test/readline/test_readline_history.rb:323:in `': undefined method `clear' for HISTORY:Class (NoMethodError)
        from C:/Users/Luis/Projects/oss/ruby/lib/rubygems/custom_require.rb:42:in `require'
        from C:/Users/Luis/Projects/oss/ruby/lib/rubygems/custom_require.rb:42:in `require'
        from C:/Users/Luis/Projects/oss/ruby/lib/test/unit.rb:215:in `block in non_options'
        from C:/Users/Luis/Projects/oss/ruby/lib/test/unit.rb:209:in `each'
        from C:/Users/Luis/Projects/oss/ruby/lib/test/unit.rb:209:in `non_options'
        from C:/Users/Luis/Projects/oss/ruby/lib/test/unit.rb:52:in `process_args'
        from C:/Users/Luis/Projects/oss/ruby/lib/minitest/unit.rb:767:in `run'
        from C:/Users/Luis/Projects/oss/ruby/lib/test/unit.rb:21:in `run'
        from C:/Users/Luis/Projects/oss/ruby/lib/test/unit.rb:585:in `run'
        from C:/Users/Luis/Projects/oss/ruby/lib/test/unit.rb:589:in `run'
        from ../../../../ruby/test/runner.rb:13:in `'

Either implement it or raise NotImplementedError.

insert_more_chars method not fully implemented

prompt = "\001\e[0;36m\002this is long enough to cause a problem\001\e[m\002 % "

loop do
  Readline.readline(prompt, true)
end

Using gnome-terminal (TERM=xterm, IC term capability), inputtting:

hello<Enter>
[Ctrl-r]hel[Right-arrow]

Produces:

% ruby -v -I lib/ examples/issue-54
ruby 1.9.2p180 (2011-02-18) [x86_64-linux]
this is long enough to cause a problem % hello
this is long enough to cause a problem % 
                                          ^----- cursor
% /usr/bin/ruby -v -I lib/ examples/issue-54
ruby 1.8.7 (2011-02-18 patchlevel 334) [x86_64-linux]
this is long enough to cause a problem % hello
this is long enough to cause a problem % h
                                          ^----- cursor

The problem is that rb-readline currently can't call tgoto().

Cryptic error from rbreadline caused by unquoted key-combo in .inputrc when running irb.

In my .inputrc the following line:

C-u: possible-completions

causes:
C:/Ruby192/lib/ruby/site_ruby/1.9.1/rbreadline.rb:2398:in instance_eval': uninitialized constant Module::C (NameError) from C:/Ruby192/lib/ruby/site_ruby/1.9.1/rbreadline.rb:2398:ininstance_eval'

For the unsurprising reason that it is trying to evaluate the C as-is, not as a string.

Changing the line to:
"C-u": possible-completions

Fixes the error.

I was rather slow at finding the cause of this (http://groups.google.com/group/rubyinstaller/browse_thread/thread/fb14c5a950e335e4#).
It may be helpful to have a more to-the-point error message (or just handle unquoted key-combos).

-------------- Environment
Ruby version: 1.8.7
Installed on windows via 1.8.7p302 RubyInstaller from rubyinstaller.org
Windows 7

Steps to repro:

  1. Install ruby via ruby installer.
  2. Create .inputrc like this in home directory:

    BEGIN FILE

    C-u: possible-completions

    END FILE

  3. run irb
  4. Confirm the cryptic error
  5. Change .inputrc file to
    "C-u": possible-completions
  6. run irb
  7. Confirm there is no error :)

ctrl+r crashes irb

irb crashes when ctrl+r is used.
To reproduce in ruby 1.9.1, open irb and hit ctrl+r:

C:\>ruby -v
ruby 1.9.1p243 (2009-07-16 revision 24175) [i386-mingw32]

C:\>irb
main>> {{here I type ctrl+R}}C:/Ruby19/lib/ruby/site_ruby/1.9.1/
rbreadline.rb:3781:in `_rl_col_width': undefined method
`force_encoding' for nil:NilClass (NoMethodError)
       from C:/Ruby19/lib/ruby/site_ruby/1.9.1/rbreadline.rb:1701:in
`block in expand_prompt'
       from C:/Ruby19/lib/ruby/site_ruby/1.9.1/rbreadline.rb:1676:in
`each'
       from C:/Ruby19/lib/ruby/site_ruby/1.9.1/rbreadline.rb:1676:in
`expand_prompt'
       from C:/Ruby19/lib/ruby/site_ruby/1.9.1/rbreadline.rb:7194:in
`rl_message'
       from C:/Ruby19/lib/ruby/site_ruby/1.9.1/rbreadline.rb:7218:in
`rl_display_search'
       from C:/Ruby19/lib/ruby/site_ruby/1.9.1/rbreadline.rb:7032:in
`rl_search_history'
       from C:/Ruby19/lib/ruby/site_ruby/1.9.1/rbreadline.rb:7015:in
`rl_reverse_search_history'
       from C:/Ruby19/lib/ruby/site_ruby/1.9.1/rbreadline.rb:4232:in
`_rl_dispatch_subseq'
       from C:/Ruby19/lib/ruby/site_ruby/1.9.1/rbreadline.rb:4221:in
`_rl_dispatch'
       from C:/Ruby19/lib/ruby/site_ruby/1.9.1/rbreadline.rb:4631:in
`readline_internal_charloop'
       from C:/Ruby19/lib/ruby/site_ruby/1.9.1/rbreadline.rb:4705:in
`readline_internal'
       from C:/Ruby19/lib/ruby/site_ruby/1.9.1/rbreadline.rb:4727:in
`readline'
       from C:/Ruby19/lib/ruby/site_ruby/1.9.1/readline.rb:40:in
`readline'
       from C:/Ruby19/lib/ruby/1.9.1/irb/input-method.rb:115:in
`gets'
       from C:/Ruby19/lib/ruby/1.9.1/irb.rb:131:in `block (2 levels)
in eval_input'
       from C:/Ruby19/lib/ruby/1.9.1/irb.rb:263:in `signal_status'
       from C:/Ruby19/lib/ruby/1.9.1/irb.rb:130:in `block in
eval_input'
       from C:/Ruby19/lib/ruby/1.9.1/irb/ruby-lex.rb:189:in `call'
       from C:/Ruby19/lib/ruby/1.9.1/irb/ruby-lex.rb:189:in
`buf_input'
       from C:/Ruby19/lib/ruby/1.9.1/irb/ruby-lex.rb:103:in `getc'
       from C:/Ruby19/lib/ruby/1.9.1/irb/slex.rb:205:in `match_io'
       from C:/Ruby19/lib/ruby/1.9.1/irb/slex.rb:75:in `match'
       from C:/Ruby19/lib/ruby/1.9.1/irb/ruby-lex.rb:287:in `token'
       from C:/Ruby19/lib/ruby/1.9.1/irb/ruby-lex.rb:263:in `lex'
       from C:/Ruby19/lib/ruby/1.9.1/irb/ruby-lex.rb:234:in `block (2
levels) in each_top_level_statement'
       from C:/Ruby19/lib/ruby/1.9.1/irb/ruby-lex.rb:230:in `loop'
       from C:/Ruby19/lib/ruby/1.9.1/irb/ruby-lex.rb:230:in `block in
each_top_level_statement'
       from C:/Ruby19/lib/ruby/1.9.1/irb/ruby-lex.rb:229:in `catch'
       from C:/Ruby19/lib/ruby/1.9.1/irb/ruby-lex.rb:229:in
`each_top_level_statement'
       from C:/Ruby19/lib/ruby/1.9.1/irb.rb:145:in `eval_input'
       from C:/Ruby19/lib/ruby/1.9.1/irb.rb:69:in `block in start'
       from C:/Ruby19/lib/ruby/1.9.1/irb.rb:68:in `catch'
       from C:/Ruby19/lib/ruby/1.9.1/irb.rb:68:in `start'
       from C:/Ruby19/bin/irb:12:in `'

C:\>

In 1.8.6, open irb, put something in the history, hit ctrl+r and hit any key:

C:\>ruby -v
ruby 1.8.6 (2009-08-04 patchlevel 383) [i386-mingw32]

C:\>irb
main>> puts "foo"
foo
=> nil
< {{here I type ctrl+R and hit
'p'}}
C:/Ruby/lib/ruby/site_ruby/1.8/rbreadline.rb
:4894:in `rl_replace_line': undefined method `delete' for nil:NilClass
(NoMethodError)
       from C:/Ruby/lib/ruby/site_ruby/1.8/rbreadline.rb:4149:in
`_rl_isearch_dispatch'
       from C:/Ruby/lib/ruby/site_ruby/1.8/rbreadline.rb:7044:in
`rl_search_history'
       from C:/Ruby/lib/ruby/site_ruby/1.8/rbreadline.rb:7015:in
`rl_reverse_search_history'
       from C:/Ruby/lib/ruby/site_ruby/1.8/rbreadline.rb:4232:in
`send'
       from C:/Ruby/lib/ruby/site_ruby/1.8/rbreadline.rb:4232:in
`_rl_dispatch_subseq'
       from C:/Ruby/lib/ruby/site_ruby/1.8/rbreadline.rb:4221:in
`_rl_dispatch'
       from C:/Ruby/lib/ruby/site_ruby/1.8/rbreadline.rb:4631:in
`readline_internal_charloop'
       from C:/Ruby/lib/ruby/site_ruby/1.8/rbreadline.rb:4705:in
`readline_internal'
        ... 19 levels...
       from C:/Ruby/lib/ruby/1.8/irb.rb:70:in `start'
       from C:/Ruby/lib/ruby/1.8/irb.rb:69:in `catch'
       from C:/Ruby/lib/ruby/1.8/irb.rb:69:in `start'
       from C:/Ruby/bin/irb:13

C:\>

ENV["HOME"] default may throw fatal NoMethodError on *NIX

The default catenation of two (Windows-specific?) ENV vars on line 1089 of rbreadline.rb results in a fatal NoMethodError (NilClass +) on a *NIX system if $HOME is not set. Further, even if it were to succeed, the library has now modified a process-level attribute, and the new ENV var will be inherited by any children spawned by the rb-readline-require'ing script.

While $HOME-less environments aren't common in *NIX, they do occur, and rb-readline should not give a fatal error nor permanently muck with the environment when they do.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.