Sha256: edf01215bfda298594a87814018e3bc3392e941b930f803fb563e13838bfc0c8

Contents?: true

Size: 1.05 KB

Versions: 1

Compression:

Stored size: 1.05 KB

Contents

require 'vedeu/support/esc'
require 'vedeu/models/colour'

# Todo: style method (actually whole thing)

module Vedeu
  module Helpers
    def foreground(value, &block)
      @output = ''
      @output << Esc.foreground_colour(value)
      @output << block.call if block_given?
      @output
    end
    alias_method :fg, :foreground

    def background(value, &block)
      @output = ''
      @output << Esc.background_colour(value)
      @output << block.call if block_given?
      @output
    end
    alias_method :bg, :background

    def colour(attributes = {}, &block)
      @output = ''
      @output << Colour.new(attributes).to_s
      @output << block.call if block_given?
      @output
    end

    def style(*value_or_values, &block)
      @output = ''
      if value_or_values.one?
        @output << Esc.string(value_or_values.first)
        @output << block.call if block_given?
      else
        @output << value_or_values.map do |s|
          Esc.string(s)
        end.join
        @output << block.call if block_given?
      end
      @output
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
vedeu-0.1.3 lib/vedeu/support/helpers.rb