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.

index.d.ts 1.8KB

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