diff options
author | Soumith Chintala <soumith@gmail.com> | 2015-02-12 04:17:03 +0300 |
---|---|---|
committer | Soumith Chintala <soumith@gmail.com> | 2015-02-12 04:17:03 +0300 |
commit | 24397ac3506e57dd05f48fedc9bbabe79c39f9d2 (patch) | |
tree | 613796c051b4590d3e8ce4c4c07003d09c744377 | |
parent | b41d77acb301d5f70cb60f798b543eb09fe019e7 (diff) | |
parent | f18cce06e64f3aab73370470c9412e459290836f (diff) |
Merge pull request #6 from adamlerer/master
Progress bar using terminal width
-rw-r--r-- | init.lua | 17 |
1 files changed, 13 insertions, 4 deletions
@@ -229,15 +229,24 @@ end -- progress bar ---------------------------------------------------------------------- do + local function getTermLength() + local tputf = glob.io.popen('tput cols', 'r') + local w = glob.tonumber(tputf:read('*a')) + local rc = {tputf:close()} + if rc[3] == 0 then return w + else return 80 end + end + local barDone = true local previous = -1 local tm = '' local timer local times local indices + local termLength = getTermLength() function progress(current, goal) -- defaults: - local barLength = 77 + local barLength = termLength - 34 local smoothing = 100 local maxfps = 10 @@ -267,9 +276,9 @@ do else glob.io.write('.') end end glob.io.write('] ') + for i=1,termLength-barLength-4 do glob.io.write(' ') end + for i=1,termLength-barLength-4 do glob.io.write('\b') end -- time stats - for i=1,#tm do glob.io.write(' ') end - for i=1,#tm do glob.io.write('\b') end local elapsed = timer:time().real local step = (elapsed-times[1]) / (current-indices[1]) if current==indices[1] then step = 0 end @@ -283,7 +292,7 @@ do tm = 'ETA: ' .. formatTime(remaining) .. ' | Step: ' .. formatTime(step) glob.io.write(tm) -- go back to center of bar, and print progress - for i=1,47+#tm do glob.io.write('\b') end + for i=1,6+#tm+barLength/2 do glob.io.write('\b') end glob.io.write(' ', current, '/', goal, ' ') -- reset for next bar if (percent == barLength) then |