Permalink
Browse files

Merge pull request #73 from dalyons/master

Adding support for non US-ASCII encoded menu items
  • Loading branch information...
2 parents 320180c + e206fb6 commit 85dd2b70dddc1db90255285b877bdb4f0d49afa6 @JEG2 committed Mar 29, 2013
Showing with 16 additions and 0 deletions.
  1. +4 −0 lib/highline.rb
  2. +12 −0 test/tc_menu.rb
View
4 lib/highline.rb
@@ -616,6 +616,10 @@ def say( statement )
statement = statement.to_str
return unless statement.length > 0
+ # Allow non-ascii menu prompts in ruby > 1.9.2. ERB eval the menu statement
+ # with the environment's default encoding(usually utf8)
+ statement.force_encoding(Encoding.default_external) if defined?(Encoding) && Encoding.default_external
+
template = ERB.new(statement, nil, "%")
statement = template.result(binding)
View
12 test/tc_menu.rb
@@ -1,3 +1,4 @@
+# encoding: utf-8
# tc_menu.rb
#
# Created by Gregory Thomas Brown on 2005-05-10.
@@ -65,6 +66,17 @@ def test_flow
end
assert_equal("Sample1, Sample2 or Sample3? ", @output.string)
end
+
+ def test_unicode_flow
+ @input << "1\n"
+ @input.rewind
+
+ @terminal.choose do |menu|
+ # Default: menu.flow = :rows
+ menu.choice "Unicode right single quotation mark: ’"
+ end
+ assert_equal("1. Unicode right single quotation mark: ’\n? ", @output.string)
+ end
def test_help
@input << "help\nhelp load\nhelp rules\nhelp missing\n"

0 comments on commit 85dd2b7

Please sign in to comment.