Comparing version 2.0.1 to 2.1.0
@@ -17,64 +17,6 @@ #!/usr/bin/env node | ||
//-------------------------------------------------------------------------------------------------------------------------------------------------------------- | ||
// Dependencies | ||
//-------------------------------------------------------------------------------------------------------------------------------------------------------------- | ||
var _stringify = require('babel-runtime/core-js/json/stringify'); | ||
var CFonts = require('..'); | ||
var _stringify2 = _interopRequireDefault(_stringify); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
var CFonts = require('../lib/index.js'); | ||
var Program = require('commander'); | ||
var Chalk = require('chalk'); | ||
var Path = require('path'); | ||
var Fs = require('fs'); | ||
var Package = JSON.parse(Fs.readFileSync(Path.normalize(__dirname + '/../package.json'), 'utf8')); | ||
var Version = Package.version; | ||
//-------------------------------------------------------------------------------------------------------------------------------------------------------------- | ||
// Setting up command line tool | ||
//-------------------------------------------------------------------------------------------------------------------------------------------------------------- | ||
Program.usage('"<value>" [option1] <input1> [option2] <input1>,<input2> [option3]\n' + (' Example: $ ' + Chalk.bold('cfonts "sexy font" -f chrome -a center -c red,green,gray'))).description('This is a tool for sexy fonts in the console. Give your cli some love.').version('v' + Version).option('-f, --font <keyword>', 'define "font face"', 'block').option('-a, --align <keyword>', 'define "alignment" for the text', 'left').option('-c, --colors <keyword>,<keyword>...', 'provide colors for text; comma separated (no space)', 'system').option('-b, --background <keyword>', 'provide background color', 'transparent').option('-l, --letter-spacing <n>', 'define letter spacing {integer}').option('-z, --line-height <n>', 'define line height {integer}', 1).option('-s, --spaceless', 'surpress space on top and on the bottom').option('-m, --max-length <keyword>', 'define how many character can be on one line').action(function (text) { | ||
Program.text = text; //add flagless option for text | ||
}).on('--help', function () { | ||
//adding options for each keyword section | ||
console.log(Chalk.bold(' Font face options:')); | ||
console.log(' [ ' + CFonts.FONTFACES.join(', ') + ' ]\n'); | ||
console.log(Chalk.bold(' Alignment options:')); | ||
console.log(' [ ' + CFonts.ALIGNMENT.join(', ') + ' ]\n'); | ||
console.log(Chalk.bold(' Color options:')); | ||
console.log(' [ ' + CFonts.COLORS.join(', ') + ' ]\n'); | ||
console.log(Chalk.bold(' background color options:')); | ||
console.log(' [ ' + CFonts.BGCOLORS.join(', ') + ' ]\n'); | ||
}).parse(process.argv); | ||
//-------------------------------------------------------------------------------------------------------------------------------------------------------------- | ||
// Execute program | ||
//-------------------------------------------------------------------------------------------------------------------------------------------------------------- | ||
if (Program.text !== undefined) { | ||
//log OPTIONS for debugging | ||
if (CFonts.DEBUG) { | ||
CFonts.Debugging.report('OPTIONS:\n' + (' CFonts.say("' + Program.text + '", {\n') + ('\t\'font\': "' + Program.font + '",\n') + ('\t\'align\': "' + Program.align + '",\n') + ('\t\'colors\': ' + (Program.colors ? (0, _stringify2.default)(Program.colors.split(',')) : []) + ',\n') + ('\t\'background\': "' + Program.background + '",\n') + ('\t\'letterSpacing\': ' + Program.letterSpacing + ',\n') + ('\t\'lineHeight\': ' + Program.lineHeight + ',\n') + ('\t\'space\': ' + (Program.spaceless ? false : true) + ',\n') + ('\t\'maxLength\': ' + Program.maxLength + '\n') + ' });', 3); | ||
} | ||
//execute cfonts | ||
CFonts.say(Program.text, { | ||
'font': Program.font, | ||
'align': Program.align, | ||
'colors': Program.colors ? Program.colors.split(',') : [], | ||
'background': Program.background, | ||
'letterSpacing': Program.letterSpacing, | ||
'lineHeight': Program.lineHeight, | ||
'space': Program.spaceless ? false : true, | ||
'maxLength': Program.maxLength | ||
}); | ||
} else { | ||
//we do need text to convert | ||
CFonts.Log.error('Please provide text to convert with ' + Chalk.green('cfonts "Text"') + '\n' + ('Run ' + Chalk.green('cfonts --help') + ' for more infos')); | ||
} | ||
CFonts.__test__.Cli(); |
498
lib/index.js
@@ -17,2 +17,6 @@ /*************************************************************************************************************************************************************** | ||
var _stringify = require('babel-runtime/core-js/json/stringify'); | ||
var _stringify2 = _interopRequireDefault(_stringify); | ||
var _repeat = require('babel-runtime/core-js/string/repeat'); | ||
@@ -26,2 +30,6 @@ | ||
var _keys = require('babel-runtime/core-js/object/keys'); | ||
var _keys2 = _interopRequireDefault(_keys); | ||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
@@ -36,10 +44,142 @@ | ||
// settings | ||
// global defaults | ||
var DEBUG = false; | ||
var DEBUGLEVEL = 2; | ||
var CHARS = ["A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "|", "!", "?", ".", "+", "-", "_", "=", "@", "#", "$", "%", "&", "(", ")", "/", ":", ";", ",", " "]; | ||
var COLORS = ['system', 'black', 'red', 'green', 'yellow', 'blue', 'magenta', 'cyan', 'white', 'gray', 'redBright', 'greenBright', 'yellowBright', 'blueBright', 'magentaBright', 'cyanBright', 'whiteBright']; | ||
var BGCOLORS = ['transparent', 'black', 'red', 'green', 'yellow', 'blue', 'magenta', 'cyan', 'white', 'blackBright', 'redBright', 'greenBright', 'yellowBright', 'blueBright', 'magentaBright', 'cyanBright', 'whiteBright']; | ||
var COLORS = { | ||
system: 'system', | ||
black: 'black', | ||
red: 'red', | ||
green: 'green', | ||
yellow: 'yellow', | ||
blue: 'blue', | ||
magenta: 'magenta', | ||
cyan: 'cyan', | ||
white: 'white', | ||
gray: 'gray', | ||
redbright: 'redBright', | ||
greenbright: 'greenBright', | ||
yellowbright: 'yellowBright', | ||
bluebright: 'blueBright', | ||
magentabright: 'magentaBright', | ||
cyanbright: 'cyanBright', | ||
whitebright: 'whiteBright' | ||
}; | ||
var BGCOLORS = { | ||
transparent: 'transparent', | ||
black: 'black', | ||
red: 'red', | ||
green: 'green', | ||
yellow: 'yellow', | ||
blue: 'blue', | ||
magenta: 'magenta', | ||
cyan: 'cyan', | ||
white: 'white', | ||
blackbright: 'blackBright', | ||
redbright: 'redBright', | ||
greenbright: 'greenBright', | ||
yellowbright: 'yellowBright', | ||
bluebright: 'blueBright', | ||
magentabright: 'magentaBright', | ||
cyanbright: 'cyanBright', | ||
whitebright: 'whiteBright' | ||
}; | ||
var ALIGNMENT = ['left', 'center', 'right']; | ||
var FONTFACES = ['console', 'block', 'simpleBlock', 'simple', '3d', 'simple3d', 'chrome', 'huge']; | ||
var FONTFACES = { | ||
console: 'console', | ||
block: 'block', | ||
simpleblock: 'simpleBlock', | ||
simple: 'simple', | ||
'3d': '3d', | ||
simple3d: 'simple3d', | ||
chrome: 'chrome', | ||
huge: 'huge' | ||
}; | ||
var CLIOPTIONS = { | ||
'--version': { | ||
description: 'Use to display the version of cfonts', | ||
example: '--version', | ||
short: '-v', | ||
default: false | ||
}, | ||
'--help': { | ||
description: 'Use to display this help', | ||
example: '--help', | ||
short: '-h', | ||
default: false | ||
}, | ||
'--font': { | ||
description: 'Use to define the font face', | ||
example: '--font block', | ||
short: '-f', | ||
options: (0, _keys2.default)(FONTFACES).map(function (color) { | ||
return FONTFACES[color]; | ||
}), | ||
default: 'block' | ||
}, | ||
'--colors': { | ||
description: 'Use to define the font color', | ||
example: '--colors block', | ||
short: '-c', | ||
options: true, // Object.keys( COLORS ).map( color => COLORS[ color ] ), | ||
default: 'system' | ||
}, | ||
'--background': { | ||
description: 'Use to define background color', | ||
example: '--background block', | ||
short: '-b', | ||
options: (0, _keys2.default)(BGCOLORS).map(function (color) { | ||
return BGCOLORS[color]; | ||
}), | ||
default: 'transparent' | ||
}, | ||
'--align': { | ||
description: 'Use to align your text output', | ||
example: '--align block', | ||
short: '-a', | ||
options: ALIGNMENT, | ||
default: 'left' | ||
}, | ||
'--letter-spacing': { | ||
description: 'Use to define your letter spacing', | ||
example: '--letter-spacing 2', | ||
short: '-l', | ||
options: true, | ||
default: 1 | ||
}, | ||
'--line-height': { | ||
description: 'Use to define your line height', | ||
example: '--line-height 5', | ||
short: '-z', | ||
options: true, | ||
default: 1 | ||
}, | ||
'--spaceless': { | ||
description: 'Use to disable the padding around your output', | ||
example: '--spaceless', | ||
short: '-s', | ||
default: 1 | ||
}, | ||
'--max-length': { | ||
description: 'Use to define the amount of maximum characters per line', | ||
example: '--max-length 10', | ||
short: '-m', | ||
options: true, | ||
default: 1 | ||
}, | ||
'--debug': { | ||
description: 'Use to enable debug mode', | ||
example: '--debug', | ||
short: '-d', | ||
default: false | ||
}, | ||
'--debug-level': { | ||
description: 'Use to define the debug level. The higher, the less debug infos', | ||
example: '--debug-level 2', | ||
short: '-m', | ||
options: true, | ||
default: 1 | ||
} | ||
}; | ||
var PACKAGE = JSON.parse(Fs.readFileSync(Path.normalize(__dirname + '/../package.json'), 'utf8')); | ||
@@ -312,14 +452,17 @@ /** | ||
* | ||
* @param {string} INPUT - The string you want to write out | ||
* @param {object} FONTFACES - All allowed fontfaces | ||
* @param {string} font - The font the user chose | ||
* @param {array} colors - The color the user chose | ||
* @param {string} background - The background the user chose | ||
* @param {string} align - The alignment the user chose | ||
* @param {string} INPUT - The string you want to write out | ||
* @param {string} userFont - The user specified font | ||
* @param {array} userColors - The user specified colors | ||
* @param {string} userBackground - The user specified background color | ||
* @param {string} userAlign - The user specified alignment option | ||
* @param {object} fontfaces - All allowed fontfaces | ||
* @param {object} colors - All allowed font colors | ||
* @param {object} bgcolors - All allowed background colors | ||
* @param {array} alignment - All allowed alignments | ||
* | ||
* @typedef {object} ReturnObject | ||
* @property {boolean} pass - Whether the input is valid | ||
* @property {string} message - Possible error messages | ||
* @property {boolean} pass - Whether the input is valid | ||
* @property {string} message - Possible error messages | ||
* | ||
* @return {ReturnObject} - An object with error messages and a pass key | ||
* @return {ReturnObject} - An object with error messages and a pass key | ||
*/ | ||
@@ -341,5 +484,7 @@ var CheckInput = function CheckInput(INPUT, userFont, userColors, userBackground, userAlign) { | ||
// checking font | ||
if (fontfaces.indexOf(userFont) === -1) { | ||
if ((0, _keys2.default)(fontfaces).indexOf(userFont.toLowerCase()) === -1) { | ||
return { | ||
message: '"' + Chalk.red(userFont) + '" is not a valid font option.\n' + ('Please use a font from the supported stack:\n' + Chalk.green('[ ' + FONTFACES.join(' | ') + ' ]')), | ||
message: '"' + Chalk.red(userFont) + '" is not a valid font option.\n' + ('Please use a font from the supported stack:\n' + Chalk.green((0, _keys2.default)(fontfaces).map(function (font) { | ||
return fontfaces[font]; | ||
}).join(', '))), | ||
pass: false | ||
@@ -352,5 +497,7 @@ }; | ||
// check color usage | ||
if (colors.indexOf(userColors[color]) === -1 && userColors[color] !== 'candy') { | ||
if ((0, _keys2.default)(colors).indexOf(userColors[color].toLowerCase()) === -1 && userColors[color] !== 'candy') { | ||
return { | ||
message: '"' + Chalk.red(userColors[color]) + '" is not a valid font color option.\n' + ('Please use a color from the supported stack:\n' + Chalk.green('[ ' + colors.join(' | ') + ' | candy ]')), | ||
message: '"' + Chalk.red(userColors[color]) + '" is not a valid font color option.\n' + ('Please use a color from the supported stack:\n' + Chalk.green((0, _keys2.default)(colors).map(function (color) { | ||
return colors[color]; | ||
}).join(', ') + ', candy')), | ||
pass: false | ||
@@ -362,5 +509,7 @@ }; | ||
// checking background colors | ||
if (bgcolors.indexOf(userBackground) === -1) { | ||
if ((0, _keys2.default)(bgcolors).indexOf(userBackground.toLowerCase()) === -1) { | ||
return { | ||
message: '"' + Chalk.red(userBackground) + '" is not a valid background option.\n' + ('Please use a color from the supported stack:\n' + Chalk.green('[ ' + bgcolors.join(' | ') + ' ]')), | ||
message: '"' + Chalk.red(userBackground) + '" is not a valid background option.\n' + ('Please use a color from the supported stack:\n' + Chalk.green((0, _keys2.default)(bgcolors).map(function (bgcolor) { | ||
return bgcolors[bgcolor]; | ||
}).join(', '))), | ||
pass: false | ||
@@ -371,5 +520,5 @@ }; | ||
// CHECKING ALIGNMENT | ||
if (alignment.indexOf(userAlign) === -1) { | ||
if (alignment.indexOf(userAlign.toLowerCase()) === -1) { | ||
return { | ||
message: '"' + Chalk.red(userAlign) + '" is not a valid alignment option.\n' + ('Please use an alignment option from the supported stack:\n' + Chalk.green('[ ' + alignment.join(' | ') + ' ]')), | ||
message: '"' + Chalk.red(userAlign) + '" is not a valid alignment option.\n' + ('Please use an alignment option from the supported stack:\n' + Chalk.green(alignment.join(' | '))), | ||
pass: false | ||
@@ -461,7 +610,11 @@ }; | ||
var clean = INPUT.split('').filter(function (char) { | ||
return chars.includes(char.toUpperCase()); | ||
}).join(''); | ||
if (typeof INPUT === 'string') { | ||
var clean = INPUT.split('').filter(function (char) { | ||
return chars.includes(char.toUpperCase()); | ||
}).join(''); | ||
return clean; | ||
return clean; | ||
} else { | ||
return ''; | ||
} | ||
}; | ||
@@ -472,3 +625,6 @@ | ||
* | ||
* @param {SETTINGS} SETTINGS - Some or all of the allowed settings | ||
* @param {SETTINGS} SETTINGS - Some or all of the allowed settings | ||
* @param {array} allowedColors - All allowed font colors | ||
* @param {array} allowedBG - All allowed background colors | ||
* @param {array} allowedFont - All allowed fontfaces | ||
* | ||
@@ -497,10 +653,15 @@ * @typedef {object} SETTINGS | ||
maxLength = _ref.maxLength; | ||
var allowedColors = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : COLORS; | ||
var allowedBG = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : BGCOLORS; | ||
var allowedFont = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : FONTFACES; | ||
return { | ||
font: font || 'block', | ||
align: align || 'left', | ||
colors: colors || [], | ||
background: background || backgroundColor || 'transparent', | ||
letterSpacing: letterSpacing === undefined ? 1 : letterSpacing, | ||
font: font === undefined ? 'block' : allowedFont[font.toLowerCase()] || font, | ||
align: align === undefined ? 'left' : align.toLowerCase(), | ||
colors: Array.isArray(colors) ? colors.map(function (color) { | ||
return allowedColors[color.toLowerCase()] || color; | ||
}) : [], | ||
background: background === undefined && backgroundColor === undefined ? 'transparent' : background === undefined ? allowedBG[backgroundColor.toLowerCase()] || backgroundColor : allowedBG[background.toLowerCase()] || background, | ||
letterSpacing: typeof letterSpacing === 'number' && letterSpacing > 0 ? letterSpacing : 1, | ||
lineHeight: lineHeight === undefined ? 1 : parseInt(lineHeight), | ||
space: space === undefined ? true : space, | ||
space: typeof space === 'boolean' ? space : true, | ||
maxLength: maxLength || 0 | ||
@@ -515,2 +676,4 @@ }; | ||
* @param {object} SETTINGS - Settings object | ||
* @param {boolean} debug - A flag to enable debug mode | ||
* @param {integer} debuglevel - The debug level we want to show | ||
* @param {object} size - The size of the terminal as an object, default: Size | ||
@@ -530,11 +693,17 @@ * @param {integer} size.width - The width of the terminal | ||
var SETTINGS = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
var size = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : Size; | ||
var debug = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : DEBUG; | ||
var debuglevel = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : DEBUGLEVEL; | ||
var size = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : Size; | ||
Debugging.report('Running render', 1); | ||
DEBUG = debug; | ||
DEBUGLEVEL = debuglevel; | ||
var INPUT = CleanInput(input, CHARS); | ||
var OPTIONS = GetOptions(SETTINGS); | ||
var output = []; // for output where each line is an output line | ||
var lines = 0; // for counting each line | ||
var FONTFACE = {}; // scoping the fontface object higher for fonts with just one color | ||
var OPTIONS = GetOptions(SETTINGS); | ||
@@ -545,3 +714,3 @@ var _isGoodHuman = CheckInput(INPUT, OPTIONS.font, OPTIONS.colors, OPTIONS.background, OPTIONS.align); | ||
process.exit(1); // exit program with failure code | ||
return false; | ||
} | ||
@@ -557,3 +726,3 @@ | ||
Debugging.report(outOption, 2); | ||
Debugging.report(outOption, 3); | ||
} | ||
@@ -577,5 +746,5 @@ | ||
if (!FONTFACE) { | ||
Log.error('Font file for "' + font + '" could not be found.\nTry reinstalling this package.'); | ||
Log.error('Font file for the font "' + font + '" could not be found.\nTry reinstalling this package.'); | ||
process.exit(1); | ||
return false; | ||
} | ||
@@ -612,50 +781,43 @@ | ||
// iterate through the message | ||
var CHAR = INPUT.charAt(_i).toUpperCase(); // the current character we convert, only upper case is supported at this time | ||
var lastLineLength = lineLength; // we need the lineLength for alignment before we look up if the next char fits | ||
if (FONTFACE.chars[CHAR] === undefined && CHAR !== '|') { | ||
// make sure this character exists in the font | ||
Debugging.error('Character not found in font: "' + CHAR + '"', 2); // fail silently | ||
} else { | ||
Debugging.report('Character found in font: "' + CHAR + '"', 2); | ||
Debugging.report('Character found in font: "' + CHAR + '"', 2); | ||
var lastLineLength = lineLength; // we need the lineLength for alignment before we look up if the next char fits | ||
if (CHAR !== '|') { | ||
// what will the line length be if we add the next char? | ||
lineLength += CharLength(FONTFACE.chars[CHAR], FONTFACE.lines, OPTIONS); // get the length of this character | ||
lineLength += CharLength(FONTFACE.letterspace, FONTFACE.lines, OPTIONS) * OPTIONS.letterSpacing; // new line, new line length | ||
} | ||
if (CHAR !== '|') { | ||
// what will the line length be if we add the next char? | ||
lineLength += CharLength(FONTFACE.chars[CHAR], FONTFACE.lines, OPTIONS); // get the length of this character | ||
lineLength += CharLength(FONTFACE.letterspace, FONTFACE.lines, OPTIONS) * OPTIONS.letterSpacing; // new line, new line length | ||
} | ||
// jump to next line after OPTIONS.maxLength characters or when line break is found or the console windows would have ran out of space | ||
if (maxChars >= OPTIONS.maxLength && OPTIONS.maxLength != 0 || CHAR === '|' || lineLength > size.width) { | ||
lines++; | ||
// jump to next line after OPTIONS.maxLength characters or when line break is found or the console windows would have ran out of space | ||
if (maxChars >= OPTIONS.maxLength && OPTIONS.maxLength != 0 || CHAR === '|' || lineLength > size.width) { | ||
lines++; | ||
Debugging.report('NEWLINE: maxChars: ' + maxChars + ', ' + ('OPTIONS.maxLength: ' + OPTIONS.maxLength + ', ') + ('CHAR: ' + CHAR + ', ') + ('lineLength: ' + lineLength + ', ') + ('Size.width: ' + size.width + ' '), 2); | ||
Debugging.report('NEWLINE: maxChars: ' + maxChars + ', ' + ('OPTIONS.maxLength: ' + OPTIONS.maxLength + ', ') + ('CHAR: ' + CHAR + ', ') + ('lineLength: ' + lineLength + ', ') + ('Size.width: ' + size.width + ' '), 2); | ||
output = AlignText(output, lastLineLength, FONTFACE.lines, OPTIONS.align, size); // calculate alignment based on lineLength | ||
output = AlignText(output, lastLineLength, FONTFACE.lines, OPTIONS.align, size); // calculate alignment based on lineLength | ||
lineLength = CharLength(FONTFACE.buffer, FONTFACE.lines, OPTIONS); // new line: new line length | ||
lineLength += CharLength(FONTFACE.letterspace, FONTFACE.lines, OPTIONS) * OPTIONS.letterSpacing; // each new line starts with letter spacing | ||
lineLength = CharLength(FONTFACE.buffer, FONTFACE.lines, OPTIONS); // new line: new line length | ||
lineLength += CharLength(FONTFACE.letterspace, FONTFACE.lines, OPTIONS) * OPTIONS.letterSpacing; // each new line starts with letter spacing | ||
if (CHAR !== '|') { | ||
// if this is a character and not a line break | ||
lineLength += CharLength(FONTFACE.chars[CHAR], FONTFACE.lines, OPTIONS); // get the length of this character | ||
lineLength += CharLength(FONTFACE.letterspace, FONTFACE.lines, OPTIONS) * OPTIONS.letterSpacing; // add letter spacing at the end | ||
} | ||
if (CHAR !== '|') { | ||
// if this is a character and not a line break | ||
lineLength += CharLength(FONTFACE.chars[CHAR], FONTFACE.lines, OPTIONS); // get the length of this character | ||
lineLength += CharLength(FONTFACE.letterspace, FONTFACE.lines, OPTIONS) * OPTIONS.letterSpacing; // add letter spacing at the end | ||
} | ||
maxChars = 0; // new line, new maxLength goal | ||
maxChars = 0; // new line, new maxLength goal | ||
output = AddLine(output, FONTFACE.lines, FONTFACE.buffer, OPTIONS.lineHeight); // adding new line | ||
// add letter spacing to the beginning | ||
output = AddLetterSpacing(output, FONTFACE.lines, FONTFACE.letterspace, FONTFACE.colors, OPTIONS.colors, OPTIONS.letterSpacing); | ||
} | ||
output = AddLine(output, FONTFACE.lines, FONTFACE.buffer, OPTIONS.lineHeight); // adding new line | ||
// add letter spacing to the beginning | ||
output = AddLetterSpacing(output, FONTFACE.lines, FONTFACE.letterspace, FONTFACE.colors, OPTIONS.colors, OPTIONS.letterSpacing); | ||
} | ||
Debugging.report('lineLength at: "' + lineLength + '"', 2); | ||
Debugging.report('lineLength at: "' + lineLength + '"', 2); | ||
if (CHAR !== '|') { | ||
maxChars++; // counting all printed characters | ||
output = AddChar(CHAR, output, FONTFACE.lines, FONTFACE.chars, FONTFACE.colors, OPTIONS.colors); // add new character | ||
output = AddLetterSpacing(output, FONTFACE.lines, FONTFACE.letterspace, FONTFACE.colors, OPTIONS.colors, OPTIONS.letterSpacing); | ||
} | ||
if (CHAR !== '|') { | ||
maxChars++; // counting all printed characters | ||
output = AddChar(CHAR, output, FONTFACE.lines, FONTFACE.chars, FONTFACE.colors, OPTIONS.colors); // add new character | ||
output = AddLetterSpacing(output, FONTFACE.lines, FONTFACE.letterspace, FONTFACE.colors, OPTIONS.colors, OPTIONS.letterSpacing); | ||
} | ||
@@ -699,11 +861,166 @@ } | ||
var SETTINGS = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : {}; | ||
var debug = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : DEBUG; | ||
var debuglevel = arguments.length > 3 && arguments[3] !== undefined ? arguments[3] : DEBUGLEVEL; | ||
var size = arguments.length > 4 && arguments[4] !== undefined ? arguments[4] : Size; | ||
Debugging.report('Running say', 1); | ||
var write = Render(INPUT, SETTINGS); | ||
DEBUG = debug; | ||
DEBUGLEVEL = debuglevel; | ||
console.log(write.string); // write out | ||
var write = Render(INPUT, SETTINGS, debug, debuglevel, size); | ||
if (write) { | ||
console.log(write.string); // write out | ||
} | ||
}; | ||
/** | ||
* Flatten the shortcuts in our cli options object | ||
* | ||
* @param {object} options - An object objects with a short key | ||
* | ||
* @return {object} - All short keys flattened into first level | ||
*/ | ||
var AddShortcuts = function AddShortcuts(options) { | ||
var flatOptions = (0, _assign2.default)({}, options); | ||
(0, _keys2.default)(flatOptions).forEach(function (option) { | ||
flatOptions[option]._name = option; | ||
flatOptions[flatOptions[option].short] = flatOptions[option]; | ||
}); | ||
return flatOptions; | ||
}; | ||
/** | ||
* Parse cli arguments into a nice object | ||
* | ||
* @param {array} inputOptions - All possible options registered for this app | ||
* @param {array} inputArgs - The arguments given to us in our cli, default: process.argv | ||
* | ||
* @return {object} - An object of all options with at least their default values | ||
*/ | ||
var ParseArgs = function ParseArgs() { | ||
var inputOptions = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : CLIOPTIONS; | ||
var inputArgs = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : process.argv; | ||
var parsedArgs = { | ||
text: inputArgs[2] | ||
}; | ||
// create defaults | ||
(0, _keys2.default)(inputOptions).forEach(function (option) { | ||
var name = option.replace('--', ''); | ||
parsedArgs[name] = inputOptions[option].default; | ||
}); | ||
if (inputArgs[2] === '--help' || inputArgs[2] === '-h') { | ||
parsedArgs.help = true; | ||
} | ||
if (inputArgs[2] === '--version' || inputArgs[2] === '-v') { | ||
parsedArgs.version = true; | ||
} | ||
var args = inputArgs.splice(3); // the first two are node specific, the third is our text | ||
var options = AddShortcuts(inputOptions); | ||
for (var index = 0; args.length > index; index++) { | ||
var option = options[args[index]]; | ||
if (option) { | ||
var name = option._name.replace('--', ''); | ||
if (option.options !== undefined) { | ||
index++; | ||
var value = args[index]; | ||
if (option.options === true) { | ||
parsedArgs[name] = value; | ||
} else { | ||
if (option.options.includes(value)) { | ||
parsedArgs[name] = value; | ||
} else { | ||
parsedArgs[name] = option.default; | ||
} | ||
} | ||
} else { | ||
parsedArgs[name] = true; | ||
} | ||
} else { | ||
Debugging.report('The cli argument ' + args[index] + ' was not found and ignored', 2); | ||
} | ||
}; | ||
return parsedArgs; | ||
}; | ||
/** | ||
* Display the help generated from our CLIOPTIONS | ||
*/ | ||
var DisplayHelp = function DisplayHelp() { | ||
console.log(' ' + Render('cfonts', { align: 'center', colors: ['redBright', 'greenBright'] }).string + 'This is a tool for sexy fonts in the console. Give your cli some love.\n\n' + 'Usage: cfonts "<value>" [option1] <input1> [option2] <input1>,<input2> [option3]\n' + ('Example: ' + Chalk.bold('$ cfonts "sexy font" -f chrome -a center -c red,green,gray') + '\n\n') + 'Options:\n'); | ||
var command = []; | ||
var largestSize = 0; | ||
(0, _keys2.default)(CLIOPTIONS).forEach(function (option) { | ||
console.log(Chalk.bold(option + ', ' + CLIOPTIONS[option].short)); | ||
console.log(CLIOPTIONS[option].description); | ||
console.log(Chalk.bold('$') + ' cfonts ' + option + (typeof CLIOPTIONS[option].options !== 'boolean' && typeof CLIOPTIONS[option].options !== 'undefined' ? Chalk.green(' ( ' + CLIOPTIONS[option].options.join(', ') + ' )') : '') + '\n'); | ||
}); | ||
}; | ||
/** | ||
* Display the version of this package | ||
*/ | ||
var DisplayVersion = function DisplayVersion() { | ||
console.log(PACKAGE.version); | ||
}; | ||
/** | ||
* Run cli commands | ||
* | ||
* @param {array} inputOptions - All possible options registered for this app | ||
* @param {array} inputArgs - The arguments given to us in our cli, default: process.argv | ||
*/ | ||
var Cli = function Cli() { | ||
var inputOptions = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : CLIOPTIONS; | ||
var inputArgs = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : process.argv; | ||
var args = ParseArgs(inputOptions, inputArgs); | ||
Debugging.report('OPTIONS:\n' + (' CFonts.say("' + args.text + '", {\n') + (' font: "' + args.font + '",\n') + (' align: "' + args.align + '",\n') + (' colors: ' + (args.colors ? (0, _stringify2.default)(args.colors.split(',')) : []) + ',\n') + (' background: "' + args.background + '",\n') + (' letterSpacing: ' + args.letterSpacing + ',\n') + (' lineHeight: ' + args.lineHeight + ',\n') + (' space: ' + args.spaceless + ',\n') + (' maxLength: ' + args.maxLength + '\n') + (' }, ' + args.debug + ', ' + args.debugLevel + ' );'), 3, args.debug, args.debugLevel); | ||
if (args.help) { | ||
DisplayHelp(); | ||
return; | ||
} | ||
if (args.version) { | ||
DisplayVersion(); | ||
return; | ||
} | ||
if (!args.text) { | ||
Log.error('Please provide text to convert with ' + Chalk.green('cfonts "Text"') + '\n' + ('Run ' + Chalk.green('cfonts --help') + ' for more infos')); | ||
return; | ||
} | ||
Say(args.text, { | ||
font: args.font, | ||
align: args.align, | ||
colors: args.colors ? args.colors.split(',') : [], | ||
background: args.background, | ||
letterSpacing: args.letterSpacing, | ||
lineHeight: args.lineHeight, | ||
space: args.spaceless, | ||
maxLength: args.maxLength | ||
}, args.debug, args.debugLevel); | ||
}; | ||
/** | ||
* Debugging prettiness | ||
@@ -781,17 +1098,18 @@ * | ||
// Module export | ||
// Export for API use and unit tests | ||
module.exports = exports = { | ||
render: Render, | ||
say: Say, | ||
DEBUG: DEBUG, | ||
DEBUGLEVEL: DEBUGLEVEL, | ||
CHARS: CHARS, | ||
COLORS: COLORS, | ||
BGCOLORS: BGCOLORS, | ||
ALIGNMENT: ALIGNMENT, | ||
FONTFACES: FONTFACES, | ||
Debugging: Debugging, | ||
Log: Log, | ||
__test__: { | ||
DEBUG: DEBUG, | ||
DEBUGLEVEL: DEBUGLEVEL, | ||
CHARS: CHARS, | ||
COLORS: COLORS, | ||
BGCOLORS: BGCOLORS, | ||
ALIGNMENT: ALIGNMENT, | ||
FONTFACES: FONTFACES, | ||
CLIOPTIONS: CLIOPTIONS, | ||
PACKAGE: PACKAGE, | ||
AddShortcuts: AddShortcuts, | ||
GetFont: GetFont, | ||
@@ -809,4 +1127,10 @@ CharLength: CharLength, | ||
CleanInput: CleanInput, | ||
GetOptions: GetOptions | ||
GetOptions: GetOptions, | ||
ParseArgs: ParseArgs, | ||
DisplayHelp: DisplayHelp, | ||
DisplayVersion: DisplayVersion, | ||
Cli: Cli, | ||
Debugging: Debugging, | ||
Log: Log | ||
} | ||
}; |
{ | ||
"name": "cfonts", | ||
"description": "Sexy fonts for the console", | ||
"version": "2.0.1", | ||
"version": "2.1.0", | ||
"homepage": "https://github.com/dominikwilkowski/cfonts", | ||
@@ -54,5 +54,4 @@ "author": { | ||
"babel-runtime": "^6.26.0", | ||
"chalk": "^2.3.2", | ||
"chalk": "^2.4.1", | ||
"change-case": "^3.0.2", | ||
"commander": "^2.15.1", | ||
"window-size": "^1.1.0" | ||
@@ -59,0 +58,0 @@ }, |
119
README.md
@@ -10,17 +10,10 @@ ```shell | ||
[![NPM](https://nodei.co/npm/cfonts.png?downloads=true)](https://nodei.co/npm/cfonts/) | ||
> This is a silly little command line tool for sexy fonts in the console. **Give your cli some love.** | ||
## Examples | ||
Different styles: | ||
![cfont styles](https://raw.githubusercontent.com/dominikwilkowski/cfonts/master/img/example1.png) | ||
Real world example: | ||
![api example](https://raw.githubusercontent.com/dominikwilkowski/cfonts/master/img/example2.png) | ||
<p align="center"><img src="https://raw.githubusercontent.com/dominikwilkowski/cfonts/master/img/example2.png" alt="api example"></p> | ||
<p align="center"><a href="https://nodei.co/npm/cfonts/"><img src="https://nodei.co/npm/cfonts.png?downloads=true" alt="npm status"></a></p> | ||
<p align="center"><a href="https://travis-ci.org/dominikwilkowski/cfonts"><img src="https://travis-ci.org/dominikwilkowski/cfonts.svg?branch=master" alt="build status"></a></p> | ||
<p align="center">This is a silly little command line tool for sexy fonts in the console. <strong>Give your cli some love.</strong></p> | ||
@@ -49,10 +42,10 @@ ## Installing | ||
CFonts.say('Hello|world!', { | ||
font: 'block', //define the font face | ||
align: 'left', //define text alignment | ||
colors: ['system'], //define all colors | ||
background: 'transparent', //define the background color, you can also use `backgroundColor` here as key | ||
letterSpacing: 1, //define letter spacing | ||
lineHeight: 1, //define the line height | ||
space: true, //define if the output text should have empty lines on top and on the bottom | ||
maxLength: '0', //define how many character can be on one line | ||
font: 'block', // define the font face | ||
align: 'left', // define text alignment | ||
colors: ['system'], // define all colors | ||
background: 'transparent', // define the background color, you can also use `backgroundColor` here as key | ||
letterSpacing: 1, // define letter spacing | ||
lineHeight: 1, // define the line height | ||
space: true, // define if the output text should have empty lines on top and on the bottom | ||
maxLength: '0', // define how many character can be on one line | ||
}); | ||
@@ -70,6 +63,6 @@ ``` | ||
prettyFont.string //the ansi string for sexy console font | ||
prettyFont.array //returns the array for the output | ||
prettyFont.lines //returns the lines used | ||
prettyFont.options //returns the options used | ||
prettyFont.string // the ansi string for sexy console font | ||
prettyFont.array // returns the array for the output | ||
prettyFont.lines // returns the lines used | ||
prettyFont.options // returns the options used | ||
``` | ||
@@ -96,58 +89,20 @@ | ||
- `A` | ||
- `B` | ||
- `C` | ||
- `D` | ||
- `E` | ||
- `F` | ||
- `G` | ||
- `H` | ||
- `I` | ||
- `J` | ||
- `K` | ||
- `L` | ||
- `M` | ||
- `N` | ||
- `O` | ||
- `P` | ||
- `Q` | ||
- `R` | ||
- `S` | ||
- `T` | ||
- `U` | ||
- `V` | ||
- `W` | ||
- `X` | ||
- `Y` | ||
- `Z` | ||
- `0` | ||
- `1` | ||
- `2` | ||
- `3` | ||
- `4` | ||
- `5` | ||
- `6` | ||
- `7` | ||
- `8` | ||
- `9` | ||
- `!` | ||
- `?` | ||
- `.` | ||
- `+` | ||
- `-` | ||
- `_` | ||
- `=` | ||
- `@` | ||
- `#` | ||
- `$` | ||
- `%` | ||
- `&` | ||
- `(` | ||
- `)` | ||
- `/` | ||
- `:` | ||
- `;` | ||
- `,` | ||
- ` ` (space) | ||
| | | | | | | ||
|-----|-----|-----|-----|-------------| | ||
| `A` | `O` | `2` | `2` | `=` | | ||
| `B` | `P` | `3` | `3` | `@` | | ||
| `C` | `Q` | `4` | `4` | `#` | | ||
| `D` | `R` | `5` | `5` | `$` | | ||
| `E` | `S` | `6` | `6` | `%` | | ||
| `F` | `T` | `7` | `7` | `&` | | ||
| `G` | `U` | `8` | `8` | `(` | | ||
| `H` | `V` | `9` | `9` | `)` | | ||
| `I` | `W` | `!` | `!` | `/` | | ||
| `J` | `X` | `?` | `?` | `:` | | ||
| `K` | `Y` | `.` | `.` | `;` | | ||
| `L` | `Z` | `+` | `+` | `,` | | ||
| `M` | `0` | `-` | `-` | ` ` (space) | | ||
| `N` | `1` | `_` | `_` | | | ||
_The `|` character will be replaced with a line break_ | ||
@@ -356,3 +311,4 @@ | ||
## Test | ||
The package comes with a bunch of unit tests and a test suite for font files. | ||
The package comes with a bunch of [unit tests](https://github.com/dominikwilkowski/cfonts/tree/master/test/unit) and a | ||
[test suite](https://github.com/dominikwilkowski/cfonts/blob/master/test/fonttest.js) for font files. | ||
@@ -372,3 +328,3 @@ Run the unit tests via: | ||
This tool checks: | ||
- the existence | ||
- the existence of the font | ||
- all attributes of a font | ||
@@ -388,3 +344,4 @@ - each character for: | ||
## Release History | ||
* 2.0.1 - Foxed terminal width detection | ||
* 2.1.0 - Rebuilt cfonts with pure functions, made colors case-insensitive | ||
* 2.0.1 - Fixed terminal width detection | ||
* 2.0.0 - Added tests, split into more pure functions | ||
@@ -391,0 +348,0 @@ * 1.2.0 - Added `transparent` and `system` as default background and color option, added `backgroundColor` as alias for `background`, upgraded deps |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
173919
5
4496
1
366
- Removedcommander@^2.15.1
- Removedcommander@2.20.3(transitive)
Updatedchalk@^2.4.1