Class: Ruco::Form

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

Instance Method Summary collapse

Constructor Details

#initialize(label, options, &submit) ⇒ Form

Returns a new instance of Form.



5
6
7
8
9
10
# File 'lib/ruco/form.rb', line 5

def initialize(label, options, &submit)
  @options = options
  @label = label.strip + ' '
  @submit = submit
  reset
end

Instance Method Details

#cursorObject



27
28
29
# File 'lib/ruco/form.rb', line 27

def cursor
  Position.new 0, @label.size + @text_field.cursor.column
end

#insert(text) ⇒ Object



22
23
24
25
# File 'lib/ruco/form.rb', line 22

def insert(text)
  @text_field.insert(text.gsub("\n",'')) unless text == "\n"
  @submit.call(@text_field.value) if text.include?("\n") or @options[:auto_enter]
end

#resetObject



31
32
33
# File 'lib/ruco/form.rb', line 31

def reset
  @text_field = TextField.new(:columns => @options[:columns] - @label.size)
end

#style_mapObject



16
17
18
19
20
# File 'lib/ruco/form.rb', line 16

def style_map
  map = @text_field.style_map
  map.left_pad!(@label.size)
  map
end

#viewObject



12
13
14
# File 'lib/ruco/form.rb', line 12

def view
  @label + @text_field.view
end