« get me outta code hell

general-util.js « src - http-music - Command-line music player + utils (not a server!)
about summary refs log tree commit diff
path: root/src/general-util.js
blob: 67f53e33e66796d2b52ed3a55306bc87319c1893 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
module.exports.showTrackProcessStatus = function(
  total, doneCount, noLineBreak = false
) {
  // Log a status line which tells how many tracks are processed and what
  // percent is completed. (Uses non-specific language: it doesn't say
  // "how many tracks downloaded" or "how many tracks processed", but
  // rather, "how many tracks completed".) Pass noLineBreak = true to skip
  // the \n character (you'll probably also want to log \r after).

  const percent = Math.trunc(doneCount / total * 10000) / 100
  process.stdout.write(
    `\x1b[1m${percent}% completed ` +
    `(${doneCount}/${total} tracks)\x1b[0m` +
    (noLineBreak ? '' : '\n')
  )
}