diff --git a/Gruntfile.js b/Gruntfile.js index 28da601..2767de9 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -47,8 +47,13 @@ module.exports = function(grunt) grunt.loadNpmTasks('grunt-contrib-jshint'); grunt.loadNpmTasks('grunt-contrib-clean'); grunt.loadNpmTasks('grunt-contrib-nodeunit'); + + grunt.registerTask('unset_clearline', 'Unset stdout.clearLine for testing', function(){ + process.stdout.clearLine = undefined; + }); grunt.registerTask('test', ['clean', 'svg2png', 'nodeunit']); + grunt.registerTask('test_noterminal', ['unset_clearline', 'test']); grunt.registerTask('default', ['jshint', 'test']); }; diff --git a/tasks/svg2png.js b/tasks/svg2png.js index 32dd754..560923d 100644 --- a/tasks/svg2png.js +++ b/tasks/svg2png.js @@ -79,10 +79,14 @@ module.exports = function(grunt) if (!total) { return; } - - process.stdout.clearLine(); - process.stdout.cursorTo(0); - + + var hasTerminal = !!process.stdout.clearLine; + + if (hasTerminal) { + process.stdout.clearLine(); + process.stdout.cursorTo(0); + } + var str = style('0%', 'yellow') + ' [ ', arr = [], count = total, @@ -93,7 +97,8 @@ module.exports = function(grunt) } str += arr.reverse().join(''); str += ' ] ' + style(percent + "%", 'green') + ' (' + ((new Date() - start) / 1000).toFixed(1) + 's) '; - process.stdout.write(str); + + process.stdout.write(str + (hasTerminal ? '' : "\n")); }; var spawn = grunt.util.spawn({