You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

unicode.rb 1.6 kB

2 years ago
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. # frozen_string_literal: true
  2. # Require this file if you need Unicode support.
  3. # Tips for improvement - esp. ruby 1.9: http://www.ruby-forum.com/topic/184730
  4. require 'cucumber/platform'
  5. require 'cucumber/formatter/ansicolor'
  6. if Cucumber::WINDOWS
  7. if ENV['CUCUMBER_OUTPUT_ENCODING']
  8. Cucumber::CODEPAGE = ENV['CUCUMBER_OUTPUT_ENCODING']
  9. elsif `cmd /c chcp` =~ /(\d+)/
  10. if [65_000, 65_001].include? Regexp.last_match(1).to_i
  11. Cucumber::CODEPAGE = 'UTF-8'.freeze
  12. ENV['ANSICON_API'] = 'ruby'
  13. else
  14. Cucumber::CODEPAGE = "cp#{Regexp.last_match(1).to_i}".freeze
  15. end
  16. else
  17. Cucumber::CODEPAGE = 'cp1252'.freeze
  18. $stderr.puts("WARNING: Couldn't detect your output codepage. Assuming it is 1252. You may have to chcp 1252 or SET CUCUMBER_OUTPUT_ENCODING=cp1252.")
  19. end
  20. module Cucumber
  21. # @private
  22. module WindowsOutput
  23. def self.extended(output)
  24. output.instance_eval do
  25. def cucumber_preprocess_output(*out)
  26. out.map { |arg| arg.to_s.encode(Encoding.default_external) }
  27. rescue Encoding::UndefinedConversionError => e
  28. $stderr.cucumber_puts("WARNING: #{e.message}")
  29. out
  30. end
  31. alias cucumber_print print
  32. def print(*out)
  33. cucumber_print(*cucumber_preprocess_output(*out))
  34. end
  35. alias cucumber_puts puts
  36. def puts(*out)
  37. cucumber_puts(*cucumber_preprocess_output(*out))
  38. end
  39. end
  40. end
  41. Kernel.extend(self)
  42. $stdout.extend(self)
  43. $stderr.extend(self)
  44. end
  45. end
  46. end

No Description

Contributors (1)