Class: Ruco::Editor

Inherits:
Object show all
Defined in:
lib/ruco/editor.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(file, options) ⇒ Editor

Returns a new instance of Editor.



6
7
8
9
10
11
# File 'lib/ruco/editor.rb', line 6

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

Instance Attribute Details

#fileObject (readonly)

Returns the value of attribute file.



3
4
5
# File 'lib/ruco/editor.rb', line 3

def file
  @file
end

Instance Method Details

#delete(*args) ⇒ Object



25
26
27
28
# File 'lib/ruco/editor.rb', line 25

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

#find(text) ⇒ Object



13
14
15
16
# File 'lib/ruco/editor.rb', line 13

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

#insert(text) ⇒ Object



20
21
22
23
# File 'lib/ruco/editor.rb', line 20

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

#modified?Boolean

Returns:

  • (Boolean)


30
31
32
# File 'lib/ruco/editor.rb', line 30

def modified?
  @modified
end

#resetObject



18
# File 'lib/ruco/editor.rb', line 18

def reset;end

#saveObject



34
35
36
37
# File 'lib/ruco/editor.rb', line 34

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