changeset 1987:d427fd97c9d5

topic: properly justify the verbose data when listing topic We align all data to the widest topic.
author Pierre-Yves David <pierre-yves.david@ens-lyon.org>
date Tue, 16 Aug 2016 15:43:06 +0200
parents 042356d5ba59
children 9a5d797d25be
files hgext3rd/topic/__init__.py tests/test-topic-list.t
diffstat 2 files changed, 10 insertions(+), 6 deletions(-) [+]
line wrap: on
line diff
--- a/hgext3rd/topic/__init__.py	Tue Aug 16 15:32:54 2016 +0200
+++ b/hgext3rd/topic/__init__.py	Tue Aug 16 15:43:06 2016 +0200
@@ -280,6 +280,10 @@
 def _listtopics(ui, repo, opts):
     fm = ui.formatter('bookmarks', opts)
     activetopic = repo.currenttopic
+    namemask = '%s'
+    if repo.topics and ui.verbose:
+        maxwidth = max(len(t) for t in repo.topics)
+        namemask = '%%-%is' % maxwidth
     for topic in sorted(repo.topics):
         fm.startitem()
         marker = ' '
@@ -291,12 +295,12 @@
         if not ui.quiet:
             # registering the active data is made explicitly later
             fm.plain(' %s ' % marker, label=label)
-        fm.write('topic', '%s', topic, label=label)
+        fm.write('topic', namemask, topic, label=label)
         fm.data(active=active)
         if ui.verbose:
             # XXX we should include the data even when not verbose
             data = stack.stackdata(repo, topic)
-            fm.plain('\t(')
+            fm.plain(' (')
             fm.write('changesetcount', '%d changesets', data['changesetcount'],
                      label='topic.list.changesetcount')
             if data['troubledcount']:
--- a/tests/test-topic-list.t	Tue Aug 16 15:32:54 2016 +0200
+++ b/tests/test-topic-list.t	Tue Aug 16 15:43:06 2016 +0200
@@ -173,10 +173,10 @@
 verbose
 
   $ hg topic --verbose
-     bar	(5 changesets, 1 troubled, 2 heads)
-     baz	(2 changesets, 2 behind)
-   * foo	(2 changesets, ambiguous destination)
-     fuz	(3 changesets, 2 troubled, 1 behind)
+     bar (5 changesets, 1 troubled, 2 heads)
+     baz (2 changesets, 2 behind)
+   * foo (2 changesets, ambiguous destination)
+     fuz (3 changesets, 2 troubled, 1 behind)
 
 json