From patchwork Sat Oct 4 00:40:34 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: [2, of, 3] bookmarks: split ui.write() so that it can be easily ported to formatter api From: Yuya Nishihara X-Patchwork-Id: 6100 Message-Id: <997ce0e10273d6b379a7.1412383234@mimosa> To: mercurial-devel@selenic.com Date: Sat, 04 Oct 2014 09:40:34 +0900 # HG changeset patch # User Yuya Nishihara # Date 1412264196 -32400 # Fri Oct 03 00:36:36 2014 +0900 # Node ID 997ce0e10273d6b379a7a0190cbce31b97977b45 # Parent 7957b516704dde10ba9b018f6b395860e2f755af bookmarks: split ui.write() so that it can be easily ported to formatter api Test output changes because color labels are applied separately. diff --git a/mercurial/commands.py b/mercurial/commands.py --- a/mercurial/commands.py +++ b/mercurial/commands.py @@ -1002,13 +1002,15 @@ def bookmark(ui, repo, *names, **opts): else: prefix, label = ' ', '' - if ui.quiet: - ui.write("%s\n" % bmark, label=label) - else: - pad = " " * (25 - encoding.colwidth(bmark)) - ui.write(" %s %s%s %d:%s\n" % ( - prefix, bmark, pad, repo.changelog.rev(n), hexfn(n)), + if not ui.quiet: + ui.write(' %s ' % prefix, label=label) + ui.write(bmark, label=label) + pad = " " * (25 - encoding.colwidth(bmark)) + if not ui.quiet: + ui.write('%s %d:%s' % ( + pad, repo.changelog.rev(n), hexfn(n)), label=label) + ui.write('\n') @command('branch', [('f', 'force', None, diff --git a/tests/test-bookmarks-current.t b/tests/test-bookmarks-current.t --- a/tests/test-bookmarks-current.t +++ b/tests/test-bookmarks-current.t @@ -18,7 +18,7 @@ list bookmarks with color $ hg --config extensions.color= --config color.mode=ansi \ > bookmark --color=always - \x1b[0;32m * X -1:000000000000\x1b[0m (esc) + \x1b[0;32m * \x1b[0m\x1b[0;32mX\x1b[0m\x1b[0;32m -1:000000000000\x1b[0m (esc) update to bookmark X diff --git a/tests/test-bookmarks.t b/tests/test-bookmarks.t --- a/tests/test-bookmarks.t +++ b/tests/test-bookmarks.t @@ -18,7 +18,7 @@ list bookmarks with color $ hg --config extensions.color= --config color.mode=ansi \ > bookmarks --color=always - \x1b[0;32m * X -1:000000000000\x1b[0m (esc) + \x1b[0;32m * \x1b[0m\x1b[0;32mX\x1b[0m\x1b[0;32m -1:000000000000\x1b[0m (esc) $ echo a > a $ hg add a