diff options
Diffstat (limited to 'etc')
-rw-r--r-- | etc/get.lua | 10 |
1 files changed, 6 insertions, 4 deletions
diff --git a/etc/get.lua b/etc/get.lua index ebf3e75..09f639d 100644 --- a/etc/get.lua +++ b/etc/get.lua | |||
@@ -65,21 +65,23 @@ end | |||
65 | -- kind of copied from luasocket's manual callback examples | 65 | -- kind of copied from luasocket's manual callback examples |
66 | function stats(size) | 66 | function stats(size) |
67 | local start = socket.gettime() | 67 | local start = socket.gettime() |
68 | local last = start | ||
68 | local got = 0 | 69 | local got = 0 |
69 | return function(chunk) | 70 | return function(chunk) |
70 | -- elapsed time since start | 71 | -- elapsed time since start |
71 | local delta = socket.gettime() - start | 72 | local current = socket.gettime() |
72 | if chunk then | 73 | if chunk then |
73 | -- total bytes received | 74 | -- total bytes received |
74 | got = got + string.len(chunk) | 75 | got = got + string.len(chunk) |
75 | -- not enough time for estimate | 76 | -- not enough time for estimate |
76 | if delta > 0.1 then | 77 | if current - last > 1 then |
77 | io.stderr:write("\r", gauge(got, delta, size)) | 78 | io.stderr:write("\r", gauge(got, current - start, size)) |
78 | io.stderr:flush() | 79 | io.stderr:flush() |
80 | last = current | ||
79 | end | 81 | end |
80 | else | 82 | else |
81 | -- close up | 83 | -- close up |
82 | io.stderr:write("\r", gauge(got, delta), "\n") | 84 | io.stderr:write("\r", gauge(got, current - start), "\n") |
83 | end | 85 | end |
84 | return chunk | 86 | return chunk |
85 | end | 87 | end |