now has sync and async functions for figlet

This commit is contained in:
Philipp Kunz 2016-02-11 18:59:02 +01:00
parent 1691b89fcf
commit cdbc6a4e7f
6 changed files with 59 additions and 30 deletions

3
index.d.ts vendored
View File

@ -27,7 +27,8 @@ declare module BeautylogNodeTable {
function init(): any;
}
declare module BeautylogNodeFiglet {
var init: () => (textArg: string, optionsArg?: any) => void;
var figlet: (textArg: string, optionsArg?: any) => any;
var figletSync: (textArg: string, optionsArg?: any) => boolean;
}
declare module BeautylogBrowser {
function init(): any;

View File

@ -76,7 +76,8 @@ var BeautylogNode;
var beautylogNode = {
log: BeautylogNodeLog.init(),
code: BeautylogNodeCode.init(),
figlet: BeautylogNodeFiglet.init()
figlet: BeautylogNodeFiglet.figlet,
figletSync: BeautylogNodeFiglet.figletSync
};
/**
* logs an directory to console
@ -232,13 +233,15 @@ var BeautylogNodeTable;
/// <reference path="./index.ts" />
var BeautylogNodeFiglet;
(function (BeautylogNodeFiglet) {
var figlet = function (textArg, optionsArg) {
var defaultOptions = {
font: "Star Wars",
color: "green",
cb: function () { }
};
var options = plugins.lodash.assign(defaultOptions, optionsArg);
var defaultOptions = {
font: "Star Wars",
color: "green",
cb: function () { }
};
BeautylogNodeFiglet.figlet = function (textArg, optionsArg) {
var done = plugins.q.defer();
var mergeOptions = plugins.lodash.cloneDeep(defaultOptions);
var options = plugins.lodash.assign(mergeOptions, optionsArg);
plugins.figlet(textArg, {
font: options.font,
horizontalLayout: 'default',
@ -251,12 +254,19 @@ var BeautylogNodeFiglet;
}
console.log(data[options.color]);
options.cb();
done.resolve();
});
return done.promise;
};
BeautylogNodeFiglet.init = function () {
var done = plugins.q.defer();
done.resolve();
return figlet;
BeautylogNodeFiglet.figletSync = function (textArg, optionsArg) {
var mergeOptions = plugins.lodash.cloneDeep(defaultOptions);
var options = plugins.lodash.assign(mergeOptions, optionsArg);
console.log(plugins.figlet.textSync(textArg, {
font: options.font,
horizontalLayout: 'default',
verticalLayout: 'default'
})[options.color]);
return true;
};
})(BeautylogNodeFiglet || (BeautylogNodeFiglet = {}));
/// <reference path="./index.ts" />

View File

@ -64,8 +64,12 @@ describe("beautylog", function () {
});
describe(".figlet", function () {
it("should print nice fonts to console in yellow", function (done) {
this.timeout(10000);
beautylog.figlet("Awesome!", { font: "Star Wars", color: "yellow", cb: done });
beautylog.figlet("Async!", { font: "Star Wars", color: "yellow" }).then(done);
});
});
describe(".figletSync", function () {
it("should print nice fonts to console in yellow", function () {
beautylog.figletSync("Sync!", { font: "Star Wars", color: "blue" });
});
});
describe(".code", function () {

View File

@ -1,12 +1,14 @@
/// <reference path="./index.ts" />
module BeautylogNodeFiglet {
var figlet = function(textArg:string,optionsArg?){
var defaultOptions = {
font:"Star Wars",
color: "green",
cb: function(){}
};
var options = plugins.lodash.assign(defaultOptions,optionsArg);
var defaultOptions = {
font:"Star Wars",
color: "green",
cb: function(){}
};
export var figlet = function(textArg:string,optionsArg?){
var done = plugins.q.defer();
var mergeOptions = plugins.lodash.cloneDeep(defaultOptions);
var options = plugins.lodash.assign(mergeOptions,optionsArg);
plugins.figlet(textArg,{
font: options.font,
horizontalLayout: 'default',
@ -19,11 +21,18 @@ module BeautylogNodeFiglet {
}
console.log(data[options.color]);
options.cb();
done.resolve();
});
}
export var init = function(){
var done = plugins.q.defer();
done.resolve();
return figlet;
return done.promise;
};
export var figletSync = function(textArg:string,optionsArg?){
var mergeOptions = plugins.lodash.cloneDeep(defaultOptions);
var options = plugins.lodash.assign(mergeOptions,optionsArg);
console.log(plugins.figlet.textSync(textArg,{
font: options.font,
horizontalLayout: 'default',
verticalLayout: 'default'
})[options.color]);
return true;
};
}

View File

@ -5,7 +5,8 @@ module BeautylogNode {
var beautylogNode:any = {
log:BeautylogNodeLog.init(),
code:BeautylogNodeCode.init(),
figlet:BeautylogNodeFiglet.init()
figlet:BeautylogNodeFiglet.figlet,
figletSync:BeautylogNodeFiglet.figletSync
};
/**

View File

@ -64,8 +64,12 @@ describe("beautylog",function(){
});
describe(".figlet",function(){
it("should print nice fonts to console in yellow",function(done){
this.timeout(10000);
beautylog.figlet("Awesome!",{font:"Star Wars",color:"yellow",cb:done});
beautylog.figlet("Async!",{font:"Star Wars",color:"yellow"}).then(done);
})
});
describe(".figletSync",function(){
it("should print nice fonts to console in yellow",function(){
beautylog.figletSync("Sync!",{font:"Star Wars",color:"blue"});
})
});
describe(".code",function(){