Print

Print class. Use sprintf to interpolate pattern and variable. Support many methods to display things on screen including ora based spinner.

It also serve as the foundation of Bajo's I18n lightweight system.

Constructor

new Print(plugin, optsopt)

Class constructor

Parameters:
NameTypeAttributesDefaultDescription
pluginObject

Plugin instance

optsObject<optional>
{}

Options to pass to ora

Methods

clear() → {Object}

Clear spinner text

Returns:

Return itself, usefull to chain methods

Type: 
Object

fail(text, …argsopt) → {Object}

Print failed message, prefixed with a cross icon

Parameters:
NameTypeAttributesDescription
textstring

Text to use

argsany<optional>
<repeatable>

Any variable to interpolate text. If the last argument is an object, it will be used to override ora options

Returns:

Return itself, usefull to chain methods

Type: 
Object

fatal(text, …argsopt)

Print failed message, prefixed with a cross icon and terminate the app process

Parameters:
NameTypeAttributesDescription
textstring

Text to use

argsany<optional>
<repeatable>

Any variable to interpolate text. If the last argument is an object, it will be used to override ora options

getElapsed(unitopt) → {string}

Get elapsed time since print instance is created

Parameters:
NameTypeAttributesDefaultDescription
unitstring<optional>
hms

Unit's time. Put 'hms' (default) to get hour, minute, second format or of any format supported by dayjs

Returns:

Elapsed time since start

Type: 
string

info(text, …argsopt) → {Object}

Print failed message, prefixed with an info icon

Parameters:
NameTypeAttributesDescription
textstring

Text to use

argsany<optional>
<repeatable>

Any variable to interpolate text. If the last argument is an object, it will be used to override ora options

Returns:

Return itself, usefull to chain methods

Type: 
Object

init()

Initialize print engine and read plugin's translation files

render() → {Object}

Force render spinner

Returns:

Return itself, usefull to chain methods

Type: 
Object

setOpts(argsopt)

Set spinner options

Parameters:
NameTypeAttributesDefaultDescription
argsArray.<any><optional>
[]

Array of options. If the last argument is an object, it will be used to override ora options

setText(text, …argsopt) → {Object}

Set spinner text

Parameters:
NameTypeAttributesDescription
textstring

Text to use

argsany<optional>
<repeatable>

Any variable to interpolate text. If the last argument is an object, it will be used to override ora options

Returns:

Return itself, usefull to chain methods

Type: 
Object

spinner() → {Object}

Create a new spinner

Returns:

Return new instance

Type: 
Object

start(text, …argsopt) → {Object}

Start the spinner

Parameters:
NameTypeAttributesDescription
textstring

Text to use

argsany<optional>
<repeatable>

Any variable to interpolate text. If the last argument is an object, it will be used to override ora options

Returns:

Return itself, usefull to chain methods

Type: 
Object

stop() → {Object}

Stop the spinner

Returns:

Return itself, usefull to chain methods

Type: 
Object

succeed(text, …argsopt) → {Object}

Print success message, prefixed with a check icon

Parameters:
NameTypeAttributesDescription
textstring

Text to use

argsany<optional>
<repeatable>

Any variable to interpolate text. If the last argument is an object, it will be used to override ora options

Returns:

Return itself, usefull to chain methods

Type: 
Object

warn(text, …argsopt) → {Object}

Print warning message, prefixed with a warn icon

Parameters:
NameTypeAttributesDescription
textstring

Text to use

argsany<optional>
<repeatable>

Any variable to interpolate text. If the last argument is an object, it will be used to override ora options

Returns:

Return itself, usefull to chain methods

Type: 
Object

write(text, …argsopt) → {string}

Interpolate and translate text according to the chosen language

Parameters:
NameTypeAttributesDescription
textstring

Text pattern to translate. See sprintf for all supported token & format

argsany<optional>
<repeatable>

Variables to interpolate with text pattern above. If the last argument is an object, it will be use to override default translation option. Example: to force language to 'id', pass the last argument as "{ lang: 'id' }"

Returns:

Interpolated & translated text

Type: 
string