Mercurial > hg
comparison mercurial/commands.py @ 11611:4f5a6df2af92 stable
i18n: use encoding.colwidth() for correct column width
Some encoding and language combinations (e.g.: UTF-8 and Japanese)
cause encoding characters into sequence of bytes more than column
width of them.
So, encoding.colwidth() should be applied instread of len() on i18n
strings.
In addition to it, formatting by '%*s'/'%-*s' also uses "number of
bytes" to calculate space padding size, and should be fixed, too.
author | FUJIWARA Katsunori <foozy@lares.dti.ne.jp> |
---|---|
date | Sun, 18 Jul 2010 01:06:50 +0900 |
parents | 8d827f4a23f1 |
children | 0e789549271d |
comparison
equal
deleted
inserted
replaced
11605:ce95d8b87d22 | 11611:4f5a6df2af92 |
---|---|
150 pieces = [] | 150 pieces = [] |
151 | 151 |
152 for f in funcmap: | 152 for f in funcmap: |
153 l = [f(n) for n, dummy in lines] | 153 l = [f(n) for n, dummy in lines] |
154 if l: | 154 if l: |
155 ml = max(map(len, l)) | 155 sized = [(x, encoding.colwidth(x)) for x in l] |
156 pieces.append(["%*s" % (ml, x) for x in l]) | 156 ml = max([w for x, w in sized]) |
157 pieces.append(["%s%s" % (' ' * (ml - w), x) for x, w in sized]) | |
157 | 158 |
158 if pieces: | 159 if pieces: |
159 for p, l in zip(zip(*pieces), lines): | 160 for p, l in zip(zip(*pieces), lines): |
160 ui.write("%s: %s" % (" ".join(p), l[1])) | 161 ui.write("%s: %s" % (" ".join(p), l[1])) |
161 | 162 |
2051 and _(" (default: %s)") % default | 2052 and _(" (default: %s)") % default |
2052 or ""))) | 2053 or ""))) |
2053 if multioccur: | 2054 if multioccur: |
2054 msg = _("\n[+] marked option can be specified multiple times") | 2055 msg = _("\n[+] marked option can be specified multiple times") |
2055 if ui.verbose and name != 'shortlist': | 2056 if ui.verbose and name != 'shortlist': |
2056 opt_output.append((msg, ())) | 2057 opt_output.append((msg, None)) |
2057 else: | 2058 else: |
2058 opt_output.insert(-1, (msg, ())) | 2059 opt_output.insert(-1, (msg, None)) |
2059 | 2060 |
2060 if not name: | 2061 if not name: |
2061 ui.write(_("\nadditional help topics:\n\n")) | 2062 ui.write(_("\nadditional help topics:\n\n")) |
2062 topics = [] | 2063 topics = [] |
2063 for names, header, doc in help.helptable: | 2064 for names, header, doc in help.helptable: |
2065 topics_len = max([len(s[0]) for s in topics]) | 2066 topics_len = max([len(s[0]) for s in topics]) |
2066 for t, desc in topics: | 2067 for t, desc in topics: |
2067 ui.write(" %-*s %s\n" % (topics_len, t, desc)) | 2068 ui.write(" %-*s %s\n" % (topics_len, t, desc)) |
2068 | 2069 |
2069 if opt_output: | 2070 if opt_output: |
2070 opts_len = max([len(line[0]) for line in opt_output if line[1]] or [0]) | 2071 colwidth = encoding.colwidth |
2071 for first, second in opt_output: | 2072 # normalize: (opt or message, desc or None, width of opt) |
2072 if second: | 2073 entries = [desc and (opt, desc, colwidth(opt)) or (opt, None, 0) |
2073 initindent = ' %-*s ' % (opts_len, first) | 2074 for opt, desc in opt_output] |
2074 hangindent = ' ' * (opts_len + 3) | 2075 hanging = max([e[2] for e in entries]) |
2075 ui.write('%s\n' % (util.wrap(second, | 2076 for opt, desc, width in entries: |
2077 if desc: | |
2078 initindent = ' %s%s ' % (opt, ' ' * (hanging - width)) | |
2079 hangindent = ' ' * (hanging + 3) | |
2080 ui.write('%s\n' % (util.wrap(desc, | |
2076 initindent=initindent, | 2081 initindent=initindent, |
2077 hangindent=hangindent))) | 2082 hangindent=hangindent))) |
2078 else: | 2083 else: |
2079 ui.write("%s\n" % first) | 2084 ui.write("%s\n" % opt) |
2080 | 2085 |
2081 def identify(ui, repo, source=None, | 2086 def identify(ui, repo, source=None, |
2082 rev=None, num=None, id=None, branch=None, tags=None): | 2087 rev=None, num=None, id=None, branch=None, tags=None): |
2083 """identify the working copy or specified revision | 2088 """identify the working copy or specified revision |
2084 | 2089 |