Sha256: fc588cbde0a0e7b17d0d866791f1519b371afda4b6800791de4a89f7aca7ad12

Contents?: true

Size: 884 Bytes

Versions: 2

Compression:

Stored size: 884 Bytes

Contents

module Ruco
  class Editor
    attr_reader :file
    delegate :view, :move, :cursor, :resize, :delete_line, :to => :text_area

    def initialize(file, options)
      @file = file
      content = (File.exist?(@file) ? File.read(@file) : '')
      @text_area = TextArea.new(content, options)
      @modified = false
    end

    def find(text)
      index = text_area.content.index(text, text_area.cursor_index+1) || text_area.cursor_index
      move :to, *text_area.position_for_index(index)
    end

    def reset;end

    def insert(text)
      @modified = true
      text_area.insert(text)
    end

    def delete(*args)
      text_area.delete(*args)
      @modified = true
    end

    def modified?
      @modified
    end

    def save
      File.open(@file,'w'){|f| f.write(text_area.content) }
      @modified = false
    end

    private

    attr_reader :text_area
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
ruco-0.0.22 lib/ruco/editor.rb
ruco-0.0.21 lib/ruco/editor.rb