There are libraries like typewriterjs and typeitjs for producing animated typing effect in the DOM. How can I produce a similar effect in the terminal. The closest option I found is terminal-kit, but it is causing problems for me when the cli app has to take an input just after the effect is completed. The next input is adding unwanted characters, and I cant seem to find a way to solve it (refer the gif below).
This is how I produced that effect using terminal kit. It would be helpful if someone can tell me why the next input is not being registered properly after the effect completes.
const repl = require('repl');
const socket = require('socket.io-client')('http://localhost:3000');
const term = require('terminal-kit').terminal;
socket.on('connect', function() {
console.log('Server connected');
});
// typing effect on receiving a message
socket.on('msg', function(data) {
term.slowTyping(
data, {
flashStyle: false,
delay: 115,
style: term.yellow
},
function() {
return takeInput();
}
);
});
socket.on('disconnect', function() {
console.log('Server disconnected');
});
function takeInput() {
console.log('');
repl.start({
prompt: '> ',
eval: (message) => {
socket.emit('msg', message);
}
});
}
takeInput();
