Sha256: 6a19c30cc53ddf09df68fcad45afc9cb840c320ca2adc28246fbc46f4499700c

Contents?: true

Size: 723 Bytes

Versions: 1

Compression:

Stored size: 723 Bytes

Contents

module Ruco
  class Form
    delegate :move, :delete, :to => :text_field

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

    def view
      @label + @text_field.view
    end

    def insert(text)
      @text_field.insert(text.gsub("\n",''))
      if text.include?("\n")
        result = @text_field.value
        result = result.to_i if @options[:type] == :integer
        Command.new(@options[:command], result)
      end
    end

    def cursor
      [0, @label.size + @text_field.cursor[1]]
    end

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

    private

    attr_reader :text_field
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
ruco-0.0.5 lib/ruco/form.rb