normal log function now respects an active Ora.

This commit is contained in:
Philipp Kunz 2016-05-17 00:24:56 +02:00
parent cfd116421c
commit b319ec41f0
8 changed files with 43 additions and 15 deletions

View File

@ -1,3 +1,5 @@
export declare let isOraActive: boolean;
export declare let activeOra: Ora;
export declare class Ora {
private _oraObject;
state: string;

View File

@ -1,7 +1,8 @@
"use strict";
/// <reference path="./typings/main.d.ts" />
var plugins = require("./beautylog.plugins");
var log = require("./beautylog.log");
var beautylog_log_helpers_1 = require("./beautylog.log.helpers");
exports.isOraActive = false; // when an Ora is active (e.g. start()) this is true;
var Ora = (function () {
function Ora(textArg, colorArg, startArg) {
if (startArg === void 0) { startArg = false; }
@ -21,21 +22,25 @@ var Ora = (function () {
this._oraObject.text = textArg;
if (colorArg)
this._oraObject.color = colorArg;
exports.activeOra = this;
exports.isOraActive = true;
this._oraObject.start();
};
;
Ora.prototype.end = function () {
this._oraObject.stop();
this._oraObject.clear();
exports.activeOra = undefined;
exports.isOraActive = false;
};
Ora.prototype.endOk = function (textArg) {
this.end();
log.ok(textArg);
beautylog_log_helpers_1.logNode(textArg, "ok");
};
;
Ora.prototype.endError = function (textArg) {
this.end();
log.error(textArg);
beautylog_log_helpers_1.logNode(textArg, "error");
};
;
Ora.prototype.stop = function () {
@ -44,11 +49,11 @@ var Ora = (function () {
// log methods that play nice with ora
Ora.prototype.log = function (logText, logType) {
this.stop();
log.log(logText, logType);
beautylog_log_helpers_1.logNode(logText, logType);
this.start();
};
return Ora;
}());
exports.Ora = Ora;
//# sourceMappingURL=data:application/json;charset=utf8;base64,eyJ2ZXJzaW9uIjozLCJzb3VyY2VzIjpbImJlYXV0eWxvZy5jbGFzc2VzLm9yYS50cyJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiO0FBQUEsNENBQTRDO0FBQzVDLElBQVksT0FBTyxXQUFNLHFCQUFxQixDQUFDLENBQUE7QUFDL0MsSUFBWSxHQUFHLFdBQU0saUJBQWlCLENBQUMsQ0FBQTtBQUV2QztJQUdJ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0aGlzLmVuZCgpO1xyXG4gICAgfVxyXG4gICAgXHJcbiAgICAvLyBsb2cgbWV0aG9kcyB0aGF0IHBsYXkgbmljZSB3aXRoIG9yYVxyXG4gICAgbG9nKGxvZ1RleHQ6c3RyaW5nLGxvZ1R5cGU6c3RyaW5nKXtcclxuICAgICAgICB0aGlzLnN0b3AoKTtcclxuICAgICAgICBsb2dOb2RlKGxvZ1RleHQsbG9nVHlwZSk7XHJcbiAgICAgICAgdGhpcy5zdGFydCgpO1xyXG4gICAgfVxyXG59Il19

View File

@ -5,3 +5,4 @@
* @returns {boolean}
*/
export declare let log: (logText?: string, logType?: string) => void;
export declare let logNode: (logText: string, logType: string) => boolean;

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@ -53,6 +53,7 @@ describe("beautylog",function(){
setTimeout(function(){
testOra.text("updated text!");
testOra.log("an intermediate log message","info");
beautylog.info("another log message that uses the normal log function");
setTimeout(function(){
testOra.endOk("Allright, ora works!");
done();

View File

@ -1,6 +1,9 @@
/// <reference path="./typings/main.d.ts" />
import * as plugins from "./beautylog.plugins";
import * as log from "./beautylog.log";
import {logNode} from "./beautylog.log.helpers";
export let isOraActive:boolean = false; // when an Ora is active (e.g. start()) this is true;
export let activeOra:Ora; //points to the currently active Ora object
export class Ora {
private _oraObject;
@ -21,19 +24,23 @@ export class Ora {
start(textArg?:string,colorArg?:string){
if(textArg) this._oraObject.text = textArg;
if(colorArg) this._oraObject.color = colorArg;
activeOra = this;
isOraActive = true;
this._oraObject.start();
};
end(){
this._oraObject.stop();
this._oraObject.clear();
activeOra = undefined;
isOraActive = false;
}
endOk(textArg){
this.end();
log.ok(textArg);
logNode(textArg,"ok");
};
endError(textArg){
this.end();
log.error(textArg);
logNode(textArg,"error");
};
stop(){ // alias for end
this.end();
@ -42,7 +49,7 @@ export class Ora {
// log methods that play nice with ora
log(logText:string,logType:string){
this.stop();
log.log(logText,logType);
logNode(logText,logType);
this.start();
}
}

View File

@ -1,6 +1,7 @@
/// <reference path="./typings/main.d.ts" />
import plugins = require("./beautylog.plugins");
import {isOraActive,activeOra} from "./beautylog.classes.ora";
var localBl = {
dirPrefix: plugins.clc.bgXterm(39).xterm(231).bold(' DIR ') + ' ',
@ -21,7 +22,11 @@ var localBl = {
export let log = function(logText:string = 'empty log', logType:string = 'normal') {
switch(plugins.smartenv.getEnv().runtimeEnv) {
case "node":
logNode(logText,logType);
if (isOraActive){
activeOra.log(logText,logType);
} else {
logNode(logText,logType);
}
break;
case "browser":
logBrowser(logText,logType);
@ -32,7 +37,7 @@ export let log = function(logText:string = 'empty log', logType:string = 'normal
}
};
let logNode = function(logText:string,logType:string){
export let logNode = function(logText:string,logType:string){
try {
switch (logType) {
case 'dir':