[PATCH] i18n: use encoding.colwidth() instead of len() for correct column width

Yuya Nishihara yuya at tcha.org
Sun Jul 18 00:49:30 CDT 2010


FUJIWARA Katsunori wrote:
> # HG changeset patch
> # User FUJIWARA Katsunori <foozy at lares.dti.ne.jp>
> # Date 1279382810 -32400
> # Branch stable
> # Node ID d342305f7635e607eef62fbfc9dc6f0e13be34d4
> # Parent  76454cbc11e48d692262843d0c87e81bbb2c053c
> i18n: use encoding.colwidth() instead of len() for correct column width

It looks good on Linux with LANG=ja_JP.utf-8.

> --- a/mercurial/commands.py
> +++ b/mercurial/commands.py
> @@ -152,8 +152,9 @@
>          for f in funcmap:
>              l = [f(n) for n, dummy in lines]
>              if l:
> -                ml = max(map(len, l))
> -                pieces.append(["%*s" % (ml, x) for x in l])
> +                sized = [(x, encoding.colwidth(x)) for x in l]
> +                ml = max([w for x, w in sized])
> +                pieces.append(["%s%s" % (' ' * (ml - w), x) for x, w in sized])

We can pass generator to max(), like max(w for x, w in sized).

> --- /dev/null
> +++ b/tests/test-encoding-align

> +cat <<EOF >> `cat s`
> +first line(1)
> +EOF
> +cat <<EOF >> `cat m`
> +first line(2)
> +EOF
> +cat <<EOF >> `cat l`
> +first line(3)
> +EOF

They don't work on Debian dash, though it appears dash's bug:

backtic operator with heredoc not work:
http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=541544

lacks \x81 (part of Japanese hiragana "i") when redirect:
http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=532302

Yuya,


More information about the Mercurial-devel mailing list