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

52 lines
1.3 KiB
TypeScript
Raw Normal View History

2016-10-16 00:26:43 +00:00
import 'typings-global'
import * as plugins from './beautylog.plugins'
import {logNode} from './beautylog.log.helpers'
2016-10-16 00:26:43 +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 {
2016-10-16 00:26:43 +00:00
state: string
private _oraObject
constructor(textArg: string,colorArg: string,startArg: boolean = false) {
2016-05-13 23:18:44 +00:00
this._oraObject = plugins.ora({
2016-10-16 00:26:43 +00:00
spinner: 'dots',
text: textArg,
color: colorArg
})
startArg ? this._oraObject.start() : void(0)
}
text(textArg) {
this._oraObject.text = textArg
}
start(textArg?: string,colorArg?: string) {
if (textArg) { this._oraObject.text = textArg }
if (colorArg) { this._oraObject.color = colorArg }
activeOra = this
oraActive = true
this._oraObject.start()
}
end() {
this._oraObject.stop()
this._oraObject.clear()
activeOra = undefined
oraActive = false
}
endOk(textArg) {
this.end()
logNode('ok',textArg)
}
endError(textArg) {
this.end()
logNode('error',textArg)
}
pause() {
this._oraObject.stop()
}
stop() { // alias for end
this.end()
}
}