smartlog-destination-local/ts/beautylog.figlet.ts

61 lines
1.7 KiB
TypeScript
Raw Normal View History

2018-03-01 00:06:12 +00:00
import plugins = require('./beautylog.plugins');
2017-01-21 18:04:40 +00:00
export interface IFigletOptions {
2018-03-01 00:06:12 +00:00
font?: string;
color?: plugins.beautycolor.TColorName;
cb?;
2017-01-21 18:04:40 +00:00
}
let defaultOptions: IFigletOptions = {
2018-03-01 00:06:12 +00:00
font: 'Star Wars',
color: 'green',
cb: function() {}
};
2016-05-02 00:23:40 +00:00
2018-03-01 00:06:12 +00:00
export let figlet = function(textArg: string, optionsArg?) {
let done = plugins.q.defer();
let mergeOptions = plugins.lodash.cloneDeep(defaultOptions);
let options = plugins.lodash.assign(mergeOptions, optionsArg);
plugins.figlet(
textArg,
{
font: options.font,
horizontalLayout: 'default',
verticalLayout: 'default'
},
function(err, data: string) {
if (err) {
console.log('Something went wrong...');
console.dir(err);
return;
}
console.log(colorFiglet(data, options.color));
options.cb();
done.resolve();
}
);
return done.promise;
};
2016-05-02 00:23:40 +00:00
2018-03-01 00:06:12 +00:00
export let figletSync = function(textArg: string, optionsArg?: IFigletOptions) {
let mergeOptions = plugins.lodash.cloneDeep(defaultOptions);
let options = plugins.lodash.assign(mergeOptions, optionsArg);
let figletString: string = plugins.figlet.textSync(textArg, {
font: options.font,
horizontalLayout: 'default',
verticalLayout: 'default'
});
console.log(colorFiglet(figletString, options.color));
return true;
};
2017-01-21 18:04:40 +00:00
let colorFiglet = (figletStringArg, colorArg: plugins.beautycolor.TColorName) => {
2018-03-01 00:06:12 +00:00
let figletArray = figletStringArg.split('\n');
let figletStringCombined = '';
for (let figletRow of figletArray) {
figletRow = plugins.beautycolor.coloredString(figletRow, colorArg);
figletStringCombined = figletStringCombined + figletRow + '\n';
}
return figletStringCombined;
};