early/ts/early.child.ts

52 lines
1.2 KiB
TypeScript
Raw Normal View History

2016-06-10 03:18:03 +00:00
import "typings-global";
let colors = require("colors");
import readline = require("readline");
2016-06-10 03:59:21 +00:00
let rl = readline.createInterface({
input: process.stdin,
output: process.stdout
2016-06-10 03:59:21 +00:00
});
let moduleName:string;
let loaderLength:number;
let frameCounter:number = 0;
let makeFrame = ():string => {
let resultString:string = "["
+ "/".green.repeat(frameCounter)
+ " ".repeat(loaderLength - frameCounter)
+ "]"
+ " starting "
+ moduleName.cyan;
if(frameCounter == loaderLength){
frameCounter = 0;
} else {
frameCounter++;
}
return resultString;
};
2016-06-10 03:59:21 +00:00
let logEarlyAbort = false;
let logEarly = () => {
rl.write(null, {ctrl: true, name: 'u'});
rl.write(makeFrame());
setTimeout(function(){
2016-06-10 03:59:21 +00:00
if(!logEarlyAbort) logEarly();
2016-05-23 03:11:03 +00:00
},80);
};
let start = function(moduleNameArg:string = "",loaderLengthArg:string = "10"){
moduleName = moduleNameArg;
loaderLength = parseInt(loaderLengthArg);
2016-06-10 03:36:06 +00:00
logEarly();
};
2016-06-10 03:59:21 +00:00
start(process.env.moduleNameArg,process.env.loaderLengthArg);
process.on('SIGINT', () => {
logEarlyAbort = true;
rl.write(null, {ctrl: true, name: 'u'});
rl.close();
2016-06-11 22:30:10 +00:00
rl.on("close",function(){
})
2016-06-10 03:59:21 +00:00
});