[PATCH STABLE, RFC] ui: add a formatted() method -- like interactive(), but for output

Brodie Rao brodie at bitheap.org
Sun Jun 6 21:48:33 CDT 2010


On May 6, 2010, at 5:33 PM, Greg Ward wrote:

> On Tue, May 4, 2010 at 5:10 PM, Dan Villiom Podlaski Christiansen
> <danchr at gmail.com> wrote:
>> # HG changeset patch
>> # User Dan Villiom Podlaski Christiansen <danchr at gmail.com>
>> # Date 1273007228 -7200
>> # Branch stable
>> # Node ID 5b66df12549a2c01c603c12151689a945037a542
>> # Parent  69145d9b4127d3307a99d19e3321bead0058f3a5
>> ui: add a formatted() method -- like interactive(), but for output
> [...]
>> I haven't tested this patch extensively; it is primarily provided for
>> testing & comment. Eventually, the progress extension should also use
>> this infrastructure.
> 
> I don't know if this is a good idea or not, but I *do* know that
> ui.formatted() really needs a docstring.  As does interactive(),
> although that's an existing flaw.

(Sorry I didn't comment sooner, Dan.)

I'd like to see this get in. As it stands, qseries will truncate patch summaries based on the terminal's width, even if the command is piped to another program. You can test this with the following command:

$ COLUMNS=1 hg qseries -s | cat

This is particularly unhelpful when doing things like grepping output.

There are three modes of output to consider:

1. Normal output (no piping, no pager). Patch summaries should be truncated.
2. Output sent through the pager extension. Patch summaries should be truncated.
3. Piped output. Patch summaries should not be truncated.

Using ui.interactive(), #1 and #3 would be satisfied, but not #2. Using ui.plain(), #3 won't be satisfied.

I do agree that the method should be documented carefully. Especially since we'd end up having three different ui attributes to check for - interactive, plain, and formatted.


More information about the Mercurial-devel mailing list