Permalink
Browse files

Rewrite quiet mode

  • Loading branch information...
Kikobeats committed Apr 30, 2018
1 parent 2033bee commit 05c8dd93af982fcb4bd4bdfb833c38d1d56968ba
Showing with 11 additions and 6 deletions.
  1. +0 −1 bin/cli/index.js
  2. +3 −1 bin/view/index.js
  3. +8 −4 bin/view/render.js
@@ -76,7 +76,6 @@ if (isEmpty(cli.input)) {
const urls = await extractUrls(url, opts)
const emitter = await urlint(urls, opts)
console.log()
view({ total: size(urls), emitter, ...opts })
})()
@@ -7,13 +7,15 @@ const render = require('./render')
module.exports = ({ total, emitter, quiet, logspeed, ...opts }) => {
const state = {
quiet,
total,
current: 0,
count: {},
links: {},
end: false,
fetchingUrl: '',
startTimestamp: Date.now()
startTimestamp: Date.now(),
timestamp: {}
}
const neat = neatLog(render, { ...opts, logspeed, state })
@@ -28,7 +28,7 @@ const renderCount = state => {
const url = gray(fetchingUrl)
const progress = gray(`${current}/${total}`)
return `${countByStatusCode}${EOL}${EOL}${timestamp} ${spinnerFrame}${progress} ${url}`
return `${EOL}${countByStatusCode}${EOL}${EOL}${timestamp} ${spinnerFrame}${progress} ${url}`
}
const renderResume = ({ count, links }) => {
@@ -43,10 +43,14 @@ const renderResume = ({ count, links }) => {
const total = reduce(count, (acc, count) => acc + count, 0)
return gray(`${info}${EOL}Total ${total}`)
return gray(`${EOL}${info}${EOL}Total ${total}`)
}
module.exports = state => {
if (state.end) return renderResume(state)
if (state.quiet) return ''
return renderCount(state)
}
module.exports = state =>
state.end === false ? renderCount(state) : renderResume(state)
module.exports.count = renderCount
module.exports.resume = renderResume

0 comments on commit 05c8dd9

Please sign in to comment.