Index: configure.ac ================================================================== --- configure.ac +++ configure.ac @@ -947,10 +947,12 @@ esac AS_IF([test x"$have_processes" = x"yes"], [ AC_SUBST(OFPROCESS_M, "OFProcess.m") AC_DEFINE(OF_HAVE_PROCESSES, 1, [Whether we have processes]) ]) + +AC_CHECK_HEADERS(sys/ioctl.h) AS_IF([test x"$objc_runtime" = x"Apple runtime"], [ AC_CHECK_HEADER(Foundation/NSObject.h, [ AC_SUBST(FOUNDATION_COMPAT_M, "foundation-compat.m") AC_SUBST(BRIDGE, "bridge") Index: utils/ofhttp/ProgressBar.m ================================================================== --- utils/ofhttp/ProgressBar.m +++ utils/ofhttp/ProgressBar.m @@ -15,10 +15,14 @@ */ #include "config.h" #include + +#ifdef HAVE_SYS_IOCTL_H +# include +#endif #import "OFDate.h" #import "OFStdIOStream.h" #import "OFTimer.h" @@ -26,11 +30,10 @@ #define GIBIBYTE (1024 * 1024 * 1024) #define MEBIBYTE (1024 * 1024) #define KIBIBYTE (1024) -#define BAR_WIDTH 52 #define UPDATE_INTERVAL 0.1 @implementation ProgressBar - initWithLength: (intmax_t)length resumedFrom: (intmax_t)resumedFrom @@ -81,41 +84,50 @@ - (void)_drawProgress { uint_fast8_t i; float bars, percent; + unsigned short barWidth; +#ifdef HAVE_SYS_IOCTL_H + struct winsize ws; + + if (ioctl(0, TIOCGWINSZ, &ws) == 0) + barWidth = ws.ws_col - 28; + else +#endif + barWidth = 52; bars = (float)(_resumedFrom + _received) / - (_resumedFrom + _length) * BAR_WIDTH; + (_resumedFrom + _length) * barWidth; percent = (float)(_resumedFrom + _received) / (_resumedFrom + _length) * 100; [of_stdout writeString: @"\r ▕"]; for (i = 0; i < (uint_fast8_t)bars; i++) [of_stdout writeString: @"█"]; - if (bars < BAR_WIDTH) { - float rest = bars - floorf(bars); + if (bars < barWidth) { + float remainder = bars - floorf(bars); - if (rest >= 0.875) + if (remainder >= 0.875) [of_stdout writeString: @"▉"]; - else if (rest >= 0.75) + else if (remainder >= 0.75) [of_stdout writeString: @"▊"]; - else if (rest >= 0.625) + else if (remainder >= 0.625) [of_stdout writeString: @"▋"]; - else if (rest >= 0.5) + else if (remainder >= 0.5) [of_stdout writeString: @"▌"]; - else if (rest >= 0.375) + else if (remainder >= 0.375) [of_stdout writeString: @"▍"]; - else if (rest >= 0.25) + else if (remainder >= 0.25) [of_stdout writeString: @"▎"]; - else if (rest >= 0.125) + else if (remainder >= 0.125) [of_stdout writeString: @"▏"]; else [of_stdout writeString: @" "]; - for (i = 0; i < BAR_WIDTH - (uint_fast8_t)bars - 1; i++) + for (i = 0; i < barWidth - (uint_fast8_t)bars - 1; i++) [of_stdout writeString: @" "]; } [of_stdout writeFormat: @"▏ %6.2f%% ", percent];