Skip to content

Commit

Permalink
refactor: remove format utils method
Browse files Browse the repository at this point in the history
  • Loading branch information
c4spar committed Aug 22, 2020
1 parent 1aa9b55 commit 2496431
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 77 deletions.
11 changes: 3 additions & 8 deletions command/help/help-generator.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import { IFlagOptions } from '../../flags/types.ts';
import { Table } from '../../table/table.ts';
import format from '../../x/format.ts';
import { ArgumentsParser } from '../_arguments-parser.ts';
import { Command } from '../command.ts';
import { blue, bold, dim, magenta, red, yellow } from '../deps.ts';
Expand Down Expand Up @@ -165,7 +164,7 @@ export class HelpGenerator {
const hints = [];

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

Expand All @@ -176,14 +175,10 @@ export class HelpGenerator {
return '';
}

private line( ...args: any[] ) {
return ( args.length ? ' '.repeat( this.indent ) + format( ...args ) : '' ) + '\n';
}

private label( label: string ) {
return '\n' +
this.line( bold( `${ label }:` ) ) +
'\n';
' '.repeat( this.indent ) + bold( `${ label }:` ) +
'\n\n';
}
}

Expand Down
23 changes: 11 additions & 12 deletions prompt/_generic-prompt.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
import { AnsiEscape } from '../ansi-escape/ansi-escape.ts';
import { KeyCode } from '../keycode/key-code.ts';
import { KeyEvent } from '../keycode/key-event.ts';
import format from '../x/format.ts';
import { blue, bold, dim, green, red, yellow } from './deps.ts';
import { Figures } from './figures.ts';

Expand Down Expand Up @@ -206,12 +205,12 @@ export abstract class GenericPrompt<T, V, S extends GenericPromptSettings<T, V>,
);
}

protected write( ...args: any[] ) {
Deno.stdout.writeSync( new TextEncoder().encode( format( ...args ) ) );
protected write( value: string ) {
Deno.stdout.writeSync( new TextEncoder().encode( value ) );
}

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

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

protected error( ...args: any[] ) {
protected error( message: string ) {
if ( typeof GenericPrompt.injectedValue !== 'undefined' ) {
throw new Error( red( bold( ` ${ Figures.CROSS } ` ) + format( ...args ) ) );
throw new Error( red( bold( ` ${ Figures.CROSS } ` ) + message ) );
}
this.write( red( bold( ` ${ Figures.CROSS } ` ) + format( ...args ) ) );
this.write( red( bold( ` ${ Figures.CROSS } ` ) + message ) );
}

protected message( ...args: any[] ) {
this.write( blue( ` ${ Figures.POINTER } ` ) + format( ...args ) );
protected message( message: string ) {
this.write( blue( ` ${ Figures.POINTER } ` ) + message );
}

protected hint( ...args: any[] ) {
this.write( dim( blue( ` ${ Figures.POINTER } ` ) + format( ...args ) ) );
protected hint( hint: string ) {
this.write( dim( blue( ` ${ Figures.POINTER } ` ) + hint ) );
}
}
5 changes: 0 additions & 5 deletions x/README.md

This file was deleted.

52 changes: 0 additions & 52 deletions x/format.ts

This file was deleted.

0 comments on commit 2496431

Please sign in to comment.