// Step 1: Import the required modules
const readline = require('readline');
const logUpdate = require('log-update');
// Step 2: Define the animation frames
const frames = ['-', '\\', '|', '/'];
// Step 3: Set up the readline interface
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});
// Step 4: Initialize the frame index
let frameIndex = 0;
// Step 5: Create a function to update and display the animation
function animate() {
// Move the cursor to the beginning of the line
logUpdate(frames[frameIndex]);
// Increment the frame index for the next iteration
frameIndex = (frameIndex + 1) % frames.length;
}
// Step 6: Start the animation
const animationInterval = setInterval(animate, 100);
// Step 7: Set a timeout to stop the animation after a certain duration
const animationDuration = 5000; // 5 seconds
setTimeout(() => {
// Stop the animation interval
clearInterval(animationInterval);
// Close the readline interface and clear the last frame
rl.close();
logUpdate.clear();
}, animationDuration);