123456789_123456789_123456789_123456789_123456789_

Class: Reline::KillRing

Relationships & Source Files
Namespace Children
Modules:
Classes:
Inherits: Object
Defined in: lib/reline/kill_ring.rb

Class Method Summary

Instance Method Summary

Constructor Details

.new(max = 1024) ⇒ KillRing

[ GitHub ]

  
# File 'lib/reline/kill_ring.rb', line 59

def initialize(max = 1024)
  @ring = RingBuffer.new(max)
  @ring_pointer = nil
  @buffer = nil
  @state = State::FRESH
end

Instance Method Details

#append(string, before_p = false)

[ GitHub ]

  
# File 'lib/reline/kill_ring.rb', line 66

def append(string, before_p = false)
  case @state
  when State::FRESH, State::YANK
    @ring << RingPoint.new(string)
    @state = State::CONTINUED
  when State::CONTINUED, State::PROCESSED
    if before_p
      @ring.head.str.prepend(string)
    else
      @ring.head.str.concat(string)
    end
    @state = State::CONTINUED
  end
end

#process

[ GitHub ]

  
# File 'lib/reline/kill_ring.rb', line 81

def process
  case @state
  when State::FRESH
    # nothing to do
  when State::CONTINUED
    @state = State::PROCESSED
  when State::PROCESSED
    @state = State::FRESH
  when State::YANK
    # nothing to do
  end
end

#yank

[ GitHub ]

  
# File 'lib/reline/kill_ring.rb', line 94

def yank
  unless @ring.empty?
    @state = State::YANK
    @ring_pointer = @ring.head
    @ring_pointer.str
  else
    nil
  end
end

#yank_pop

[ GitHub ]

  
# File 'lib/reline/kill_ring.rb', line 104

def yank_pop
  if @state == State::YANK
    prev_yank = @ring_pointer.str
    @ring_pointer = @ring_pointer.backward
    [@ring_pointer.str, prev_yank]
  else
    nil
  end
end