Fossil SCM
Auto-adjust the with of timeline (and various other output places) according to real terminal width. Suggested by Baptiste Daroussin.
Commit
c4891e24af9052db1ca824399baf468852ba9980
Parent
c5a0169786ea7dc…
5 files changed
+2
-1
+6
+6
+7
-1
+6
+2
-1
| --- src/config.h | ||
| +++ src/config.h | ||
| @@ -49,19 +49,20 @@ | ||
| 49 | 49 | #include <stdarg.h> |
| 50 | 50 | #include <assert.h> |
| 51 | 51 | |
| 52 | 52 | #endif |
| 53 | 53 | |
| 54 | -#if defined( __MINGW32__) || defined(__DMC__) || defined(_MSC_VER) || defined(__POCC__) | |
| 54 | +#if defined(__MINGW32__) || defined(__DMC__) || defined(_MSC_VER) || defined(__POCC__) | |
| 55 | 55 | # if defined(__DMC__) || defined(_MSC_VER) || defined(__POCC__) |
| 56 | 56 | typedef int socklen_t; |
| 57 | 57 | # endif |
| 58 | 58 | # ifndef _WIN32 |
| 59 | 59 | # define _WIN32 |
| 60 | 60 | # endif |
| 61 | 61 | #else |
| 62 | 62 | # include <sys/types.h> |
| 63 | +# include <termios.h> | |
| 63 | 64 | # include <signal.h> |
| 64 | 65 | # include <pwd.h> |
| 65 | 66 | #endif |
| 66 | 67 | |
| 67 | 68 | /* |
| 68 | 69 |
| --- src/config.h | |
| +++ src/config.h | |
| @@ -49,19 +49,20 @@ | |
| 49 | #include <stdarg.h> |
| 50 | #include <assert.h> |
| 51 | |
| 52 | #endif |
| 53 | |
| 54 | #if defined( __MINGW32__) || defined(__DMC__) || defined(_MSC_VER) || defined(__POCC__) |
| 55 | # if defined(__DMC__) || defined(_MSC_VER) || defined(__POCC__) |
| 56 | typedef int socklen_t; |
| 57 | # endif |
| 58 | # ifndef _WIN32 |
| 59 | # define _WIN32 |
| 60 | # endif |
| 61 | #else |
| 62 | # include <sys/types.h> |
| 63 | # include <signal.h> |
| 64 | # include <pwd.h> |
| 65 | #endif |
| 66 | |
| 67 | /* |
| 68 |
| --- src/config.h | |
| +++ src/config.h | |
| @@ -49,19 +49,20 @@ | |
| 49 | #include <stdarg.h> |
| 50 | #include <assert.h> |
| 51 | |
| 52 | #endif |
| 53 | |
| 54 | #if defined(__MINGW32__) || defined(__DMC__) || defined(_MSC_VER) || defined(__POCC__) |
| 55 | # if defined(__DMC__) || defined(_MSC_VER) || defined(__POCC__) |
| 56 | typedef int socklen_t; |
| 57 | # endif |
| 58 | # ifndef _WIN32 |
| 59 | # define _WIN32 |
| 60 | # endif |
| 61 | #else |
| 62 | # include <sys/types.h> |
| 63 | # include <termios.h> |
| 64 | # include <signal.h> |
| 65 | # include <pwd.h> |
| 66 | #endif |
| 67 | |
| 68 | /* |
| 69 |
+6
| --- src/descendants.c | ||
| +++ src/descendants.c | ||
| @@ -356,11 +356,17 @@ | ||
| 356 | 356 | width = atoi(zWidth); |
| 357 | 357 | if( (width!=0) && (width<=39) ){ |
| 358 | 358 | fossil_fatal("-W|--width value must be >39 or 0"); |
| 359 | 359 | } |
| 360 | 360 | }else{ |
| 361 | +#ifdef TIOCGWINSZ | |
| 362 | + struct winsize w; | |
| 363 | + ioctl(0, TIOCGWINSZ, &w); | |
| 364 | + width = w.ws_col; | |
| 365 | +#else | |
| 361 | 366 | width = 79; |
| 367 | +#endif | |
| 362 | 368 | } |
| 363 | 369 | db_find_and_open_repository(0,0); |
| 364 | 370 | if( recomputeFlag ) leaf_rebuild(); |
| 365 | 371 | blob_zero(&sql); |
| 366 | 372 | blob_append(&sql, timeline_query_for_tty(), -1); |
| 367 | 373 |
| --- src/descendants.c | |
| +++ src/descendants.c | |
| @@ -356,11 +356,17 @@ | |
| 356 | width = atoi(zWidth); |
| 357 | if( (width!=0) && (width<=39) ){ |
| 358 | fossil_fatal("-W|--width value must be >39 or 0"); |
| 359 | } |
| 360 | }else{ |
| 361 | width = 79; |
| 362 | } |
| 363 | db_find_and_open_repository(0,0); |
| 364 | if( recomputeFlag ) leaf_rebuild(); |
| 365 | blob_zero(&sql); |
| 366 | blob_append(&sql, timeline_query_for_tty(), -1); |
| 367 |
| --- src/descendants.c | |
| +++ src/descendants.c | |
| @@ -356,11 +356,17 @@ | |
| 356 | width = atoi(zWidth); |
| 357 | if( (width!=0) && (width<=39) ){ |
| 358 | fossil_fatal("-W|--width value must be >39 or 0"); |
| 359 | } |
| 360 | }else{ |
| 361 | #ifdef TIOCGWINSZ |
| 362 | struct winsize w; |
| 363 | ioctl(0, TIOCGWINSZ, &w); |
| 364 | width = w.ws_col; |
| 365 | #else |
| 366 | width = 79; |
| 367 | #endif |
| 368 | } |
| 369 | db_find_and_open_repository(0,0); |
| 370 | if( recomputeFlag ) leaf_rebuild(); |
| 371 | blob_zero(&sql); |
| 372 | blob_append(&sql, timeline_query_for_tty(), -1); |
| 373 |
+6
| --- src/search.c | ||
| +++ src/search.c | ||
| @@ -202,11 +202,17 @@ | ||
| 202 | 202 | width = atoi(zWidth); |
| 203 | 203 | if( (width!=0) && (width<=20) ){ |
| 204 | 204 | fossil_fatal("-W|--width value must be >20 or 0"); |
| 205 | 205 | } |
| 206 | 206 | }else{ |
| 207 | +#ifdef TIOCGWINSZ | |
| 208 | + struct winsize w; | |
| 209 | + ioctl(0, TIOCGWINSZ, &w); | |
| 210 | + width = w.ws_col; | |
| 211 | +#else | |
| 207 | 212 | width = 79; |
| 213 | +#endif | |
| 208 | 214 | } |
| 209 | 215 | |
| 210 | 216 | db_must_be_within_tree(); |
| 211 | 217 | if( g.argc<2 ) return; |
| 212 | 218 | blob_init(&pattern, g.argv[2], -1); |
| 213 | 219 |
| --- src/search.c | |
| +++ src/search.c | |
| @@ -202,11 +202,17 @@ | |
| 202 | width = atoi(zWidth); |
| 203 | if( (width!=0) && (width<=20) ){ |
| 204 | fossil_fatal("-W|--width value must be >20 or 0"); |
| 205 | } |
| 206 | }else{ |
| 207 | width = 79; |
| 208 | } |
| 209 | |
| 210 | db_must_be_within_tree(); |
| 211 | if( g.argc<2 ) return; |
| 212 | blob_init(&pattern, g.argv[2], -1); |
| 213 |
| --- src/search.c | |
| +++ src/search.c | |
| @@ -202,11 +202,17 @@ | |
| 202 | width = atoi(zWidth); |
| 203 | if( (width!=0) && (width<=20) ){ |
| 204 | fossil_fatal("-W|--width value must be >20 or 0"); |
| 205 | } |
| 206 | }else{ |
| 207 | #ifdef TIOCGWINSZ |
| 208 | struct winsize w; |
| 209 | ioctl(0, TIOCGWINSZ, &w); |
| 210 | width = w.ws_col; |
| 211 | #else |
| 212 | width = 79; |
| 213 | #endif |
| 214 | } |
| 215 | |
| 216 | db_must_be_within_tree(); |
| 217 | if( g.argc<2 ) return; |
| 218 | blob_init(&pattern, g.argv[2], -1); |
| 219 |
+7
-1
| --- src/stash.c | ||
| +++ src/stash.c | ||
| @@ -525,11 +525,17 @@ | ||
| 525 | 525 | width = atoi(zWidth); |
| 526 | 526 | if( (width!=0) && (width<=46) ){ |
| 527 | 527 | fossil_fatal("-W|--width value must be >46 or 0"); |
| 528 | 528 | } |
| 529 | 529 | }else{ |
| 530 | - width = 79; | |
| 530 | +#ifdef TIOCGWINSZ | |
| 531 | + struct winsize w; | |
| 532 | + ioctl(0, TIOCGWINSZ, &w); | |
| 533 | + width = w.ws_col; | |
| 534 | +#else | |
| 535 | + width = 79; | |
| 536 | +#endif | |
| 531 | 537 | } |
| 532 | 538 | if( !verboseFlag ){ |
| 533 | 539 | verboseFlag = find_option("detail","l",0)!=0; /* deprecated */ |
| 534 | 540 | } |
| 535 | 541 | verify_all_options(); |
| 536 | 542 |
| --- src/stash.c | |
| +++ src/stash.c | |
| @@ -525,11 +525,17 @@ | |
| 525 | width = atoi(zWidth); |
| 526 | if( (width!=0) && (width<=46) ){ |
| 527 | fossil_fatal("-W|--width value must be >46 or 0"); |
| 528 | } |
| 529 | }else{ |
| 530 | width = 79; |
| 531 | } |
| 532 | if( !verboseFlag ){ |
| 533 | verboseFlag = find_option("detail","l",0)!=0; /* deprecated */ |
| 534 | } |
| 535 | verify_all_options(); |
| 536 |
| --- src/stash.c | |
| +++ src/stash.c | |
| @@ -525,11 +525,17 @@ | |
| 525 | width = atoi(zWidth); |
| 526 | if( (width!=0) && (width<=46) ){ |
| 527 | fossil_fatal("-W|--width value must be >46 or 0"); |
| 528 | } |
| 529 | }else{ |
| 530 | #ifdef TIOCGWINSZ |
| 531 | struct winsize w; |
| 532 | ioctl(0, TIOCGWINSZ, &w); |
| 533 | width = w.ws_col; |
| 534 | #else |
| 535 | width = 79; |
| 536 | #endif |
| 537 | } |
| 538 | if( !verboseFlag ){ |
| 539 | verboseFlag = find_option("detail","l",0)!=0; /* deprecated */ |
| 540 | } |
| 541 | verify_all_options(); |
| 542 |
+6
| --- src/timeline.c | ||
| +++ src/timeline.c | ||
| @@ -1780,11 +1780,17 @@ | ||
| 1780 | 1780 | width = atoi(zWidth); |
| 1781 | 1781 | if( (width!=0) && (width<=20) ){ |
| 1782 | 1782 | fossil_fatal("-W|--width value must be >20 or 0"); |
| 1783 | 1783 | } |
| 1784 | 1784 | }else{ |
| 1785 | +#ifdef TIOCGWINSZ | |
| 1786 | + struct winsize w; | |
| 1787 | + ioctl(0, TIOCGWINSZ, &w); | |
| 1788 | + width = w.ws_col; | |
| 1789 | +#else | |
| 1785 | 1790 | width = 79; |
| 1791 | +#endif | |
| 1786 | 1792 | } |
| 1787 | 1793 | zOffset = find_option("offset",0,1); |
| 1788 | 1794 | iOffset = zOffset ? atoi(zOffset) : 0; |
| 1789 | 1795 | if( g.argc>=4 ){ |
| 1790 | 1796 | k = strlen(g.argv[2]); |
| 1791 | 1797 |
| --- src/timeline.c | |
| +++ src/timeline.c | |
| @@ -1780,11 +1780,17 @@ | |
| 1780 | width = atoi(zWidth); |
| 1781 | if( (width!=0) && (width<=20) ){ |
| 1782 | fossil_fatal("-W|--width value must be >20 or 0"); |
| 1783 | } |
| 1784 | }else{ |
| 1785 | width = 79; |
| 1786 | } |
| 1787 | zOffset = find_option("offset",0,1); |
| 1788 | iOffset = zOffset ? atoi(zOffset) : 0; |
| 1789 | if( g.argc>=4 ){ |
| 1790 | k = strlen(g.argv[2]); |
| 1791 |
| --- src/timeline.c | |
| +++ src/timeline.c | |
| @@ -1780,11 +1780,17 @@ | |
| 1780 | width = atoi(zWidth); |
| 1781 | if( (width!=0) && (width<=20) ){ |
| 1782 | fossil_fatal("-W|--width value must be >20 or 0"); |
| 1783 | } |
| 1784 | }else{ |
| 1785 | #ifdef TIOCGWINSZ |
| 1786 | struct winsize w; |
| 1787 | ioctl(0, TIOCGWINSZ, &w); |
| 1788 | width = w.ws_col; |
| 1789 | #else |
| 1790 | width = 79; |
| 1791 | #endif |
| 1792 | } |
| 1793 | zOffset = find_option("offset",0,1); |
| 1794 | iOffset = zOffset ? atoi(zOffset) : 0; |
| 1795 | if( g.argc>=4 ){ |
| 1796 | k = strlen(g.argv[2]); |
| 1797 |