* [RFC PATCH] diff: use $COLUMNS if available for default stat_width
@ 2011-08-26 5:47 Kris Shannon
2011-08-26 11:20 ` Mikael Magnusson
0 siblings, 1 reply; 2+ messages in thread
From: Kris Shannon @ 2011-08-26 5:47 UTC (permalink / raw)
To: Git Mailing List; +Cc: Junio C Hamano
If the COLUMNS environment variable is set use it's value
as the default stat_width.
Also set the stat_name_width default to 2/3 of the full width.
This does change the default from 50 to 53 when using the
original 80 column stat_width fallback.
Signed-off-by: Kris Shannon <kris@shannon.id.au>
---
diff.c | 12 ++++++++++--
1 files changed, 10 insertions(+), 2 deletions(-)
This has bugged me for a long time. I finally decided to see how hard it would
be to fix.
I thought about getting the COLUMNS value once but I'm not sure it's worth the
extra code.
diff --git a/diff.c b/diff.c
index 9038f19..6954134 100644
--- a/diff.c
+++ b/diff.c
@@ -1329,8 +1329,16 @@ static void show_stats(struct diffstat_t *data, struct diff_options *options)
line_prefix = msg->buf;
}
- width = options->stat_width ? options->stat_width : 80;
- name_width = options->stat_name_width ? options->stat_name_width : 50;
+ width = options->stat_width;
+ if (!width) {
+ char *cols = getenv("COLUMNS");
+
+ if (cols)
+ width = strtoul(cols, NULL, 10);
+ if (!width)
+ width = 80;
+ }
+ name_width = options->stat_name_width ? options->stat_name_width : ((width * 2 + 1) / 3);
/* Sanity: give at least 5 columns to the graph,
* but leave at least 10 columns for the name.
--
1.7.6.1
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [RFC PATCH] diff: use $COLUMNS if available for default stat_width
2011-08-26 5:47 [RFC PATCH] diff: use $COLUMNS if available for default stat_width Kris Shannon
@ 2011-08-26 11:20 ` Mikael Magnusson
0 siblings, 0 replies; 2+ messages in thread
From: Mikael Magnusson @ 2011-08-26 11:20 UTC (permalink / raw)
To: Kris Shannon; +Cc: Git Mailing List, Junio C Hamano
On 26 August 2011 07:47, Kris Shannon <kris@shannon.id.au> wrote:
> If the COLUMNS environment variable is set use it's value
> as the default stat_width.
>
> Also set the stat_name_width default to 2/3 of the full width.
>
> This does change the default from 50 to 53 when using the
> original 80 column stat_width fallback.
You probably only want to do this when stdout is a terminal.
--
Mikael Magnusson
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2011-08-26 11:20 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2011-08-26 5:47 [RFC PATCH] diff: use $COLUMNS if available for default stat_width Kris Shannon
2011-08-26 11:20 ` Mikael Magnusson
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).