null+****@clear*****
null+****@clear*****
Fri Jul 20 16:21:20 JST 2012
SHIMADA Koji 2012-07-20 16:21:20 +0900 (Fri, 20 Jul 2012) New Revision: fbd30b418f02b782a7194ecf83f29735645d385e https://github.com/logaling/logaling-command/commit/fbd30b418f02b782a7194ecf83f29735645d385e Merged c54901b: Merge pull request #72 from logaling/fix-format-output Log: Extract #char_display_width and add a note of caution Modified files: lib/logaling/command/renderers.rb Modified: lib/logaling/command/renderers.rb (+7 -1) =================================================================== --- lib/logaling/command/renderers.rb 2012-07-20 16:19:42 +0900 (e9c3285) +++ lib/logaling/command/renderers.rb 2012-07-20 16:21:20 +0900 (5c3bb45) @@ -110,7 +110,13 @@ module Logaling::Command private def string_display_width(string) - string.each_char.map{|char| char.bytesize == 1 ? 1 : 2}.inject(0, &:+) + string.each_char.map{|char| char_display_width(char) }.inject(0, &:+) + end + + def char_display_width(char) + # Simple and stupid implementation. It would be better to use East_Asian_Width. + # See http://ja.wikipedia.org/wiki/%E6%9D%B1%E3%82%A2%E3%82%B8%E3%82%A2%E3%81%AE%E6%96%87%E5%AD%97%E5%B9%85 + char.bytesize == 1 ? 1 : 2 end def padding_print_size(string, max_size) -------------- next part -------------- An HTML attachment was scrubbed...Descargar