Sha256: cda82ac85a9abbcc76198f00b69dbbb40ee25bfcf07bfed7953052a5a281becc

Contents?: true

Size: 943 Bytes

Versions: 10

Compression:

Stored size: 943 Bytes

Contents

require 'rib/core/history'   # dependency
require 'rib/core/multiline' # dependency

module Rib::MultilineHistory
  include Rib::Plugin
  Shell.use(self)

  # --------------- Rib API ---------------

  def before_loop
    @multiline_trash = 0
    super
  end

  def loop_eval input
    return super if MultilineHistory.disabled?
    super
  ensure
    # SyntaxError might mean we're multiline editing
    handle_multiline unless multiline?($!)
  end

  def handle_interrupt
    return super if MultilineHistory.disabled?
    if multiline_buffer.size > 1
      @multiline_trash ||= 0
      @multiline_trash  += 1
    end
    super
  end



  private
  def handle_multiline
    if multiline_buffer.size > 1
      # so multiline editing is considering done here
      # TODO: there's no history.pop(size)
      (multiline_buffer.size + @multiline_trash).times{ history.pop }
      history << "\n" + multiline_buffer.join("\n")
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
rib-1.0.1 lib/rib/more/multiline_history.rb
rib-1.0.0 lib/rib/more/multiline_history.rb
rib-0.9.9 lib/rib/more/multiline_history.rb
rib-0.9.5 lib/rib/more/multiline_history.rb
rib-0.9.5.pre.1 lib/rib/more/multiline_history.rb
rib-0.9.5.pre.0 lib/rib/more/multiline_history.rb
rib-0.9.4 lib/rib/more/multiline_history.rb
rib-0.9.3 lib/rib/more/multiline_history.rb
rib-0.9.2 lib/rib/more/multiline_history.rb
rib-0.9.1 lib/rib/more/multiline_history.rb