On 08.08.2022 03:08, Keith Thompson wrote:
> Janis Papanagnou <
janis_pa...@hotmail.com> writes:
>> When using a side-by-side diff output with GNU diff(1) it just
>> occurred to me that the output didn't fit on the screen window
>> and I saw that there's a somewhat strange or arbitrary default
>> width of 130 columns defined
>>
>> -y, --side-by-side
>> -W, --width=NUM
>> output at most NUM (default 130) print columns
>>
>> Is there a reason for a number like that; I mean I'd have (if
>> only for historical reasons) expected, say, a value of 80, or,
>> since "any default value is wrong" considering diff to take the
>> actual display width as default (if not specified by the user).
>>
>> It's no issue, but I was surprised about that default.
>
> As discussed, VT100-based terminals and line printers commonly have a
> 132-column mode. 80 columns is likely to be too narrow for a
> side-by-side diff. When the option was first added, it's likely that 80
> and 132 columns were the only options on a lot of systems.
I'm aware of that, that's why I wrote elsethread "-W80, -W132, -W160",
with 160 to mean two screen contents side by side, which might also
be a [non-]"sensible" default.
I still think that any fixed default number is arbitrary and can only
be wrong (wrong = correct only by coincidence).
(On Unix systems we have such defaults in other places as well.)
>
> I think there's a strong hesitancy to make a text-processing command's
> behavior depend on the current terminal characteristics. `ls` using
> columns when writing to a tty is a notable exception.
There's yet more commands than that; pr(1) immediately comes to mind.
>
> It might be nice for diff to have an option to check the terminal width
> itself, but as you say downthread you can roll your own:
>
> diff -W$(tput cols) -y ...
The point is that making that a default will be "correct" for any
terminal size (as opposed to one hard coded value that can anyway
be simply specified as all the other arbitrary constant values).
(If one wants any fixed value it can be written in compact form.)
>
> Another useful option might be to use the actual maximum widths of the
> input files (and again, you can roll your own).
I think taking the maximum width of data/file contents might not
be a good choice. Think about the consequences!
Usually it's the physical display that you see that should be the
limiting factor. (Whether line-wraps or truncation is appropriate
in that case could be defined by an option. See also "pr -<N>",
vim: set nowrap, and other data displaying programs.)
But as it is with design issues that are already implemented;
changing that now would break code that relies on that. <sigh>
Janis