{"thread":{"id":"2870","subject":"Make \"git help\" react to window size correctly","startedAt":"2005-12-18T20:15:58Z","lastAt":"2005-12-18T20:15:58Z","messageCount":1,"participants":["Linus Torvalds"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"13790","messageId":"Pine.LNX.4.64.0512181211160.4827@g5.osdl.org","threadId":"2870","inReplyTo":null,"subject":"Make \"git help\" react to window size correctly","fromName":"Linus Torvalds","fromEmail":"torvalds@osdl.org","sentAt":"2005-12-18T20:15:58Z","receivedAt":"2005-12-18T20:15:58Z","isPatch":false,"sender":{"key":"torvalds@linux-foundation.org","avatar":"https://avatars.githubusercontent.com/u/1024025?v=4"},"body":"\nCurrently the git \"show commands\" function will react to the environment \nvariable COLUMNS, or just default to a width of 80 characters.\n\nThat's just soo eighties. Nobody sane sets COLUMNS any more, unless they \nneed to support some stone-age software from before the age of steam \nengines, SIGWINCH and TIOCGWINSZ.\n\nSo get with the new century, and use TIOCGWINSZ to get the terminal size.\n\nSigned-off-by: Linus Torvalds <torvalds@osdl.org>\n---\ndiff --git a/git.c b/git.c\nindex c26cac6..157c549 100644\n--- a/git.c\n+++ b/git.c\n@@ -8,6 +8,7 @@\n #include <errno.h>\n #include <limits.h>\n #include <stdarg.h>\n+#include <sys/ioctl.h>\n #include \"git-compat-util.h\"\n \n #ifndef PATH_MAX\n@@ -26,6 +27,16 @@ static int term_columns(void)\n \tif (col_string && (n_cols = atoi(col_string)) > 0)\n \t\treturn n_cols;\n \n+#ifdef TIOCGWINSZ\n+\t{\n+\t\tstruct winsize ws;\n+\t\tif (!ioctl(1, TIOCGWINSZ, &ws)) {\n+\t\t\tif (ws.ws_col)\n+\t\t\t\treturn ws.ws_col;\n+\t\t}\n+\t}\n+#endif\n+\n \treturn 80;\n }\n \n"}]}