チョークアニメーション
ターミナル出力のカラフルなアニメーション
利用可能なアニメーション
名前 | プレビュー |
---|---|
虹 | ![]() |
脈 | ![]() |
グリッチ | ![]() |
レーダー | ![]() |
ネオン | ![]() |
カラオケ | ![]() |
インストール
1$ npm i chalk-animation
使用法
1
2
3const chalkAnimation = require('chalk-animation');
chalkAnimation.rainbow('Lorem ipsum dolor sit amet');
開始および停止
あなたは停止し、とアニメーションを再開することができますstop()
し、start()
。
作成されると、chalkAnimationのインスタンスが自動的に開始されます。
1
2
3
4
5
6
7
8
9
10const rainbow = chalkAnimation.rainbow('Lorem ipsum'); // Animation starts
setTimeout(() => {
rainbow.stop(); // Animation stops
}, 1000);
setTimeout(() => {
rainbow.start(); // Animation resumes
}, 2000);
自動停止
コンソールに印刷されたものはすべて、前のアニメーションを自動的に停止します
1
2
3
4
5chalkAnimation.rainbow('Lorem ipsum');
setTimeout(() => {
// Stop the 'Lorem ipsum' animation, then write on a new line.
console.log('dolor sit amet');
}, 1000);
速度の変更
2番目のパラメータを使用してアニメーション速度を変更します。0より大きくする必要があります。デフォルトは1です。
1chalkAnimation.rainbow('Lorem ipsum', 2); // Two times faster than default
テキストの変更
とシームレスにアニメーションテキストを変更します replace()
1
2
3
4
5
6
7let str = 'Loading...';
const rainbow = chalkAnimation.rainbow(str);
// Add a new dot every second
setInterval(() => {
rainbow.replace(str += '.');
}, 1000);
手動レンダリング
を使用してフレームを手動でレンダリングするrender()
か、を使用して次のフレームのコンテンツを取得しますframe()
1
2
3
4
5
6const rainbow = chalkAnimation.rainbow('Lorem ipsum').stop(); // Don't start the animation
rainbow.render(); // Display the first frame
const frame = rainbow.frame(); // Get the second frame
console.log(frame);
CLIモード
1
2# Install package globally
$ npm install --global chalk-animation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21$ chalk-animation --help
Colorful animations in terminal output
Usage
$ chalk-animation <name> [options] [text...]
Options
--duration Duration of the animation in ms, defaults to Infinity
--speed Animation speed as number > 0, defaults to 1
Available animations
rainbow
pulse
glitch
radar
neon
karaoke
Example
$ chalk-animation rainbow Hello world!
関連している
- グラデーション文字列-ターミナルにグラデーションを出力します
- チョーク-色付きのテキストを端末に出力する
ライセンス
MIT© BorisK