2016-05-23 07:10:30 +00:00
|
|
|
import "typings-global";
|
2016-05-13 23:18:44 +00:00
|
|
|
import * as plugins from "./beautylog.plugins";
|
2016-05-16 22:24:56 +00:00
|
|
|
import {logNode} from "./beautylog.log.helpers";
|
|
|
|
|
2016-05-19 17:27:09 +00:00
|
|
|
export let oraActive:boolean = false; // when an Ora is active (e.g. start()) this is true;
|
2016-05-16 22:24:56 +00:00
|
|
|
export let activeOra:Ora; //points to the currently active Ora object
|
2016-05-13 23:18:44 +00:00
|
|
|
|
|
|
|
export class Ora {
|
|
|
|
private _oraObject;
|
|
|
|
state:string;
|
2016-05-14 14:26:38 +00:00
|
|
|
constructor(textArg:string,colorArg:string,startArg:boolean = false){
|
2016-05-13 23:18:44 +00:00
|
|
|
this._oraObject = plugins.ora({
|
|
|
|
spinner:"dots",
|
|
|
|
text:textArg,
|
|
|
|
color:colorArg
|
|
|
|
});
|
2016-05-14 14:26:38 +00:00
|
|
|
|
|
|
|
startArg ? this._oraObject.start() : void(0);
|
2016-05-13 23:18:44 +00:00
|
|
|
}
|
|
|
|
text(textArg){
|
|
|
|
this._oraObject.text = textArg;
|
|
|
|
};
|
2016-05-14 14:26:38 +00:00
|
|
|
|
2016-05-14 15:51:35 +00:00
|
|
|
start(textArg?:string,colorArg?:string){
|
|
|
|
if(textArg) this._oraObject.text = textArg;
|
|
|
|
if(colorArg) this._oraObject.color = colorArg;
|
2016-05-16 22:24:56 +00:00
|
|
|
activeOra = this;
|
2016-05-19 17:27:09 +00:00
|
|
|
oraActive = true;
|
2016-05-14 14:26:38 +00:00
|
|
|
this._oraObject.start();
|
|
|
|
};
|
2016-05-13 23:18:44 +00:00
|
|
|
end(){
|
|
|
|
this._oraObject.stop();
|
|
|
|
this._oraObject.clear();
|
2016-05-16 22:24:56 +00:00
|
|
|
activeOra = undefined;
|
2016-05-19 17:27:09 +00:00
|
|
|
oraActive = false;
|
2016-05-13 23:18:44 +00:00
|
|
|
}
|
|
|
|
endOk(textArg){
|
|
|
|
this.end();
|
2016-07-23 23:17:38 +00:00
|
|
|
logNode("ok",textArg);
|
2016-05-13 23:18:44 +00:00
|
|
|
};
|
|
|
|
endError(textArg){
|
|
|
|
this.end();
|
2016-07-23 23:17:38 +00:00
|
|
|
logNode("error",textArg);
|
2016-05-13 23:18:44 +00:00
|
|
|
};
|
2016-05-19 17:27:09 +00:00
|
|
|
pause(){
|
|
|
|
this._oraObject.stop();
|
|
|
|
}
|
2016-05-14 14:26:38 +00:00
|
|
|
stop(){ // alias for end
|
|
|
|
this.end();
|
2016-07-23 23:17:38 +00:00
|
|
|
};
|
2016-05-13 23:18:44 +00:00
|
|
|
}
|