module Cucumber::WindowsOutput

def self.extended(o)

:nodoc:
def self.extended(o)
  o.instance_eval do
    alias cucumber_print print
    def print(*a)
      begin
        cucumber_print(*Iconv.iconv(Cucumber::CODEPAGE, "UTF-8", *a.map{|a|a.to_s}))
      rescue Iconv::InvalidEncoding => e
        STDERR.cucumber_puts("WARNING: #{e.message}")
        cucumber_print(*a)
      rescue Iconv::IllegalSequence => e
        STDERR.cucumber_puts("WARNING: #{e.message}")
        cucumber_print(*a)
      end
    end
    alias cucumber_puts puts
    def puts(*a)
      begin
        cucumber_puts(*Iconv.iconv(Cucumber::CODEPAGE, "UTF-8", *a.map{|a|a.to_s}))
      rescue Iconv::InvalidEncoding => e
        STDERR.cucumber_print("WARNING: #{e.message}")
        cucumber_print(*a)
      rescue Iconv::IllegalSequence => e
        STDERR.cucumber_puts("WARNING: #{e.message}")
        cucumber_puts(*a)
      end
    end
  end
end

def print(*a)

def print(*a)
  begin
    cucumber_print(*Iconv.iconv(Cucumber::CODEPAGE, "UTF-8", *a.map{|a|a.to_s}))
  rescue Iconv::InvalidEncoding => e
    STDERR.cucumber_puts("WARNING: #{e.message}")
    cucumber_print(*a)
  rescue Iconv::IllegalSequence => e
    STDERR.cucumber_puts("WARNING: #{e.message}")
    cucumber_print(*a)
  end
end

def puts(*a)

def puts(*a)
  begin
    cucumber_puts(*Iconv.iconv(Cucumber::CODEPAGE, "UTF-8", *a.map{|a|a.to_s}))
  rescue Iconv::InvalidEncoding => e
    STDERR.cucumber_print("WARNING: #{e.message}")
    cucumber_print(*a)
  rescue Iconv::IllegalSequence => e
    STDERR.cucumber_puts("WARNING: #{e.message}")
    cucumber_puts(*a)
  end
end