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; function init(): any;
} }
declare module BeautylogNodeFiglet { 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 { declare module BeautylogBrowser {
function init(): any; function init(): any;

View File

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

View File

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

View File

@ -1,12 +1,14 @@
/// <reference path="./index.ts" /> /// <reference path="./index.ts" />
module BeautylogNodeFiglet { module BeautylogNodeFiglet {
var figlet = function(textArg:string,optionsArg?){ var defaultOptions = {
var defaultOptions = { font:"Star Wars",
font:"Star Wars", color: "green",
color: "green", cb: function(){}
cb: function(){} };
}; export var figlet = function(textArg:string,optionsArg?){
var options = plugins.lodash.assign(defaultOptions,optionsArg); var done = plugins.q.defer();
var mergeOptions = plugins.lodash.cloneDeep(defaultOptions);
var options = plugins.lodash.assign(mergeOptions,optionsArg);
plugins.figlet(textArg,{ plugins.figlet(textArg,{
font: options.font, font: options.font,
horizontalLayout: 'default', horizontalLayout: 'default',
@ -19,11 +21,18 @@ module BeautylogNodeFiglet {
} }
console.log(data[options.color]); console.log(data[options.color]);
options.cb(); options.cb();
done.resolve();
}); });
} return done.promise;
export var init = function(){ };
var done = plugins.q.defer(); export var figletSync = function(textArg:string,optionsArg?){
done.resolve(); var mergeOptions = plugins.lodash.cloneDeep(defaultOptions);
return figlet; 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 = { var beautylogNode:any = {
log:BeautylogNodeLog.init(), log:BeautylogNodeLog.init(),
code:BeautylogNodeCode.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(){ describe(".figlet",function(){
it("should print nice fonts to console in yellow",function(done){ it("should print nice fonts to console in yellow",function(done){
this.timeout(10000); beautylog.figlet("Async!",{font:"Star Wars",color:"yellow"}).then(done);
beautylog.figlet("Awesome!",{font:"Star Wars",color:"yellow",cb: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(){ describe(".code",function(){