{"thread":{"id":"28224","subject":"[RFC PATCH] diff: use $COLUMNS if available for default stat_width","startedAt":"2011-08-26T05:47:27Z","lastAt":"2011-08-26T11:20:30Z","messageCount":2,"participants":["Kris Shannon","Mikael Magnusson"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"174300","messageId":"1314337647-29270-1-git-send-email-kris@shannon.id.au","threadId":"28224","inReplyTo":null,"subject":"[RFC PATCH] diff: use $COLUMNS if available for default stat_width","fromName":"Kris Shannon","fromEmail":"kris@shannon.id.au","sentAt":"2011-08-26T05:47:27Z","receivedAt":"2011-08-26T05:47:27Z","isPatch":true,"sender":{"key":"kris@shannon.id.au","avatar":"https://gravatar.com/avatar/13a7c0b3c50ffacf54f456e543023fd702898bb134165fa805f019930524151f?d=mp&s=160"},"body":"If the COLUMNS environment variable is set use it's value\nas the default stat_width.\n\nAlso set the stat_name_width default to 2/3 of the full width.\n\nThis does change the default from 50 to 53 when using the\noriginal 80 column stat_width fallback.\n\nSigned-off-by: Kris Shannon <kris@shannon.id.au>\n---\n diff.c |   12 ++++++++++--\n 1 files changed, 10 insertions(+), 2 deletions(-)\n\nThis has bugged me for a long time.  I finally decided to see how hard it would\nbe to fix.\n\nI thought about getting the COLUMNS value once but I'm not sure it's worth the\nextra code.\n\ndiff --git a/diff.c b/diff.c\nindex 9038f19..6954134 100644\n--- a/diff.c\n+++ b/diff.c\n@@ -1329,8 +1329,16 @@ static void show_stats(struct diffstat_t *data, struct diff_options *options)\n \t\tline_prefix = msg->buf;\n \t}\n \n-\twidth = options->stat_width ? options->stat_width : 80;\n-\tname_width = options->stat_name_width ? options->stat_name_width : 50;\n+\twidth = options->stat_width;\n+\tif (!width) {\n+\t\tchar *cols = getenv(\"COLUMNS\");\n+\n+\t\tif (cols)\n+\t\t\twidth = strtoul(cols, NULL, 10);\n+\t\tif (!width)\n+\t\t\twidth = 80;\n+\t}\n+\tname_width = options->stat_name_width ? options->stat_name_width : ((width * 2 + 1) / 3);\n \n \t/* Sanity: give at least 5 columns to the graph,\n \t * but leave at least 10 columns for the name.\n-- \n1.7.6.1\n"},{"id":"174311","messageId":"CAHYJk3Rw0i5uNW1vyd--OS4G6Pp2kNOA3aKUucWNrDgfQkYRkA@mail.gmail.com","threadId":"28224","inReplyTo":"1314337647-29270-1-git-send-email-kris@shannon.id.au","subject":"Re: [RFC PATCH] diff: use $COLUMNS if available for default stat_width","fromName":"Mikael Magnusson","fromEmail":"mikachu@gmail.com","sentAt":"2011-08-26T11:20:30Z","receivedAt":"2011-08-26T11:20:30Z","isPatch":true,"sender":{"key":"mikachu@gmail.com","avatar":null},"body":"On 26 August 2011 07:47, Kris Shannon <kris@shannon.id.au> wrote:\n> If the COLUMNS environment variable is set use it's value\n> as the default stat_width.\n>\n> Also set the stat_name_width default to 2/3 of the full width.\n>\n> This does change the default from 50 to 53 when using the\n> original 80 column stat_width fallback.\n\nYou probably only want to do this when stdout is a terminal.\n\n-- \nMikael Magnusson\n"}]}