Sha256: d2004ca6dc57d5c30080157743244884b1b10d127aba3ea8e27f6094ae29e6cd

Contents?: true

Size: 989 Bytes

Versions: 23

Compression:

Stored size: 989 Bytes

Contents

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

module Rib::MultilineHistory
  extend 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
      @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

  def multiline_trash
    @multiline_trash ||= 0
  end
end

Version data entries

23 entries across 23 versions & 1 rubygems

Version Path
rib-1.5.1 lib/rib/more/multiline_history.rb
rib-1.5.0 lib/rib/more/multiline_history.rb
rib-1.4.0 lib/rib/more/multiline_history.rb
rib-1.3.1 lib/rib/more/multiline_history.rb
rib-1.3.0 lib/rib/more/multiline_history.rb
rib-1.2.91 lib/rib/more/multiline_history.rb
rib-1.2.9 lib/rib/more/multiline_history.rb
rib-1.2.8 lib/rib/more/multiline_history.rb
rib-1.2.7 lib/rib/more/multiline_history.rb
rib-1.2.6 lib/rib/more/multiline_history.rb
rib-1.2.5 lib/rib/more/multiline_history.rb
rib-1.2.4 lib/rib/more/multiline_history.rb
rib-1.2.3 lib/rib/more/multiline_history.rb
rib-1.2.2 lib/rib/more/multiline_history.rb
rib-1.2.1 lib/rib/more/multiline_history.rb
rib-1.2.0 lib/rib/more/multiline_history.rb
rib-1.1.6 lib/rib/more/multiline_history.rb
rib-1.1.5 lib/rib/more/multiline_history.rb
rib-1.1.4 lib/rib/more/multiline_history.rb
rib-1.1.3 lib/rib/more/multiline_history.rb