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