2016-05-13 23:18:44 +00:00
|
|
|
/// <reference path="./typings/main.d.ts" />
|
|
|
|
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-05-16 22:24:56 +00:00
|
|
|
logNode(textArg,"ok");
|
2016-05-13 23:18:44 +00:00
|
|
|
};
|
|
|
|
endError(textArg){
|
|
|
|
this.end();
|
2016-05-16 22:24:56 +00:00
|
|
|
logNode(textArg,"error");
|
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();
|
|
|
|
}
|
|
|
|
|
|
|
|
// log methods that play nice with ora
|
|
|
|
log(logText:string,logType:string){
|
|
|
|
this.stop();
|
2016-05-16 22:24:56 +00:00
|
|
|
logNode(logText,logType);
|
2016-05-14 14:26:38 +00:00
|
|
|
this.start();
|
|
|
|
}
|
2016-05-13 23:18:44 +00:00
|
|
|
}
|