Submitter | Simon Farnsworth |
---|---|
Date | Oct. 8, 2016, 9:32 a.m. |
Message ID | <4c76c4023f440ee2fefe.1475919120@devvm022.lla2.facebook.com> |
Download | mbox | patch |
Permalink | /patch/16911/ |
State | Accepted |
Headers | show |
Comments
On Sat, 8 Oct 2016 02:32:00 -0700, Simon Farnsworth wrote: > # HG changeset patch > # User Simon Farnsworth <simonfar@fb.com> > # Date 1475918808 25200 > # Sat Oct 08 02:26:48 2016 -0700 > # Node ID 4c76c4023f440ee2fefe2b632a99869cd657ff90 > # Parent 91a3c58ecf938ed675f5364b88f0d663f12b0047 > 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. Looks good. Queued, thanks.
Patch
diff --git a/mercurial/templatekw.py b/mercurial/templatekw.py --- a/mercurial/templatekw.py +++ b/mercurial/templatekw.py @@ -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() 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 @@ -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}")}'