Permalink
Browse files

Adding support for non US-ASCII encoded menu items

- Eval the menu template in the interpreter's default_external encoding,
  which will probably be utf8, or something like windows-1252 on win32
- Added test with utf8 char in it
  • Loading branch information...
1 parent 320180c commit e206fb6c5da5bdbc6daefcbd19d0c50635d62376 @dalyons dalyons committed Mar 28, 2013
Showing with 16 additions and 0 deletions.
  1. +4 −0 lib/highline.rb
  2. +12 −0 test/tc_menu.rb
View
@@ -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
@@ -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 e206fb6

Please sign in to comment.