You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Oct 9, 2020. It is now read-only.
If jsl.pause() is used multiple times in the same process, due to the process.stdin.on("data") event not being unregistered, the callback and line breaks will be called multiple times, increasing by one each time jsl.pause() is used.
This might also result in the wrong callbacks being executed at the wrong time, causing bugs that are horrible to debug.
Example code:
letallFlags=["nsfw","religious","political","racist","sexist"];letflagIteration=idx=>{if(idx>=allFlags.length)returnflagIterFinished();else{jsl.pause(`Is this joke ${allFlags[idx]}? (y/N):`).then(key=>{if(key.toLowerCase()=="y")joke["flags"][allFlags[idx]]=true;elsejoke["flags"][allFlags[idx]]=false;returnflagIteration(++idx);}).catch(err=>{console.error(`Error: ${err}`);returnprocess.exit(1);});}};flagIteration(0);
Results in:
The text was updated successfully, but these errors were encountered:
functionpause(text="Press any key to continue..."){if(!process.stdin.isRaw)process.stdin.setRawMode(true);returnnewPromise((resolve,reject)=>{process.stdout.write(`${text} `);process.stdin.resume();letonData=function(chunk){if(/\u0003/gu.test(chunk))// eslint-disable-line no-control-regexprocess.exit(0);process.stdout.write("\n");process.stdin.pause();process.stdin.removeListener("data",onData);returnresolve(chunk.toString());}process.stdin.on("data",onData);process.stdin.on("error",err=>{returnreject(err);});});}
If
jsl.pause()
is used multiple times in the same process, due to theprocess.stdin.on("data")
event not being unregistered, the callback and line breaks will be called multiple times, increasing by one each timejsl.pause()
is used.This might also result in the wrong callbacks being executed at the wrong time, causing bugs that are horrible to debug.
Example code:
Results in:
The text was updated successfully, but these errors were encountered: