From c1dde6053030dfab0f21852d3d75336479907c57 Mon Sep 17 00:00:00 2001 From: Joe Hand Date: Tue, 3 Jul 2018 17:09:43 -0700 Subject: [PATCH] Update neat log to use new diffy (#1010) * change outputs to fn * use neat-log diffy version * fix exit stuff * update neat-log * add clear, update neat-log * fix create output --- package.json | 2 +- src/commands/create.js | 8 ++++---- src/lib/discovery-exit.js | 4 ++-- src/lib/exit.js | 2 +- src/ui/archive.js | 4 ++-- src/ui/components/download.js | 4 ++-- src/ui/components/import-progress.js | 16 ++++++++-------- src/ui/components/network.js | 4 ++-- src/ui/components/sources.js | 4 ++-- src/ui/create.js | 8 ++++---- src/ui/status.js | 4 ++-- 11 files changed, 30 insertions(+), 30 deletions(-) diff --git a/package.json b/package.json index a6354479..0e8ef342 100644 --- a/package.json +++ b/package.json @@ -47,7 +47,7 @@ "dat-node": "^3.5.5", "dat-registry": "^4.0.0", "debug": "^3.0.0", - "neat-log": "^1.1.0", + "neat-log": "^2.4.0", "prettier-bytes": "^1.0.3", "progress-string": "^1.2.1", "prompt": "^1.0.0", diff --git a/src/commands/create.js b/src/commands/create.js index e2d571d3..ea234a9a 100644 --- a/src/commands/create.js +++ b/src/commands/create.js @@ -34,7 +34,7 @@ function create (opts) { } var welcome = `Welcome to ${chalk.green(`dat`)} program!` - var intro = output` + var intro = output(` You can turn any folder on your computer into a Dat. A Dat is a folder with some magic. @@ -46,7 +46,7 @@ function create (opts) { ${chalk.dim('Ctrl+C to exit at any time')} - ` + `) var outro // Force certain options @@ -57,7 +57,7 @@ function create (opts) { if (err && err.name === 'ExistsError') return exitErr('\nArchive already exists.\nYou can use `dat sync` to update.') if (err) return exitErr(err) - outro = output` + outro = output(` Created empty Dat in ${dat.path}/.dat @@ -66,7 +66,7 @@ function create (opts) { * Copy the unique dat link and securely share it. ${chalk.blue(`dat://${dat.key.toString('hex')}`)} - ` + `) if (opts.yes) return done() diff --git a/src/lib/discovery-exit.js b/src/lib/discovery-exit.js index 56ed2271..7da23640 100644 --- a/src/lib/discovery-exit.js +++ b/src/lib/discovery-exit.js @@ -8,12 +8,12 @@ function discoveryExit (state, bus) { function checkExit () { if (state.dat.network.connected || !state.opts.exit) return if (state.dat.network.connecting) return setTimeout(checkExit, 500) // wait to see if any connections resolve - var msg = output` + var msg = output(` Dat could not find any connections for that link. There may not be any sources online. Run 'dat doctor' if you keep having trouble. - ` + `) bus.emit('exit:warn', msg) } } diff --git a/src/lib/exit.js b/src/lib/exit.js index 2b24cf7d..b06ab86a 100644 --- a/src/lib/exit.js +++ b/src/lib/exit.js @@ -6,7 +6,7 @@ function onExit (state, bus) { bus.on('exit:warn', function (err) { onError(err, true) }) - process.on('SIGINT', function () { + bus.on('exit', function () { state.exiting = true bus.render() process.exit() diff --git a/src/ui/archive.js b/src/ui/archive.js index 5d9d449e..7c9d8a8a 100644 --- a/src/ui/archive.js +++ b/src/ui/archive.js @@ -45,7 +45,7 @@ function archiveUI (state) { } } - return output` + return output(` ${version(pkg.version)} ${title} ${state.joinNetwork ? '\n' + networkUI(state) : ''} @@ -54,5 +54,5 @@ function archiveUI (state) { ${state.opts.sources ? sourcesUI(state) : ''} ${state.warnings ? warningsUI(state) : ''} ${state.exiting ? 'Exiting the Dat program...' : chalk.dim('Ctrl+C to Exit')} - ` + `) } diff --git a/src/ui/components/download.js b/src/ui/components/download.js index 0c287377..3c779dd8 100644 --- a/src/ui/components/download.js +++ b/src/ui/components/download.js @@ -30,10 +30,10 @@ function networkUI (state) { return '' // no metadata yet } - return output` + return output(` ${title} ${downBar(stats.downloaded)} - ` + `) function makeBar () { var total = stats.length diff --git a/src/ui/components/import-progress.js b/src/ui/components/import-progress.js index 7a742b5e..0fbd193c 100644 --- a/src/ui/components/import-progress.js +++ b/src/ui/components/import-progress.js @@ -13,11 +13,11 @@ function importUI (state) { if (importState.count && !importState.count.done) { // dry run in progress if (!importState.count.files) return 'Checking for file updates...' - return output` + return output(` Metadata created for ${importState.putDone.files} of ${importState.count.files} files ${indexSpeed} (Calculating file count...) ${fileImport(importState.fileImport)} - ` + `) } else if (importState.putDone.files >= importState.count.files) { // Initial import done if (!watch) return 'Archive metadata updated for all files.' @@ -32,19 +32,19 @@ function importUI (state) { } }) - return output` + return output(` Creating metadata for ${importState.count.files} files ${indexSpeed} ${totalBar(importState.importedBytes)} ${fileImport(importState.fileImport)} - ` + `) function liveImport () { // Live import var imports = importState.liveImports.slice(1).slice(-7) - return output` + return output(` Watching for file updates ${imports.reverse().map(function (file) { return fileImport(file) }).join('\n')} - ` + `) } function fileImport (file) { @@ -58,8 +58,8 @@ function importUI (state) { // >500 mb show progress if (total < 5e8 || !file.progress) size = `(${pretty(total)})` else size = `(${pretty(file.progress)} / ${pretty(total)})` - return output` + return output(` ADD: ${cliTruncate(name, process.stdout.columns - 7 - size.length, {position: 'start'})} ${size} - ` + `) } } diff --git a/src/ui/components/network.js b/src/ui/components/network.js index 2db0a4ea..34a3d077 100644 --- a/src/ui/components/network.js +++ b/src/ui/components/network.js @@ -11,9 +11,9 @@ function networkUI (state) { if (!network) return '' var peers = stats.peers.total || 0 // var complete = stats.peers.complete - return output` + return output(` ${peers} ${pluralize('connection', peers)} ${speedUI()} - ` + `) function speedUI () { var output = '| ' diff --git a/src/ui/components/sources.js b/src/ui/components/sources.js index d06d7cf6..47f118e9 100644 --- a/src/ui/components/sources.js +++ b/src/ui/components/sources.js @@ -27,9 +27,9 @@ function peersUI (state) { } }) var theBar = progress ? bar(progress) : '' // progress bar todo - return output` + return output(` [${i}] ${peer.closed ? 'CLOSED' : peer.type}: ${peer.host}:${peer.port} ${pretty(peer.speed)}/s ${peer.error ? peer.error : theBar} - ` + `) } } diff --git a/src/ui/create.js b/src/ui/create.js index 542a1429..b53ec25c 100644 --- a/src/ui/create.js +++ b/src/ui/create.js @@ -9,9 +9,9 @@ module.exports = createUI function createUI (state) { if (!state.dat) { - return output` + return output(` Creating a Dat! Add information to your dat.json file: - ` + `) } var dat = state.dat @@ -42,10 +42,10 @@ function createUI (state) { progressView = 'Not importing files.' } - return output` + return output(` ${title} ${progressView} ${state.exiting ? exitMsg : chalk.dim('Ctrl+C to Exit')} - ` + `) } diff --git a/src/ui/status.js b/src/ui/status.js index f409b7ff..71b86896 100644 --- a/src/ui/status.js +++ b/src/ui/status.js @@ -11,9 +11,9 @@ function statusUI (state) { var dat = state.dat var stats = dat.stats.get() - return output` + return output(` ${chalk.blue('dat://' + stringKey(dat.key))} ${stats.files} files (${pretty(stats.byteLength)}) Version: ${chalk.bold(stats.version)} - ` + `) }