smartlog-destination-local/ts/beautylog.classes.ora.ts

51 lines
1.3 KiB
TypeScript
Raw Normal View History

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";
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;
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;
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
});
startArg ? this._oraObject.start() : void(0);
2016-05-13 23:18:44 +00:00
}
text(textArg){
this._oraObject.text = textArg;
};
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;
activeOra = this;
2016-05-19 17:27:09 +00:00
oraActive = true;
this._oraObject.start();
};
2016-05-13 23:18:44 +00:00
end(){
this._oraObject.stop();
this._oraObject.clear();
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();
}
stop(){ // alias for end
this.end();
2016-07-23 23:17:38 +00:00
};
2016-05-13 23:18:44 +00:00
}