Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/torch/xlua.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSoumith Chintala <soumith@gmail.com>2015-02-12 04:17:03 +0300
committerSoumith Chintala <soumith@gmail.com>2015-02-12 04:17:03 +0300
commit24397ac3506e57dd05f48fedc9bbabe79c39f9d2 (patch)
tree613796c051b4590d3e8ce4c4c07003d09c744377
parentb41d77acb301d5f70cb60f798b543eb09fe019e7 (diff)
parentf18cce06e64f3aab73370470c9412e459290836f (diff)
Merge pull request #6 from adamlerer/master
Progress bar using terminal width
-rw-r--r--init.lua17
1 files changed, 13 insertions, 4 deletions
diff --git a/init.lua b/init.lua
index b29bc13..4357fd8 100644
--- a/init.lua
+++ b/init.lua
@@ -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