[#4479] Requesting addition to IRB (configurable standard output) — Sascha Ebach <se@...>

Hello,

13 messages 2005/02/24
[#4482] Re: Requesting addition to IRB (configurable standard output) — Sam Roberts <sroberts@...> 2005/02/25

Quoting se@digitale-wertschoepfung.de, on Fri, Feb 25, 2005 at 01:22:34AM +0900:

[#4483] Re: Requesting addition to IRB (configurable standard output) — Eric Hodel <drbrain@...7.net> 2005/02/25

On 24 Feb 2005, at 19:51, Sam Roberts wrote:

[#4488] Re: Requesting addition to IRB (configurable standard output) — Sam Roberts <sroberts@...> 2005/02/26

Quoting drbrain@segment7.net, on Sat, Feb 26, 2005 at 02:43:31AM +0900:

[#4489] Re: Requesting addition to IRB (configurable standard output) — Eric Hodel <drbrain@...7.net> 2005/02/26

On 25 Feb 2005, at 16:03, Sam Roberts wrote:

Re: [PATCH] add persistent history to irb

From: Thomas Uehlinger <uehli@...>
Date: 2005-02-20 16:47:34 UTC
List: ruby-core #4454
On Saturday 19 February 2005 15.34, David A. Black wrote:
> Hi --
>
> I've often wanted the up-arrow in irb to give me my history from the
> previous session.  Well, now it does :-)  Patch follows, in the hope
> that this (or equivalent) might make it into the real irb.
>
>
> David
>

Hi David,

There is already a history file support in 1.9. Just set SAVE_HISTORY=true in 
your IRB configuration. If you want, you can also configure the used file by 
setting HISTORY_FILE
This was a patch I contributed some time ago, but obviously it did not make it 
into 1.8 by now.

May I ask the maintainer to commit these changes also to 1.8?

-- Thomas


******
excerpt from input-method.rb:


class FileInputMethod < InputMethod
    def initialize(file)
      super
      @io = open(file)
    end
    attr_reader :file_name

    def eof?
      @io.eof?
    end

    def gets
      print @prompt
      l = @io.gets
#      print @prompt, l
      l
    end
  end

  begin
    require "readline"
    class ReadlineInputMethod < InputMethod
      include Readline 

      def ReadlineInputMethod.create_finalizer(hist, file)
 proc do
   if num = IRB.conf[:SAVE_HISTORY] and (num = num.to_i) > 0
            if hf = IRB.conf[:HISTORY_FILE]
       file = File.expand_path(hf)
            end
            if file
              open(file, 'w' ) do |f|
                hist = hist.to_a
                f.puts(hist[-num..-1] || hist)
              end
     end
   end
 end
      end

      def initialize
 super

 @line_no = 0
 @line = []
 @eof = false

 loader = proc {|f| f.each {|l| HISTORY << l.chomp}}
 if hist = IRB.conf[:HISTORY_FILE]
   hist = File.expand_path(hist)
   begin
     open(hist, &loader) 
   rescue
   end
 else
   IRB.rc_files("_history") do |hist|
     begin
       open(hist, &loader)
     rescue
       hist = nil
     else
       break
     end
   end
 end
 ObjectSpace.define_finalizer(self, 
ReadlineInputMethod.create_finalizer(HISTORY, hist))
      end

      def gets
 if l = readline(@prompt, true)
   HISTORY.pop if l.empty?
   @line[@line_no += 1] = l + "\n"
 else
   @eof = true
   l
 end
      end

In This Thread