1- import { colors , tty } from "./deps.ts" ;
1+ import * as colors from "@std/fmt/colors" ;
2+ import * as tty from "@denosaurs/tty" ;
23
34import spinners from "./spinners.ts" ;
4-
55import { symbols } from "./log_symbols.ts" ;
66
7+ export { spinners , symbols } ;
8+
79const encoder = new TextEncoder ( ) ;
810
911type ColorFunction = ( message : string ) => string ;
@@ -32,7 +34,7 @@ export interface SpinnerOptions {
3234 hideCursor ?: boolean ;
3335 indent ?: number ;
3436 interval ?: number ;
35- stream ?: Deno . WriterSync & { rid : number } ;
37+ stream ?: tty . SyncStream ;
3638 enabled ?: boolean ;
3739 discardStdin ?: boolean ;
3840 interceptConsole ?: boolean ;
@@ -62,7 +64,7 @@ export interface Console {
6264 timeLog : typeof console . timeLog ;
6365}
6466
65- export function wait ( opts : string | SpinnerOptions ) {
67+ export function wait ( opts : string | SpinnerOptions ) : Spinner {
6668 if ( typeof opts === "string" ) {
6769 opts = { text : opts } ;
6870 }
@@ -86,7 +88,7 @@ export class Spinner {
8688
8789 isSpinning : boolean ;
8890
89- #stream: Deno . WriterSync & { rid : number } ;
91+ #stream: tty . SyncStream ;
9092 indent : number ;
9193 interval : number ;
9294
@@ -135,7 +137,7 @@ export class Spinner {
135137 #text = "" ;
136138 #prefix = "" ;
137139
138- #interceptConsole( ) {
140+ #interceptConsole( ) : void {
139141 const methods : ( keyof Console ) [ ] = [
140142 "log" ,
141143 "warn" ,
@@ -174,7 +176,7 @@ export class Spinner {
174176 else this . #spinner = spin ;
175177 }
176178
177- get spinner ( ) {
179+ get spinner ( ) : SpinnerAnimation {
178180 return this . #spinner;
179181 }
180182
@@ -183,7 +185,7 @@ export class Spinner {
183185 else this . #color = color ;
184186 }
185187
186- get color ( ) {
188+ get color ( ) : ColorFunction {
187189 return this . #color;
188190 }
189191
@@ -192,26 +194,26 @@ export class Spinner {
192194 this . updateLines ( ) ;
193195 }
194196
195- get text ( ) {
197+ get text ( ) : string {
196198 return this . #text;
197199 }
198200 set prefix ( value : string ) {
199201 this . #prefix = value ;
200202 this . updateLines ( ) ;
201203 }
202204
203- get prefix ( ) {
205+ get prefix ( ) : string {
204206 return this . #prefix;
205207 }
206208
207- private write ( data : string ) {
209+ # write( data : string ) : void {
208210 this . #stream. writeSync ( encoder . encode ( data ) ) ;
209211 }
210212
211213 start ( ) : Spinner {
212214 if ( ! this . #enabled) {
213215 if ( this . text ) {
214- this . write ( `- ${ this . text } \n` ) ;
216+ this . # write( `- ${ this . text } \n` ) ;
215217 }
216218 return this ;
217219 }
@@ -229,7 +231,7 @@ export class Spinner {
229231
230232 render ( ) : void {
231233 this . clear ( ) ;
232- this . write ( `${ this . frame ( ) } \n` ) ;
234+ this . # write( `${ this . frame ( ) } \n` ) ;
233235 this . updateLines ( ) ;
234236 this . #linesToClear = this . #linesCount;
235237 }
@@ -282,7 +284,7 @@ export class Spinner {
282284 } , 0 ) ;
283285 }
284286
285- stop ( ) {
287+ stop ( ) : void {
286288 if ( ! this . #enabled) return ;
287289 clearInterval ( this . #id) ;
288290 this . #id = - 1 ;
@@ -294,7 +296,7 @@ export class Spinner {
294296 }
295297 }
296298
297- stopAndPersist ( options : PersistOptions = { } ) {
299+ stopAndPersist ( options : PersistOptions = { } ) : void {
298300 const prefix = options . prefix || this . prefix ;
299301 const fullPrefix = typeof prefix === "string" && prefix !== ""
300302 ? prefix + " "
@@ -304,22 +306,22 @@ export class Spinner {
304306
305307 this . stop ( ) ;
306308 // https://github.com/denoland/deno/issues/6001
307- this . write ( `${ fullPrefix } ${ options . symbol || " " } ${ fullText } \n` ) ;
309+ this . # write( `${ fullPrefix } ${ options . symbol || " " } ${ fullText } \n` ) ;
308310 }
309311
310- succeed ( text ?: string ) {
312+ succeed ( text ?: string ) : void {
311313 return this . stopAndPersist ( { symbol : symbols . success , text } ) ;
312314 }
313315
314- fail ( text ?: string ) {
316+ fail ( text ?: string ) : void {
315317 return this . stopAndPersist ( { symbol : symbols . error , text } ) ;
316318 }
317319
318- warn ( text ?: string ) {
320+ warn ( text ?: string ) : void {
319321 return this . stopAndPersist ( { symbol : symbols . warning , text } ) ;
320322 }
321323
322- info ( text ?: string ) {
324+ info ( text ?: string ) : void {
323325 return this . stopAndPersist ( { symbol : symbols . info , text } ) ;
324326 }
325327}
0 commit comments