Overview
Comment: | utils/ofhttp: Get terminal width for progress bar |
---|---|
Downloads: | Tarball | ZIP archive | SQL archive |
Timelines: | family | ancestors | descendants | both | trunk |
Files: | files | file ages | folders |
SHA3-256: |
84f2ba7fbcd34dab728f9840be3540c9 |
User & Date: | js on 2015-05-16 18:32:49 |
Other Links: | manifest | tags |
Context
2015-05-16
| ||
19:05 | configure: We still need -D_GNU_SOURCE check-in: 1807f33207 user: js tags: trunk | |
18:32 | utils/ofhttp: Get terminal width for progress bar check-in: 84f2ba7fbc user: js tags: trunk | |
18:28 | OFKernelEventObserver_poll: Exception -> assert check-in: 13d72034ed user: js tags: trunk | |
Changes
Modified configure.ac from [0f82546aef] to [360209fe98].
︙ | ︙ | |||
945 946 947 948 949 950 951 952 953 954 955 956 957 958 | ]) ;; 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]) ]) 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") AS_IF([test x"$enable_shared" != x"no"], [ | > > | 945 946 947 948 949 950 951 952 953 954 955 956 957 958 959 960 | ]) ;; 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") AS_IF([test x"$enable_shared" != x"no"], [ |
︙ | ︙ |
Modified utils/ofhttp/ProgressBar.m from [7133bd835c] to [54fb752c1d].
︙ | ︙ | |||
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 | * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this * file. */ #include "config.h" #include <math.h> #import "OFDate.h" #import "OFStdIOStream.h" #import "OFTimer.h" #import "ProgressBar.h" #define GIBIBYTE (1024 * 1024 * 1024) #define MEBIBYTE (1024 * 1024) #define KIBIBYTE (1024) | > > > > < | 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 | * LICENSE.GPLv2 or LICENSE.GPLv3 respectively included in the packaging of this * file. */ #include "config.h" #include <math.h> #ifdef HAVE_SYS_IOCTL_H # include <sys/ioctl.h> #endif #import "OFDate.h" #import "OFStdIOStream.h" #import "OFTimer.h" #import "ProgressBar.h" #define GIBIBYTE (1024 * 1024 * 1024) #define MEBIBYTE (1024 * 1024) #define KIBIBYTE (1024) #define UPDATE_INTERVAL 0.1 @implementation ProgressBar - initWithLength: (intmax_t)length resumedFrom: (intmax_t)resumedFrom { self = [super init]; |
︙ | ︙ | |||
79 80 81 82 83 84 85 86 87 | _received = received; } - (void)_drawProgress { uint_fast8_t i; float bars, percent; bars = (float)(_resumedFrom + _received) / | > > > > > > > > > | | | | | | | | | | | | 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 | _received = received; } - (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) * 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 < barWidth) { float remainder = bars - floorf(bars); if (remainder >= 0.875) [of_stdout writeString: @"▉"]; else if (remainder >= 0.75) [of_stdout writeString: @"▊"]; else if (remainder >= 0.625) [of_stdout writeString: @"▋"]; else if (remainder >= 0.5) [of_stdout writeString: @"▌"]; else if (remainder >= 0.375) [of_stdout writeString: @"▍"]; else if (remainder >= 0.25) [of_stdout writeString: @"▎"]; else if (remainder >= 0.125) [of_stdout writeString: @"▏"]; else [of_stdout writeString: @" "]; for (i = 0; i < barWidth - (uint_fast8_t)bars - 1; i++) [of_stdout writeString: @" "]; } [of_stdout writeFormat: @"▏ %6.2f%% ", percent]; if (percent == 100) _BPS = (float)_received / -[_startDate timeIntervalSinceNow]; |
︙ | ︙ |