8d9b44056cc4c69e935a757fcc6a455558eb9d293627fbc2a370d8851b0c0addc3e8f1cf4f7041ab946e9cfcd3b2c6b4b1fb6222cbe6a00276c61a92da5b0f 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. # log-update [![Build Status](https://travis-ci.org/sindresorhus/log-update.svg?branch=master)](https://travis-ci.org/sindresorhus/log-update)
  2. > Log by overwriting the previous output in the terminal.<br>
  3. > Useful for rendering progress bars, animations, etc.
  4. ![](screenshot.gif)
  5. ## Install
  6. ```
  7. $ npm install log-update
  8. ```
  9. ## Usage
  10. ```js
  11. const logUpdate = require('log-update');
  12. const frames = ['-', '\\', '|', '/'];
  13. let i = 0;
  14. setInterval(() => {
  15. const frame = frames[i = ++i % frames.length];
  16. logUpdate(
  17. `
  18. ♥♥
  19. ${frame} unicorns ${frame}
  20. ♥♥
  21. `
  22. );
  23. }, 80);
  24. ```
  25. ## API
  26. ### logUpdate(text…)
  27. Log to stdout.
  28. ### logUpdate.clear()
  29. Clear the logged output.
  30. ### logUpdate.done()
  31. Persist the logged output.<br>
  32. Useful if you want to start a new log session below the current one.
  33. ### logUpdate.stderr(text…)
  34. Log to stderr.
  35. ### logUpdate.stderr.clear()
  36. ### logUpdate.stderr.done()
  37. ### logUpdate.create(stream, options?)
  38. Get a `logUpdate` method that logs to the specified stream.
  39. #### options
  40. Type: `object`
  41. ##### showCursor
  42. Type: `boolean`\
  43. Default: `false`
  44. Show the cursor. This can be useful when a CLI accepts input from a user.
  45. ```js
  46. const logUpdate = require('log-update');
  47. // Write output but don't hide the cursor
  48. const log = logUpdate.create(process.stdout, {
  49. showCursor: true
  50. });
  51. ```
  52. ## Examples
  53. - [listr](https://github.com/SamVerschueren/listr) - Uses this module to render an interactive task list
  54. - [ora](https://github.com/sindresorhus/ora) - Uses this module to render awesome spinners
  55. - [speed-test](https://github.com/sindresorhus/speed-test) - Uses this module to render a [spinner](https://github.com/sindresorhus/elegant-spinner)
  56. ---
  57. <div align="center">
  58. <b>
  59. <a href="https://tidelift.com/subscription/pkg/npm-log-update?utm_source=npm-log-update&utm_medium=referral&utm_campaign=readme">Get professional support for this package with a Tidelift subscription</a>
  60. </b>
  61. <br>
  62. <sub>
  63. Tidelift helps make open source sustainable for maintainers while giving companies<br>assurances about security, maintenance, and licensing for their dependencies.
  64. </sub>
  65. </div>