Sandro Tosi <mo...@debian.org> wrote:

>On Mon, Jan 14, 2013 at 5:20 PM, Matthew Gabeler-Lee
><chee...@fastcat.org> wrote:
>> Anyways, my point in the bug report is that fetching the COLUMNS
>environment
>> variable is a no-op, it is completely non-functional.
>
>have you tried it?

Yes ... hence the bug report ...

>$ diff -urNad pp-1.6.2 pp-1.6.3 | diffstat

Try with a diff with long paths and an even wider window, e.g. paths > 80 chars 
and a terminal / window > 100 columns.  It will not use the full terminal 
width, but instead use its minimum histogram width of 10 chars.

>$ diff -urNad pp-1.6.2 pp-1.6.3 | COLUMNS=20 diffstat

Aah, but here you are explicitly setting the COLUMNS value.

My point was that, unless you do something to explicitly expose COLUMNS to 
diffstat, it isn't available.  In your first sample, if you ran it under gdb, 
you would find that the fetch of the COLUMNS environment var returned NULL.  
You can demonstrate that simply by just running "env | grep COLUMNS".

COLUMNS is an automatic / magic variable, at least in bash, and is not exported 
to sub-processes by default, so fetching it from a sub-process is not a 
functional way to query the terminal size.  I don't know if other shells behave 
differently from bash in that regard.

My point to the report is that if diffstat wants to find out the terminal size, 
it should actually query the terminal, instead of hoping that the user would 
have told their shell to tell diffstat what the terminal size is.  If I have to 
manually send the COLUMNS variable to diffstat, it's no better than a command 
line option.  Exporting COLUMNS from the shell by default is a poor option, I 
think, because it can cause many programs you might launch from the shell to 
then not react to terminal size changes, as they will treat having it set as a 
request to override whatever the reported terminal size is.  I actually use 
that feature sometimes to make reading man pages easier in otherwise very large 
terminal windows.

If using the termcap type facilities is too "heavy weight" for diffstat, it 
could farm out to stty or some other program that does query the terminal size 
"properly".

Reply via email to