index.d.ts 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. /// <reference types="node"/>
  2. declare namespace logUpdate {
  3. interface LogUpdate {
  4. /**
  5. Log to `stdout` by overwriting the previous output in the terminal.
  6. @param text - The text to log to `stdout`.
  7. @example
  8. ```
  9. import logUpdate = require('log-update');
  10. const frames = ['-', '\\', '|', '/'];
  11. let i = 0;
  12. setInterval(() => {
  13. const frame = frames[i = ++i % frames.length];
  14. logUpdate(
  15. `
  16. ♥♥
  17. ${frame} unicorns ${frame}
  18. ♥♥
  19. `
  20. );
  21. }, 80);
  22. ```
  23. */
  24. (...text: string[]): void;
  25. /**
  26. Clear the logged output.
  27. */
  28. clear(): void;
  29. /**
  30. Persist the logged output. Useful if you want to start a new log session below the current one.
  31. */
  32. done(): void;
  33. }
  34. interface Options {
  35. /**
  36. Show the cursor. This can be useful when a CLI accepts input from a user.
  37. @example
  38. ```
  39. import logUpdate = require('log-update');
  40. // Write output but don't hide the cursor
  41. const log = logUpdate.create(process.stdout, {
  42. showCursor: true
  43. });
  44. ```
  45. */
  46. readonly showCursor?: boolean;
  47. }
  48. }
  49. declare const logUpdate: logUpdate.LogUpdate & {
  50. /**
  51. Log to `stderr` by overwriting the previous output in the terminal.
  52. @param text - The text to log to `stderr`.
  53. */
  54. readonly stderr: logUpdate.LogUpdate;
  55. /**
  56. Get a `logUpdate` method that logs to the specified stream.
  57. @param stream - The stream to log to.
  58. */
  59. readonly create: (
  60. stream: NodeJS.WritableStream,
  61. options?: logUpdate.Options
  62. ) => logUpdate.LogUpdate;
  63. };
  64. export = logUpdate;