OutputText
Constructors
new OutputText()
new OutputText(output): OutputTextParameters
| Parameter | Type |
|---|---|
|
Returns
Methods
animation()
animation(
animation,
text,
speed?): AnimationParameters
| Parameter | Type |
|---|---|
| |
|
|
|
|
Returns
Animation
figlet()
Call Signature
figlet(
txt,
font,
cb?): Promise<any>Parameters
| Parameter | Type |
|---|---|
|
|
|
|
| ( |
Returns
Promise<any>
Call Signature
figlet(
txt,
options,
cb?): Promise<any>Parameters
| Parameter | Type |
|---|---|
|
|
|
|
| ( |
Returns
Promise<any>
Call Signature
figlet(txt, cb?): Promise<any>Parameters
| Parameter | Type |
|---|---|
|
|
| ( |
Returns
Promise<any>
gradient()
gradient(gradient, str): stringParameters
| Parameter | Type |
|---|---|
| |
|
|
Returns
string
multilineGradient()
multilineGradient(gradient, str): stringParameters
| Parameter | Type |
|---|---|
| |
|
|
Returns
string
slice()
slice(...args): anySlice a string with ANSI escape codes
Parameters
| Parameter | Type |
|---|---|
... |
|
Returns
any
Method
Example
import chalk from 'chalk';
import sliceAnsi from 'slice-ansi';
const string = 'The quick brown ' + chalk.red('fox jumped over ') +
'the lazy ' + chalk.green('dog and then ran away with the unicorn.');
console.log(sliceAnsi(string, 20, 30));strip()
strip(...args): anyStrips ANSI escape codes from a string.
Parameters
| Parameter | Type |
|---|---|
... |
|
Returns
any
The stripped text
Example
stripAnsi('\u001B[4mUnicorn\u001B[0m');
//=> 'Unicorn'
stripAnsi('\u001B] 8;;https:// github. com\u0007Click\u001B] 8;;\u0007');
//=> 'Click'truncate()
truncate(...args): anyTruncate a string to a specific width in the terminal.
Parameters
| Parameter | Type |
|---|---|
... |
|
Returns
any
Example
import cliTruncate from 'cli-truncate';
cliTruncate('unicorn', 4);
//=> 'uni…'
// Truncate at different positions
cliTruncate('unicorn', 4, {position='start'});
//=> '…orn'
cliTruncate('unicorn', 4, {position='middle'});
//=> 'un…n'
cliTruncate('\u001B[31municorn\u001B[39m', 4);
//=> '\u001B[31muni\u001B[39m…'
// Truncate Unicode surrogate pairs
cliTruncate('uni\uD83C\uDE00corn', 5);
//=> 'uni\uD83C\uDE00…'
// Truncate fullwidth characters
cliTruncate('안녕하세요', 3);
//=> '안…'
// Truncate the paragraph to the terminal width
const paragraph = 'Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa.';
cliTruncate(paragraph, process.stdout.columns);
//=> 'Lorem ipsum dolor sit amet, consectetuer adipiscing…'widest()
widest(input): numberParameters
| Parameter | Type |
|---|---|
|
|
Returns
number
widestLine()
widestLine(...args): anyGet the visual width of the widest line in a string - the number of columns required to display it.
Parameters
| Parameter | Type |
|---|---|
... |
|
Returns
any
Method
Example
import widestLine from 'widest-line';
widestLine('古\n\u001B[1m@\u001B[22m');
//=> 2width()
width(...args): anyGet the visual width of a string - the number of columns required to display it.
Some Unicode characters are fullwidth and use double the normal width. ANSI escape codes are stripped and doesn't affect the width.
Parameters
| Parameter | Type |
|---|---|
... |
|
Returns
any
Method
Example
import stringWidth from 'string-width';
stringWidth('a');
//=> 1
stringWidth('古');
//=> 2
stringWidth('\u001B[1m古\u001B[22m');
//=> 2wrap()
wrap(...args): anyWrap words to the specified column width.
Parameters
| Parameter | Type |
|---|---|
... |
|
Returns
any
Method
Example
import chalk from 'chalk';
import wrapAnsi from 'wrap-ansi';
const input = 'The quick brown ' + chalk.red('fox jumped over ') +
'the lazy ' + chalk.green('dog and then ran away with the unicorn.');
console.log(wrapAnsi(input, 20));