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

58 lines
1.5 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();
logNode(textArg,"ok");
2016-05-13 23:18:44 +00:00
};
endError(textArg){
this.end();
logNode(textArg,"error");
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();
}
// log methods that play nice with ora
log(logText:string,logType:string){
this.stop();
logNode(logText,logType);
this.start();
}
2016-05-13 23:18:44 +00:00
}