You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

91 lines
1.7 KiB

3 months ago
  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`<br>
  43. Default: `false`
  44. Show the cursor. This can be useful when a CLI accepts input from a user.
  45. ```js
  46. // Write output but don't hide the cursor
  47. const log = logUpdate.create(process.stdout, {
  48. showCursor: true
  49. });
  50. ```
  51. ## Examples
  52. - [listr](https://github.com/SamVerschueren/listr) - Uses this module to render an interactive task list
  53. - [ora](https://github.com/sindresorhus/ora) - Uses this module to render awesome spinners
  54. - [speed-test](https://github.com/sindresorhus/speed-test) - Uses this module to render a [spinner](https://github.com/sindresorhus/elegant-spinner)
  55. ## License
  56. MIT © [Sindre Sorhus](https://sindresorhus.com)