[PATCH 2 of 2] template: filter to fill to terminal width (issue5395)
Simon Farnsworth
simonfar at fb.com
Fri Oct 7 12:07:54 UTC 2016
# HG changeset patch
# User Simon Farnsworth <simonfar at fb.com>
# Date 1475841473 -7200
# Fri Oct 07 13:57:53 2016 +0200
# Node ID ad9be6bb981ca5dccdd4d64dd682e0cba780067b
# Parent 5831f8daf49f2eabe5b7e6ba0f3da1fc61b5ed09
template: filter to fill to terminal width (issue5395)
We can fill to various sizes - terminal width is also useful
diff --git a/mercurial/templatefilters.py b/mercurial/templatefilters.py
--- a/mercurial/templatefilters.py
+++ b/mercurial/templatefilters.py
@@ -165,6 +165,11 @@
"""Any text. Wraps the text to fit in 76 columns."""
return fill(text, 76)
+ at templatefilter('fillterminal')
+def fillterminal(text):
+ """Any text. Wraps the text to fit in the terminal."""
+ return fill(text, util.termwidth())
+
@templatefilter('firstline')
def firstline(text):
"""Any text. Returns the first line of text."""
diff --git a/tests/test-command-template.t b/tests/test-command-template.t
--- a/tests/test-command-template.t
+++ b/tests/test-command-template.t
@@ -3213,6 +3213,15 @@
$ hg log -l1 -T '{fill(desc, date, "", "")}\n'
hg: parse error: fill expects an integer width
[255]
+ $ COLUMNS=5 hg log -l1 --template '{fillterminal(desc)}'
+ desc
+ to be
+ wrapp
+ ed
+ desc
+ to be
+ wrapp
+ ed (no-eol)
$ hg log -l 1 --template '{sub(r"[0-9]", "-", author)}'
{node|short} (no-eol)
More information about the Mercurial-devel
mailing list