null+****@clear*****
null+****@clear*****
Wed Jul 18 17:14:07 JST 2012
SUZUKI Miho 2012-07-18 17:14:07 +0900 (Wed, 18 Jul 2012) New Revision: a9d04290164e4a56a70cbdc31ab67284c4155f42 https://github.com/logaling/logaling-command/commit/a9d04290164e4a56a70cbdc31ab67284c4155f42 Merged c54901b: Merge pull request #72 from logaling/fix-format-output Log: Count number of characters in source term correctly when render in terminal Modified files: lib/logaling/command/application.rb lib/logaling/command/renderers.rb Modified: lib/logaling/command/application.rb (+3 -5) =================================================================== --- lib/logaling/command/application.rb 2012-07-18 14:32:30 +0900 (f249d69) +++ lib/logaling/command/application.rb 2012-07-18 17:14:07 +0900 (04bd85c) @@ -379,12 +379,10 @@ module Logaling::Command @repository.index end - def term_print_size(string) - string.each_char.map{|char| char.bytesize == 1 ? 1 : 2}.inject(0, &:+) - end - def max_str_size(terms) - terms.map{|term| term_print_size(term[:source_term])}.sort.last + terms.map{|term| + Logaling::Command::Renderers::TermDefaultRenderer.print_size(term[:source_term]) + }.sort.last end end end Modified: lib/logaling/command/renderers.rb (+16 -2) =================================================================== --- lib/logaling/command/renderers.rb 2012-07-18 14:32:30 +0900 (b13947b) +++ lib/logaling/command/renderers.rb 2012-07-18 17:14:07 +0900 (3376944) @@ -63,6 +63,19 @@ module Logaling::Command end class TermDefaultRenderer < TermRenderer + class << self + def print_size(string) + string.each_char.map{|char| char.bytesize == 1 ? 1 : 2}.inject(0, &:+) + end + + def padding_print_size(string_raw, string, max_size) + # use size of un-snipped source_term + padding_size = max_size - print_size(string_raw) + padding_size = 0 if padding_size < 0 + string + " " * padding_size + end + public :padding_print_size, :print_size + end attr_accessor :max_str_size def initialize(term, repository, config, options) @@ -71,8 +84,9 @@ module Logaling::Command end def render(output) - format = [target_term, note, glossary_name].compact.join("\t") - output.printf(" %-#{@max_str_size+10}s %s\n", source_term, format) + format = [target_term.strip, note, glossary_name].compact.join("\t") + paddinged_source_term = TermDefaultRenderer.padding_print_size(@term[:source_term], source_term, @max_str_size) + output.printf(" %s %s\n", paddinged_source_term, format) end def glossary_name -------------- next part -------------- An HTML attachment was scrubbed...下载