UNPKG

4.15 kBTypeScriptView Raw
1import * as clc from "cli-color";
2
3export interface LineBufferOptions {
4 x?: number | undefined;
5 y?: number | undefined;
6 width?: number | "console" | undefined;
7 height?: number | "console" | undefined;
8 scroll?: number | undefined;
9}
10
11export class LineBuffer {
12 /**
13 * Creates an object for buffering a group of text lines and then outputting them
14 * @param options Values to build the buffer
15 */
16 constructor(options: LineBufferOptions);
17
18 /**
19 * Return the height of the `LineBuffer`, when specified as `console`
20 */
21 height(): number;
22
23 /**
24 * Return the width of the `LineBuffer`, when specified as `console`
25 */
26 width(): number;
27
28 /**
29 * Put a `Line` object into the `LineBuffer`
30 * @param line The line object to put into the buffer
31 */
32 addLine(line: Line): void;
33
34 /**
35 * If you don't have enough lines in the buffer, this will fill the reset of
36 * the lines with empty spaces
37 */
38 fill(): void;
39
40 /**
41 * Draw the `LineBuffer` to screen
42 */
43 output(): void;
44}
45
46/**
47 * This chainable object can be used to generate a line of text with columns, padding, and fill
48 */
49export class Line {
50 /**
51 * Create a new instance of Line object
52 * @param buffer Object to be used as buffer
53 */
54 constructor(buffer?: LineBuffer);
55
56 /**
57 * Output `width` characters of blank space
58 * @param width Number of characters to print
59 */
60 padding(width: number): Line;
61
62 /**
63 * Output text within a column of the specified width
64 * @param text Text to print
65 * @param width Width of the column
66 * @param styles List of `cli-color` styles to apply
67 */
68 column(text: string, width: number, styles?: clc.Format[]): Line;
69
70 /**
71 * At the end of a line, fill the rest of the columns to the right edge
72 */
73 fill(): Line;
74
75 /**
76 * Print the generated line of text to the console
77 */
78 output(): Line;
79
80 /**
81 * Return the contents of this line as a string
82 */
83 contents(): string;
84
85 /**
86 * Store this line into the buffer
87 */
88 store(): void;
89}
90
91/**
92 * Creates a basic horizontal gauge to the screen
93 * @param value The current value of the metric being displayed by this gauge
94 * @param maxValue The highest possible value of the metric being displayed
95 * @param guageWidth How many columns widt to draw the gauge
96 * @param dangerZone The point after which the value will be drawn in red because it's too high
97 * @param suffix A value to output after the gauge itself
98 */
99export function Gauge(
100 value: number,
101 maxValue: number,
102 guageWidth: number,
103 dangerZone: number,
104 suffix: string,
105): string;
106
107/**
108 * A simple command line sparkline that draws a series of values, and highlights the peak for the period
109 * @param values An array of values to go into the sparkline
110 * @param suffix A suffix to use when drawing the current and max values at the end of the sparkline
111 */
112export function Sparkline(values: number[], suffix: string): string;
113
114export class Progress {
115 /**
116 * Creates a progress bar
117 * @param length The desired length of the progress bar in characters
118 */
119 constructor(length: number);
120
121 /**
122 * Returns the progress bar min/max context to write to stdout
123 * @param currentValueOrPercent Current value (or percent) of the progress bar
124 * @param maxValue Maximum value of the progress bar
125 */
126 update(currentValueOrPercent: number, maxValue?: number): string;
127}
128
129export class Spinner {
130 /**
131 * Creates a new spinner
132 * @param statusText The default text to display while the spinner is spinning
133 * @param style Array of graphical characters used to draw the spinner
134 */
135 constructor(statusText: string, style?: string[]);
136
137 /**
138 * Show the spinner on the screen
139 */
140 start(): void;
141
142 /**
143 * Update the status message that follows the spinner
144 * @param statusMessage Message to be displayed
145 */
146 message(statusMessage: string): void;
147
148 /**
149 * Erase the spinner from the screen
150 */
151 stop(): void;
152}