From 31b89477cf4004b99d4c6ef9124792367eb4bb4f Mon Sep 17 00:00:00 2001 From: Joe Hand Date: Thu, 2 Feb 2017 13:37:59 -0800 Subject: [PATCH] improve progress UI --- lib/share.js | 4 ++-- lib/ui/import-progress.js | 5 ++++- 2 files changed, 6 insertions(+), 3 deletions(-) diff --git a/lib/share.js b/lib/share.js index eabbfd4..f9a8c46 100644 --- a/lib/share.js +++ b/lib/share.js @@ -73,7 +73,7 @@ module.exports = function sync (type, opts, dat) { if (dat.owner && opts.import) { debug('Importing updated & new files into archive') // File Imports - progressOutput[2] = 'Importing new & updated files to archive...' + progressOutput[2] = 'Importing files...' importStatus = dat.importFiles({ watch: opts.watch, // TODO: allow live: true. opts.live is used by archive.live though =( @@ -125,7 +125,7 @@ module.exports = function sync (type, opts, dat) { } function updateImport () { - progressOutput[2] = importUI(importStatus) + progressOutput[3] = importUI(importStatus) } function updateNetwork () { diff --git a/lib/ui/import-progress.js b/lib/ui/import-progress.js index 85b4d5f..88516f7 100644 --- a/lib/ui/import-progress.js +++ b/lib/ui/import-progress.js @@ -1,11 +1,14 @@ var Bar = require('./bar') +var prettyBytes = require('pretty-bytes') module.exports = function () { var bar = Bar() + var start = Date.now() return function (importer) { if (!importer || !importer.bytesImported) return '' var importedBytes = importer.bytesImported + var speed = importer.bytesImported * 1000 / (Date.now() - start) var progress = Math.round(importedBytes * 100 / importer.countStats.bytes) - return bar(progress) + ` ${importer.fileCount} ${importer.fileCount === 1 ? 'file' : 'files'} imported` + return bar(progress) + ` ${importer.fileCount} of ${importer.countStats.files} ${importer.countStats.files === 1 ? 'file' : 'files'}` + ' (' + prettyBytes(speed) + '/s' + ')' } }