changeset 30088:d1f5f158768e

template: provide a termwidth keyword (issue5395) We want to provide terminal-sized output. As a starting point, expose the terminal width to the templater for use in things like fill.
author Simon Farnsworth <simonfar@fb.com>
date Sat, 08 Oct 2016 02:26:48 -0700
parents 9b230a8e6008
children 040f23ed6963
files mercurial/templatekw.py tests/test-command-template.t
diffstat 2 files changed, 10 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/templatekw.py	Sat Oct 08 08:36:39 2016 -0400
+++ b/mercurial/templatekw.py	Sat Oct 08 02:26:48 2016 -0700
@@ -589,5 +589,10 @@
     for name, func in registrarobj._table.iteritems():
         keywords[name] = func
 
+@templatekeyword('termwidth')
+def termwidth(repo, ctx, templ, **args):
+    """Integer. The width of the current terminal."""
+    return repo.ui.termwidth()
+
 # tell hggettext to extract docstrings from these functions:
 i18nfunctions = keywords.values()
--- a/tests/test-command-template.t	Sat Oct 08 08:36:39 2016 -0400
+++ b/tests/test-command-template.t	Sat Oct 08 02:26:48 2016 -0700
@@ -3214,6 +3214,11 @@
   hg: parse error: fill expects an integer width
   [255]
 
+  $ COLUMNS=25 hg log -l1 --template '{fill(desc, termwidth, "{node|short}:", "termwidth.{rev}:")}'
+  bcc7ff960b8e:desc to be
+  termwidth.1:wrapped desc
+  termwidth.1:to be wrapped (no-eol)
+
   $ hg log -l 1 --template '{sub(r"[0-9]", "-", author)}'
   {node|short} (no-eol)
   $ hg log -l 1 --template '{sub(r"[0-9]", "-", "{node|short}")}'