1
- import { colors , tty } from "./deps.ts" ;
1
+ import * as colors from "@std/fmt/colors" ;
2
+ import * as tty from "@denosaurs/tty" ;
2
3
3
4
import spinners from "./spinners.ts" ;
4
-
5
5
import { symbols } from "./log_symbols.ts" ;
6
6
7
+ export { spinners , symbols } ;
8
+
7
9
const encoder = new TextEncoder ( ) ;
8
10
9
11
type ColorFunction = ( message : string ) => string ;
@@ -32,7 +34,7 @@ export interface SpinnerOptions {
32
34
hideCursor ?: boolean ;
33
35
indent ?: number ;
34
36
interval ?: number ;
35
- stream ?: Deno . WriterSync & { rid : number } ;
37
+ stream ?: tty . SyncStream ;
36
38
enabled ?: boolean ;
37
39
discardStdin ?: boolean ;
38
40
interceptConsole ?: boolean ;
@@ -62,7 +64,7 @@ export interface Console {
62
64
timeLog : typeof console . timeLog ;
63
65
}
64
66
65
- export function wait ( opts : string | SpinnerOptions ) {
67
+ export function wait ( opts : string | SpinnerOptions ) : Spinner {
66
68
if ( typeof opts === "string" ) {
67
69
opts = { text : opts } ;
68
70
}
@@ -86,7 +88,7 @@ export class Spinner {
86
88
87
89
isSpinning : boolean ;
88
90
89
- #stream: Deno . WriterSync & { rid : number } ;
91
+ #stream: tty . SyncStream ;
90
92
indent : number ;
91
93
interval : number ;
92
94
@@ -135,7 +137,7 @@ export class Spinner {
135
137
#text = "" ;
136
138
#prefix = "" ;
137
139
138
- #interceptConsole( ) {
140
+ #interceptConsole( ) : void {
139
141
const methods : ( keyof Console ) [ ] = [
140
142
"log" ,
141
143
"warn" ,
@@ -174,7 +176,7 @@ export class Spinner {
174
176
else this . #spinner = spin ;
175
177
}
176
178
177
- get spinner ( ) {
179
+ get spinner ( ) : SpinnerAnimation {
178
180
return this . #spinner;
179
181
}
180
182
@@ -183,7 +185,7 @@ export class Spinner {
183
185
else this . #color = color ;
184
186
}
185
187
186
- get color ( ) {
188
+ get color ( ) : ColorFunction {
187
189
return this . #color;
188
190
}
189
191
@@ -192,26 +194,26 @@ export class Spinner {
192
194
this . updateLines ( ) ;
193
195
}
194
196
195
- get text ( ) {
197
+ get text ( ) : string {
196
198
return this . #text;
197
199
}
198
200
set prefix ( value : string ) {
199
201
this . #prefix = value ;
200
202
this . updateLines ( ) ;
201
203
}
202
204
203
- get prefix ( ) {
205
+ get prefix ( ) : string {
204
206
return this . #prefix;
205
207
}
206
208
207
- private write ( data : string ) {
209
+ # write( data : string ) : void {
208
210
this . #stream. writeSync ( encoder . encode ( data ) ) ;
209
211
}
210
212
211
213
start ( ) : Spinner {
212
214
if ( ! this . #enabled) {
213
215
if ( this . text ) {
214
- this . write ( `- ${ this . text } \n` ) ;
216
+ this . # write( `- ${ this . text } \n` ) ;
215
217
}
216
218
return this ;
217
219
}
@@ -229,7 +231,7 @@ export class Spinner {
229
231
230
232
render ( ) : void {
231
233
this . clear ( ) ;
232
- this . write ( `${ this . frame ( ) } \n` ) ;
234
+ this . # write( `${ this . frame ( ) } \n` ) ;
233
235
this . updateLines ( ) ;
234
236
this . #linesToClear = this . #linesCount;
235
237
}
@@ -282,7 +284,7 @@ export class Spinner {
282
284
} , 0 ) ;
283
285
}
284
286
285
- stop ( ) {
287
+ stop ( ) : void {
286
288
if ( ! this . #enabled) return ;
287
289
clearInterval ( this . #id) ;
288
290
this . #id = - 1 ;
@@ -294,7 +296,7 @@ export class Spinner {
294
296
}
295
297
}
296
298
297
- stopAndPersist ( options : PersistOptions = { } ) {
299
+ stopAndPersist ( options : PersistOptions = { } ) : void {
298
300
const prefix = options . prefix || this . prefix ;
299
301
const fullPrefix = typeof prefix === "string" && prefix !== ""
300
302
? prefix + " "
@@ -304,22 +306,22 @@ export class Spinner {
304
306
305
307
this . stop ( ) ;
306
308
// https://github.com/denoland/deno/issues/6001
307
- this . write ( `${ fullPrefix } ${ options . symbol || " " } ${ fullText } \n` ) ;
309
+ this . # write( `${ fullPrefix } ${ options . symbol || " " } ${ fullText } \n` ) ;
308
310
}
309
311
310
- succeed ( text ?: string ) {
312
+ succeed ( text ?: string ) : void {
311
313
return this . stopAndPersist ( { symbol : symbols . success , text } ) ;
312
314
}
313
315
314
- fail ( text ?: string ) {
316
+ fail ( text ?: string ) : void {
315
317
return this . stopAndPersist ( { symbol : symbols . error , text } ) ;
316
318
}
317
319
318
- warn ( text ?: string ) {
320
+ warn ( text ?: string ) : void {
319
321
return this . stopAndPersist ( { symbol : symbols . warning , text } ) ;
320
322
}
321
323
322
- info ( text ?: string ) {
324
+ info ( text ?: string ) : void {
323
325
return this . stopAndPersist ( { symbol : symbols . info , text } ) ;
324
326
}
325
327
}
0 commit comments