Skip to content

Commit 2496431

Browse files
committed
refactor: remove format utils method
1 parent 1aa9b55 commit 2496431

File tree

4 files changed

+14
-77
lines changed

4 files changed

+14
-77
lines changed

command/help/help-generator.ts

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
import { IFlagOptions } from '../../flags/types.ts';
22
import { Table } from '../../table/table.ts';
3-
import format from '../../x/format.ts';
43
import { ArgumentsParser } from '../_arguments-parser.ts';
54
import { Command } from '../command.ts';
65
import { blue, bold, dim, magenta, red, yellow } from '../deps.ts';
@@ -165,7 +164,7 @@ export class HelpGenerator {
165164
const hints = [];
166165

167166
option.required && hints.push( yellow( `required` ) );
168-
typeof option.default !== 'undefined' && hints.push( blue( bold( `Default: ` ) ) + blue( format( option.default ) ) );
167+
typeof option.default !== 'undefined' && hints.push( blue( bold( `Default: ` ) ) + blue( Deno.inspect( option.default, { depth: 1 } ) ) );
169168
option.depends && option.depends.length && hints.push( red( bold( `depends: ` ) ) + option.depends.map( depends => red( depends ) ).join( ', ' ) );
170169
option.conflicts && option.conflicts.length && hints.push( red( bold( `conflicts: ` ) ) + option.conflicts.map( conflict => red( conflict ) ).join( ', ' ) );
171170

@@ -176,14 +175,10 @@ export class HelpGenerator {
176175
return '';
177176
}
178177

179-
private line( ...args: any[] ) {
180-
return ( args.length ? ' '.repeat( this.indent ) + format( ...args ) : '' ) + '\n';
181-
}
182-
183178
private label( label: string ) {
184179
return '\n' +
185-
this.line( bold( `${ label }:` ) ) +
186-
'\n';
180+
' '.repeat( this.indent ) + bold( `${ label }:` ) +
181+
'\n\n';
187182
}
188183
}
189184

prompt/_generic-prompt.ts

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import { AnsiEscape } from '../ansi-escape/ansi-escape.ts';
22
import { KeyCode } from '../keycode/key-code.ts';
33
import { KeyEvent } from '../keycode/key-event.ts';
4-
import format from '../x/format.ts';
54
import { blue, bold, dim, green, red, yellow } from './deps.ts';
65
import { Figures } from './figures.ts';
76

@@ -206,12 +205,12 @@ export abstract class GenericPrompt<T, V, S extends GenericPromptSettings<T, V>,
206205
);
207206
}
208207

209-
protected write( ...args: any[] ) {
210-
Deno.stdout.writeSync( new TextEncoder().encode( format( ...args ) ) );
208+
protected write( value: string ) {
209+
Deno.stdout.writeSync( new TextEncoder().encode( value ) );
211210
}
212211

213-
protected writeLine( ...args: any[] ) {
214-
Deno.stdout.writeSync( new TextEncoder().encode( format( ...args ) + '\n' ) );
212+
protected writeLine( value?: string ) {
213+
Deno.stdout.writeSync( new TextEncoder().encode( ( value ?? '' ) + '\n' ) );
215214
}
216215

217216
protected preBufferEmptyLines( message: string ) {
@@ -220,18 +219,18 @@ export abstract class GenericPrompt<T, V, S extends GenericPromptSettings<T, V>,
220219
this.screen.cursorUp( linesCount );
221220
}
222221

223-
protected error( ...args: any[] ) {
222+
protected error( message: string ) {
224223
if ( typeof GenericPrompt.injectedValue !== 'undefined' ) {
225-
throw new Error( red( bold( ` ${ Figures.CROSS } ` ) + format( ...args ) ) );
224+
throw new Error( red( bold( ` ${ Figures.CROSS } ` ) + message ) );
226225
}
227-
this.write( red( bold( ` ${ Figures.CROSS } ` ) + format( ...args ) ) );
226+
this.write( red( bold( ` ${ Figures.CROSS } ` ) + message ) );
228227
}
229228

230-
protected message( ...args: any[] ) {
231-
this.write( blue( ` ${ Figures.POINTER } ` ) + format( ...args ) );
229+
protected message( message: string ) {
230+
this.write( blue( ` ${ Figures.POINTER } ` ) + message );
232231
}
233232

234-
protected hint( ...args: any[] ) {
235-
this.write( dim( blue( ` ${ Figures.POINTER } ` ) + format( ...args ) ) );
233+
protected hint( hint: string ) {
234+
this.write( dim( blue( ` ${ Figures.POINTER } ` ) + hint ) );
236235
}
237236
}

x/README.md

Lines changed: 0 additions & 5 deletions
This file was deleted.

x/format.ts

Lines changed: 0 additions & 52 deletions
This file was deleted.

0 commit comments

Comments
 (0)