UNPKG

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