Output
The Output
class provides methods for formatted and styled console output.
- If we put
options.silent
totrue
, nothing will be printed - If we put
options.colors
tofalse
, no colors will be printed
Example
const out = new Output({ silent: false });
out.write('Hello, World!');
out.success('Operation completed successfully.');
out.error('An error occurred.');
out.line(out.t`Hello {green.bold.dim World, this is colored!} and this aint`
out.line(`Hello {green.bold.dim World, this is colored!} and this aint`)
out.line(out.color.red('This is red text'));
Constructors
new Output()
new Output(options): Output
Creates an instance of Output
.
Parameters
Parameter | Type | Description |
---|---|---|
|
| Partial options to override the default settings. |
Returns
Example
const output = new Output({ silent: true });
Properties
Property | Modifier | Type | Default value | Description |
---|---|---|---|---|
|
|
| ‐ | |
|
| ‐ | ||
| ( |
| Blocks are delimited by an opening curly brace ({), a style, some content, and a closing curly brace (}). Template styles are chained exactly like normal Chalk styles. See https://github.com/chalk/chalk-template Example
| |
| ( |
| ‐ | |
|
|
| ‐ | |
|
|
| ‐ | |
|
| ‐ |
Accessors
colorsEnabled
Get Signature
get colorsEnabled(): boolean
Returns
boolean
err
Get Signature
get err(): WriteStream & object
The output stream for standard messages.
Example
output.out.write('Hello, World!');
output.out.write('Hello, World!').write('Hello, World!');
output.out.write('Hello, World!').writeln('Hello, World!');
Returns
WriteStream
& object
isSilent
Get Signature
get isSilent(): boolean
Returns
boolean
nl
Get Signature
get nl(): this
Returns
this
out
Get Signature
get out(): WriteStream & object
The output stream for standard messages.
Example
output.out.write('Hello, World!');
output.out.write('Hello, World!').write('Hello, World!');
output.out.write('Hello, World!').writeln('Hello, World!');
Returns
WriteStream
& object
Methods
configure()
configure(options): Output
Configures the Output
instance with new options.
Parameters
Parameter | Type | Description |
---|---|---|
|
| Partial options to merge with the current settings. |
Returns
The current Output
instance.
Example
output.configure({ colors: false });
disableColors()
disableColors(): Output
Returns
dump()
dump(...args): this
Dumps the provided arguments to the output stream using util.inspect
.
Parameters
Parameter | Type | Description |
---|---|---|
... |
| The arguments to dump. |
Returns
this
The current Output
instance.
Example
output.dump({ key: 'value' }, [1, 2, 3]);
enableColors()
enableColors(): Output
Returns
error()
error(text): Output
Writes an error message to the output stream.
Parameters
Parameter | Type | Description |
---|---|---|
|
| The error message. |
Returns
The current Output
instance.
Example
output.error('An error occurred.');
line()
line(text?): this
Writes text followed by a newline to the output stream.
Parameters
Parameter | Type | Default value | Description |
---|---|---|---|
|
|
| The text to write. |
Returns
this
The current Output
instance.
Example
output.line('Hello, World!');
silence()
silence(): Output
Returns
success()
success(text): Output
Writes a success message to the output stream.
Parameters
Parameter | Type | Description |
---|---|---|
|
| The success message. |
Returns
The current Output
instance.
Example
output.success('Operation completed successfully.');
unsilence()
unsilence(): Output
Returns
warn()
warn(text): Output
Writes a warning message to the output stream.
Parameters
Parameter | Type | Description |
---|---|---|
|
| The warning message. |
Returns
The current Output
instance.
Example
output.warn('This is a warning message.');
write()
write(text): this
Writes text to the output stream.
Parameters
Parameter | Type | Description |
---|---|---|
|
| The text to write. |
Returns
this
The current Output
instance.
Example
output.write('Hello, World!');
writeln()
writeln(text?): this
Writes text followed by a newline to the output stream.
Parameters
Parameter | Type | Default value | Description |
---|---|---|---|
|
|
| The text to write. |
Returns
this
The current Output
instance.
Example
output.writeln('Hello, World!');