@@ -8,21 +8,24 @@ var ui = require('../lib/ui')
88module . exports = function ( args ) {
99 if ( args && args . exit ) args . upload = false
1010 var dat = Dat ( args )
11- var log = logger ( args )
11+
12+ var messages = [ ]
13+ var progressLines = [ ]
14+ var log = logger ( [ messages , progressLines ] , { debug : args . debug , quiet : args . quiet } )
1215
1316 var downloadTxt = 'Downloading '
1417 var finished = false
1518
1619 dat . stats . rateUp = speedometer ( )
1720 dat . stats . rateDown = speedometer ( )
1821
19- log . status ( 'Starting Dat...\n' , 0 )
20- log . status ( 'Connecting...' , 1 )
22+ progressLines [ 0 ] = 'Starting Dat...\n'
23+ progressLines [ 1 ] = 'Connecting...'
2124
2225 dat . on ( 'error' , onerror )
2326
2427 dat . open ( function ( ) {
25- log . message ( 'Downloading in ' + dat . dir + '\n' )
28+ messages . push ( 'Downloading in ' + dat . dir + '\n' )
2629 dat . download ( function ( err ) {
2730 if ( err ) onerror ( err )
2831 } )
@@ -35,7 +38,7 @@ module.exports = function (args) {
3538 } )
3639
3740 dat . once ( 'key' , function ( key ) {
38- log . message ( ui . keyMsg ( key ) )
41+ messages . push ( ui . keyMsg ( key ) )
3942 if ( args . quiet ) console . log ( ui . keyMsg ( key ) )
4043 } )
4144
@@ -53,7 +56,7 @@ module.exports = function (args) {
5356 finished = false
5457 dat . stats . rateDown = speedometer ( )
5558 updateStats ( )
56- log . status ( '' , - 1 ) // remove download finished message
59+ progressLines [ 2 ] = '' // remove download finished message
5760 } )
5861 dat . on ( 'file-downloaded' , updateStats )
5962
@@ -62,16 +65,16 @@ module.exports = function (args) {
6265 dat . stats . rateDown = 0
6366 updateStats ( )
6467 if ( args . exit ) {
65- log . status ( '' , 1 )
68+ progressLines [ 1 ] = '' // clear swarm info before exiting
6669 process . exit ( 0 )
6770 }
68- log . status ( '\nDownload Finished. You may exit the process with Ctrl-C.' , - 1 )
71+ progressLines [ 2 ] = '\nDownload Finished. You may exit the process with Ctrl-C.'
6972 } )
7073
7174 dat . on ( 'swarm-update' , printSwarm )
7275
7376 function printSwarm ( ) {
74- log . status ( ui . swarmMsg ( dat ) , 1 )
77+ progressLines [ 1 ] = ui . swarmMsg ( dat )
7578 }
7679
7780 function updateStats ( ) {
@@ -83,7 +86,7 @@ module.exports = function (args) {
8386 }
8487 msg += ' ' + downloadTxt + chalk . bold ( stats . filesTotal ) + ' items'
8588 msg += chalk . dim ( ' (' + prettyBytes ( stats . bytesProgress ) + '/' + prettyBytes ( stats . bytesTotal ) + ')' )
86- log . status ( msg + '\n' , 0 )
89+ progressLines [ 0 ] = msg + '\n'
8790 }
8891}
8992
0 commit comments