##// END OF EJS Templates
i18n: use encoding.colwidth() for correct column width...
FUJIWARA Katsunori -
r11611:4f5a6df2 stable
parent child Browse files
Show More
@@ -0,0 +1,123 b''
1 #!/bin/sh
2
3 ########################################
4
5 HGENCODING=utf-8
6 export HGENCODING
7
8 hg init t
9 cd t
10
11 python << EOF
12 # (byte, width) = (6, 4)
13 s = "\xe7\x9f\xad\xe5\x90\x8d"
14 # (byte, width) = (7, 7): odd width is good for alignment test
15 m = "MIDDLE_"
16 # (byte, width) = (18, 12)
17 l = "\xe9\x95\xb7\xe3\x81\x84\xe9\x95\xb7\xe3\x81\x84\xe5\x90\x8d\xe5\x89\x8d"
18
19 f = file('s', 'w'); f.write(s); f.close()
20 f = file('m', 'w'); f.write(m); f.close()
21 f = file('l', 'w'); f.write(l); f.close()
22
23 # instant extension to show list of options
24 f = file('showoptlist.py', 'w'); f.write("""# encoding: utf-8
25 def showoptlist(ui, repo, *pats, **opts):
26 '''dummy command to show option descriptions'''
27 return 0
28
29 cmdtable = {
30 'showoptlist':
31 (showoptlist,
32 [('s', 'opt1', '', 'short width', '""" + s + """'),
33 ('m', 'opt2', '', 'middle width', '""" + m + """'),
34 ('l', 'opt3', '', 'long width', '""" + l + """')
35 ],
36 ""
37 )
38 }
39 """)
40 f.close()
41 EOF
42
43 S=`cat s`
44 M=`cat m`
45 L=`cat l`
46
47 ########################################
48 #### alignment of:
49 #### - option descriptions in help
50
51 cat <<EOF > .hg/hgrc
52 [extensions]
53 ja_ext = `pwd`/showoptlist.py
54 EOF
55 echo '% check alignment of option descriptions in help'
56 hg help showoptlist
57
58 ########################################
59 #### alignment of:
60 #### - user names in annotate
61 #### - file names in diffstat
62
63 #### add files
64
65 touch $S
66 hg add $S
67 touch $M
68 hg add $M
69 touch $L
70 hg add $L
71
72 #### commit(1)
73
74 echo 'first line(1)' >> $S
75 echo 'first line(2)' >> $M
76 echo 'first line(3)' >> $L
77 hg commit -m 'first commit' -u $S -d "1000000 0"
78
79 #### commit(2)
80
81 echo 'second line(1)' >> $S
82 echo 'second line(2)' >> $M
83 echo 'second line(3)' >> $L
84 hg commit -m 'second commit' -u $M -d "1000000 0"
85
86 #### commit(3)
87
88 echo 'third line(1)' >> $S
89 echo 'third line(2)' >> $M
90 echo 'third line(3)' >> $L
91 hg commit -m 'third commit' -u $L -d "1000000 0"
92
93 #### check
94
95 echo '% check alignment of user names in annotate'
96 hg annotate -u $M
97 echo '% check alignment of filenames in diffstat'
98 hg diff -c tip --stat
99
100 ########################################
101 #### alignment of:
102 #### - branch names in list
103 #### - tag names in list
104
105 #### add branches/tags
106
107 hg branch $S
108 hg tag -d "1000000 0" $S
109 hg branch $M
110 hg tag -d "1000000 0" $M
111 hg branch $L
112 hg tag -d "1000000 0" $L
113
114 #### check
115
116 echo '% check alignment of branches'
117 hg tags
118 echo '% check alignment of tags'
119 hg tags
120
121 ########################################
122
123 exit 0
@@ -0,0 +1,34 b''
1 % check alignment of option descriptions in help
2 hg showoptlist
3
4 dummy command to show option descriptions
5
6 options:
7
8 -s --opt1 短名 short width
9 -m --opt2 MIDDLE_ middle width
10 -l --opt3 長い長い名前 long width
11
12 use "hg -v help showoptlist" to show global options
13 % check alignment of user names in annotate
14 短名: first line(2)
15 MIDDLE_: second line(2)
16 長い長い名前: third line(2)
17 % check alignment of filenames in diffstat
18 MIDDLE_ | 1 +
19 短名 | 1 +
20 長い長い名前 | 1 +
21 3 files changed, 3 insertions(+), 0 deletions(-)
22 marked working directory as branch 短名
23 marked working directory as branch MIDDLE_
24 marked working directory as branch 長い長い名前
25 % check alignment of branches
26 tip 5:afc60d8eed19
27 長い長い名前 4:19fe74d09ba0
28 MIDDLE_ 3:8a20997d2281
29 短名 2:0cc06ffa3461
30 % check alignment of tags
31 tip 5:afc60d8eed19
32 長い長い名前 4:19fe74d09ba0
33 MIDDLE_ 3:8a20997d2281
34 短名 2:0cc06ffa3461
@@ -152,8 +152,9 b' def annotate(ui, repo, *pats, **opts):'
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):
@@ -2053,9 +2054,9 b' def help_(ui, name=None, with_version=Fa'
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"))
@@ -2067,16 +2068,20 b' def help_(ui, name=None, with_version=Fa'
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):
@@ -11,7 +11,7 b' import tempfile, zlib'
11
11
12 from i18n import _
12 from i18n import _
13 from node import hex, nullid, short
13 from node import hex, nullid, short
14 import base85, cmdutil, mdiff, util, diffhelpers, copies
14 import base85, cmdutil, mdiff, util, diffhelpers, copies, encoding
15
15
16 gitre = re.compile('diff --git a/(.*) b/(.*)')
16 gitre = re.compile('diff --git a/(.*) b/(.*)')
17
17
@@ -1644,10 +1644,14 b' def diffstat(lines, width=80, git=False)'
1644 maxtotal, maxname = 0, 0
1644 maxtotal, maxname = 0, 0
1645 totaladds, totalremoves = 0, 0
1645 totaladds, totalremoves = 0, 0
1646 hasbinary = False
1646 hasbinary = False
1647 for filename, adds, removes, isbinary in stats:
1647
1648 sized = [(filename, adds, removes, isbinary, encoding.colwidth(filename))
1649 for filename, adds, removes, isbinary in stats]
1650
1651 for filename, adds, removes, isbinary, namewidth in sized:
1648 totaladds += adds
1652 totaladds += adds
1649 totalremoves += removes
1653 totalremoves += removes
1650 maxname = max(maxname, len(filename))
1654 maxname = max(maxname, namewidth)
1651 maxtotal = max(maxtotal, adds + removes)
1655 maxtotal = max(maxtotal, adds + removes)
1652 if isbinary:
1656 if isbinary:
1653 hasbinary = True
1657 hasbinary = True
@@ -1667,15 +1671,17 b' def diffstat(lines, width=80, git=False)'
1667 # if there were at least some changes.
1671 # if there were at least some changes.
1668 return max(i * graphwidth // maxtotal, int(bool(i)))
1672 return max(i * graphwidth // maxtotal, int(bool(i)))
1669
1673
1670 for filename, adds, removes, isbinary in stats:
1674 for filename, adds, removes, isbinary, namewidth in sized:
1671 if git and isbinary:
1675 if git and isbinary:
1672 count = 'Bin'
1676 count = 'Bin'
1673 else:
1677 else:
1674 count = adds + removes
1678 count = adds + removes
1675 pluses = '+' * scale(adds)
1679 pluses = '+' * scale(adds)
1676 minuses = '-' * scale(removes)
1680 minuses = '-' * scale(removes)
1677 output.append(' %-*s | %*s %s%s\n' % (maxname, filename, countwidth,
1681 output.append(' %s%s | %*s %s%s\n' %
1678 count, pluses, minuses))
1682 (filename, ' ' * (maxname - namewidth),
1683 countwidth, count,
1684 pluses, minuses))
1679
1685
1680 if stats:
1686 if stats:
1681 output.append(_(' %d files changed, %d insertions(+), %d deletions(-)\n')
1687 output.append(_(' %d files changed, %d insertions(+), %d deletions(-)\n')
General Comments 0
You need to be logged in to leave comments. Login now