2018-03-01 00:06:12 +00:00
|
|
|
import 'typings-global';
|
|
|
|
import * as plugins from './beautylog.plugins';
|
|
|
|
import { logNode } from './beautylog.log.helpers';
|
2016-05-16 22:24:56 +00:00
|
|
|
|
2018-03-01 00:06:12 +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 {
|
2018-03-01 00:06:12 +00:00
|
|
|
state: string;
|
|
|
|
private _oraObject;
|
2017-03-11 11:30:18 +00:00
|
|
|
constructor(textArg: string, colorArg: string, startArg: boolean = false) {
|
|
|
|
this._oraObject = plugins.ora({
|
|
|
|
spinner: 'dots',
|
|
|
|
text: textArg,
|
|
|
|
color: colorArg
|
2018-03-01 00:06:12 +00:00
|
|
|
});
|
2017-03-11 11:30:18 +00:00
|
|
|
if (startArg) {
|
2018-03-01 00:06:12 +00:00
|
|
|
this.start();
|
2017-03-11 11:30:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
text(textArg) {
|
2018-03-01 00:06:12 +00:00
|
|
|
this._oraObject.text = textArg;
|
2017-03-11 11:30:18 +00:00
|
|
|
}
|
2016-10-16 00:26:43 +00:00
|
|
|
|
2017-03-11 11:30:18 +00:00
|
|
|
start(textArg?: string, colorArg?: string) {
|
2018-03-01 00:06:12 +00:00
|
|
|
if (textArg) {
|
|
|
|
this.text(textArg);
|
|
|
|
}
|
|
|
|
if (colorArg) {
|
|
|
|
this._oraObject.color = colorArg;
|
|
|
|
}
|
|
|
|
activeOra = this;
|
|
|
|
oraActive = true;
|
|
|
|
this._oraObject.start();
|
2017-03-11 11:30:18 +00:00
|
|
|
}
|
|
|
|
end() {
|
2018-03-01 00:06:12 +00:00
|
|
|
this._oraObject.stop();
|
|
|
|
this._oraObject.clear();
|
|
|
|
activeOra = undefined;
|
|
|
|
oraActive = false;
|
2017-03-11 11:30:18 +00:00
|
|
|
}
|
|
|
|
endOk(textArg) {
|
2018-03-01 00:06:12 +00:00
|
|
|
this.end();
|
|
|
|
logNode('ok', textArg);
|
2017-03-11 11:30:18 +00:00
|
|
|
}
|
|
|
|
endError(textArg) {
|
2018-03-01 00:06:12 +00:00
|
|
|
this.end();
|
|
|
|
logNode('error', textArg);
|
2017-03-11 11:30:18 +00:00
|
|
|
}
|
|
|
|
pause() {
|
2018-03-01 00:06:12 +00:00
|
|
|
this._oraObject.stop();
|
2017-03-11 11:30:18 +00:00
|
|
|
}
|
2018-03-01 00:06:12 +00:00
|
|
|
stop() {
|
|
|
|
// alias for end
|
|
|
|
this.end();
|
2017-03-11 11:30:18 +00:00
|
|
|
}
|
2016-10-16 00:26:43 +00:00
|
|
|
}
|
2017-01-21 22:12:39 +00:00
|
|
|
|
2018-03-01 00:06:12 +00:00
|
|
|
export let ora = new Ora('init...', 'blue', false);
|