Sha256: acd68046869ee9393533d9d149d855136ab2628245862f03f5205b9bfa373a69

Contents?: true

Size: 826 Bytes

Versions: 14

Compression:

Stored size: 826 Bytes

Contents

module Ruco
  class Form
    delegate :move, :delete, :value, :selecting, :selection, :text_in_selection, :to => :text_field

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

    def view
      @label + @text_field.view
    end

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

    def insert(text)
      @text_field.insert(text.gsub("\n",'')) unless text == "\n"
      @submit.call(@text_field.value) if text.include?("\n")
    end

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

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

    private

    attr_reader :text_field
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
ruco-0.1.12 lib/ruco/form.rb
ruco-0.1.11 lib/ruco/form.rb
ruco-0.1.10 lib/ruco/form.rb
ruco-0.1.9 lib/ruco/form.rb
ruco-0.1.8 lib/ruco/form.rb
ruco-0.1.7 lib/ruco/form.rb
ruco-0.1.6 lib/ruco/form.rb
ruco-0.1.5 lib/ruco/form.rb
ruco-0.1.4 lib/ruco/form.rb
ruco-0.1.3 lib/ruco/form.rb
ruco-0.1.2 lib/ruco/form.rb
ruco-0.1.1 lib/ruco/form.rb
ruco-0.1.0 lib/ruco/form.rb
ruco-0.0.56 lib/ruco/form.rb