Comparing version 1.0.1 to 1.0.2
{ | ||
"name": "3D", | ||
"version": "0.0.2", | ||
"version": "0.0.3", | ||
"homepage": "https://github.com/dominikwilkowski/cfonts", | ||
@@ -613,2 +613,13 @@ "colors": 2, | ||
], | ||
",": [ | ||
"<c2>______</c2>", | ||
"<c2>______</c2>", | ||
"<c2>______</c2>", | ||
"<c2>______</c2>", | ||
"<c2>______</c2>", | ||
"<c2>_</c2><c1>/\\\\\\\\</c1>", | ||
"<c1>\\///\\\\</c1>", | ||
"<c2>_</c2><c1>/\\\\/</c1><c2>_</c2>", | ||
"<c1>\\//</c1><c2>___</c2>" | ||
], | ||
" ": [ | ||
@@ -615,0 +626,0 @@ "<c2>___</c2>", |
{ | ||
"name": "block", | ||
"version": "0.0.3", | ||
"version": "0.0.4", | ||
"homepage": "https://github.com/dominikwilkowski/cfonts", | ||
@@ -442,8 +442,16 @@ "colors": 2, | ||
" ", | ||
" ", | ||
"<c1>██</c1><c2>╗</c2>", | ||
"<c2>╚═╝</c2>", | ||
"<c1>▄█</c1><c2>╗</c2>", | ||
"<c1>▀</c1><c2>═╝</c2>", | ||
" " | ||
"<c1>▀</c1><c2>═╝</c2>" | ||
], | ||
",": [ | ||
" ", | ||
" ", | ||
" ", | ||
" ", | ||
"<c1>▄█</c1><c2>╗</c2>", | ||
"<c1>▀</c1><c2>═╝</c2>" | ||
], | ||
" ": [ | ||
@@ -450,0 +458,0 @@ " ", |
{ | ||
"name": "chrome", | ||
"version": "0.0.1", | ||
"version": "0.0.2", | ||
"homepage": "https://github.com/dominikwilkowski/cfonts", | ||
@@ -283,2 +283,7 @@ "colors": 3, | ||
], | ||
",": [ | ||
"<c1> </c1>", | ||
"<c1> </c1>", | ||
"<c3>╔</c3>" | ||
], | ||
" ": [ | ||
@@ -285,0 +290,0 @@ " ", |
{ | ||
"name": "simple", | ||
"version": "0.0.2", | ||
"version": "0.0.3", | ||
"homepage": "https://github.com/dominikwilkowski/cfonts", | ||
@@ -338,2 +338,8 @@ "colors": 1, | ||
], | ||
",": [ | ||
" ", | ||
" ", | ||
"( )", | ||
"|/ " | ||
], | ||
" ": [ | ||
@@ -340,0 +346,0 @@ " ", |
{ | ||
"name": "simple3d", | ||
"version": "0.0.2", | ||
"version": "0.0.3", | ||
"homepage": "https://github.com/dominikwilkowski/cfonts", | ||
@@ -503,2 +503,11 @@ "colors": 1, | ||
], | ||
",": [ | ||
" ", | ||
" ", | ||
" ", | ||
" _ ", | ||
" /\\ \\", | ||
" \\ \\/", | ||
" \\/ " | ||
], | ||
" ": [ | ||
@@ -505,0 +514,0 @@ " ", |
{ | ||
"name": "simpleBlock", | ||
"version": "0.0.2", | ||
"version": "0.0.3", | ||
"homepage": "https://github.com/dominikwilkowski/cfonts", | ||
@@ -496,8 +496,17 @@ "colors": 1, | ||
" ", | ||
" ", | ||
" ", | ||
" _|", | ||
" ", | ||
" _|", | ||
" _| " | ||
], | ||
",": [ | ||
" ", | ||
" ", | ||
" ", | ||
" ", | ||
" ", | ||
" _|", | ||
" _| ", | ||
" " | ||
" _| " | ||
], | ||
@@ -504,0 +513,0 @@ " ": [ |
148
index.js
@@ -39,9 +39,2 @@ /*************************************************************************************************************************************************************** | ||
//check selected font exists in preset | ||
if( CFonts.FONTFACES.indexOf( font ) === -1 ) { | ||
CFonts.log.error(`Please use a font from the supported stack:\n${Chalk.green(`[ ${CFonts.FONTFACES.join(' | ')} ]`)}`); | ||
process.exit(1); //exit program with failure code | ||
} | ||
//try loading the font file | ||
@@ -196,12 +189,30 @@ try { | ||
if( CFonts.FONTFACE.colors > 1 && character !== undefined ) { | ||
for(let i = 0; i < CFonts.FONTFACE.colors; i++) { //convert all colors | ||
let open = new RegExp(`<c${(i + 1)}>`, 'g'); | ||
let close = new RegExp(`</c${(i + 1)}>`, 'g'); | ||
let candyColors = ['red','green','yellow','magenta','cyan' ]; //allowed candy colors | ||
let color = CFonts.OPTIONS.colors[ i ] || 'white'; | ||
if( character !== undefined ) { | ||
if( CFonts.FONTFACE.colors > 1 ) { | ||
for(let i = 0; i < CFonts.FONTFACE.colors; i++) { //convert all colors | ||
let open = new RegExp(`<c${(i + 1)}>`, 'g'); | ||
let close = new RegExp(`</c${(i + 1)}>`, 'g'); | ||
character = character.replace( open, Chalk.styles[ color.toLowerCase() ].open ); | ||
character = character.replace( close, Chalk.styles[ color.toLowerCase() ].close ); | ||
let color = CFonts.OPTIONS.colors[ i ] || 'white'; | ||
if( color === 'candy' ) { | ||
color = candyColors[ Math.floor( Math.random() * candyColors.length ) ]; | ||
} | ||
character = character.replace( open, Chalk.styles[ color.toLowerCase() ].open ); | ||
character = character.replace( close, Chalk.styles[ color.toLowerCase() ].close ); | ||
} | ||
} | ||
if( CFonts.FONTFACE.colors === 1 ) { | ||
let color = CFonts.OPTIONS.colors[ 0 ] || 'white'; | ||
if( color === 'candy' ) { | ||
color = candyColors[ Math.floor( Math.random() * candyColors.length ) ]; | ||
} | ||
character = Chalk.styles[ color.toLowerCase() ].open + character + Chalk.styles[ color.toLowerCase() ].close; | ||
} | ||
} | ||
@@ -258,3 +269,3 @@ | ||
//-------------------------------------------------------------------------------------------------------------------------------------------------------------- | ||
DEBUG: false, //Debug setting | ||
DEBUG: false, //Debug setting | ||
DEBUGLEVEL: 2, //Debug level setting | ||
@@ -295,2 +306,3 @@ COLORS: [ //All allowed font colors | ||
'chrome', | ||
'huge', | ||
], | ||
@@ -303,3 +315,3 @@ FONTFACE: {}, //Font face object to be filled with selected fontface | ||
// Public function | ||
// say, main method to write out your string | ||
// render, main method to get the ANSI output for a string | ||
// | ||
@@ -317,8 +329,12 @@ // @param INPUT {string} The string you want to write out | ||
// | ||
// @return {string} CLI output of INPUT | ||
// @return {string} CLI output of INPUT to be consoled out | ||
//-------------------------------------------------------------------------------------------------------------------------------------------------------------- | ||
say: ( INPUT = '', SETTINGS = {} ) => { | ||
CFonts.debugging.report(`Running say`, 1); | ||
render: ( INPUT = '', SETTINGS = {} ) => { | ||
CFonts.debugging.report(`Running render`, 1); | ||
let write = ''; //output to be build | ||
let write = ''; //output in a string | ||
let output = []; //output in an array | ||
let lines = 0; //count each line | ||
//SETTINGS | ||
CFonts.OPTIONS = { //SETTINGS and defaults | ||
@@ -335,2 +351,3 @@ font: SETTINGS.font || 'block', | ||
//CHECKING INPUT | ||
if( INPUT === undefined || INPUT === '' ) { | ||
@@ -342,7 +359,21 @@ CFonts.log.error(`Please provide text to convert`); | ||
//CHECKING FONT | ||
if( CFonts.FONTFACES.indexOf( CFonts.OPTIONS.font ) === -1 ) { | ||
CFonts.log.error( | ||
`"${Chalk.red( SETTINGS.font )}" is not a valid font option.\n` + | ||
`Please use a font from the supported stack:\n${Chalk.green(`[ ${CFonts.FONTFACES.join(' | ')} ]`)}` | ||
); | ||
process.exit(1); //exit program with failure code | ||
} | ||
//CHECKING COLORS | ||
for( let color in CFonts.OPTIONS.colors ) { //check color usage | ||
if( CFonts.COLORS.indexOf( CFonts.OPTIONS.colors[ color ] ) === -1 ) { | ||
if( | ||
CFonts.COLORS.indexOf( CFonts.OPTIONS.colors[ color ] ) === -1 && | ||
CFonts.OPTIONS.colors[ color ] !== 'candy' | ||
) { | ||
CFonts.log.error( | ||
`"${Chalk.red( CFonts.OPTIONS.colors[ color ] )}" is not a valid font color option.\n` + | ||
`Please use a color from the supported stack:\n${Chalk.green(`[ ${CFonts.COLORS.join(' | ')} ]`)}` | ||
`Please use a color from the supported stack:\n${Chalk.green(`[ ${CFonts.COLORS.join(' | ')} | candy ]`)}` | ||
); | ||
@@ -354,2 +385,3 @@ | ||
//CHECKING BACKGROUND COLORS | ||
if( CFonts.BGCOLORS.indexOf( CFonts.OPTIONS.background.toLowerCase() ) === -1 ) { | ||
@@ -364,2 +396,3 @@ CFonts.log.error( | ||
//CHECKING ALIGNMENT | ||
if( CFonts.ALIGNMENT.indexOf( CFonts.OPTIONS.align ) === -1 ) { | ||
@@ -375,4 +408,4 @@ CFonts.log.error( | ||
//log OPTIONS for debugging | ||
if( CFonts.DEBUG ) { | ||
//DEBUG | ||
if( CFonts.DEBUG ) { //log options | ||
let outOption = `OPTIONS:\n Text: ${INPUT}`; | ||
@@ -389,19 +422,25 @@ | ||
if( CFonts.OPTIONS.font === 'console' ) { //console fontface is pretty easy to process | ||
let color = CFonts.OPTIONS.colors[0].toLowerCase() || 'white'; //font color | ||
let lines = INPUT.split('|'); //each line | ||
let output = [] | ||
let outputLines = INPUT.replace('\\', '').split('|'); //remove escape characters and split into each line | ||
CFonts.FONTFACE.colors = 1; //console defaults | ||
CFonts.FONTFACE.lines = 1; | ||
for(let line in lines) { | ||
let length = lines[ line ].length; | ||
for(let line in outputLines) { //each line needs to be pushed into the output array | ||
lines += Math.ceil( outputLines[ line ].length / WinSize.width ); //count each line even when they overflow | ||
lines[ line ] = Chalk[ color ]( lines[ line ] ); | ||
output.push( lines[ line ] ); | ||
if( CFonts.OPTIONS.colors[0] === "candy" ) { //if the color is candy | ||
let character = ''; | ||
output = AlignText( output, length ); //calculate alignment based on lineLength | ||
} | ||
for(let i = 0; i < outputLines[ line ].length; i++) { //iterate through the message | ||
character += Colorize( outputLines[ line ][ i ] ); //and colorize each character individually | ||
} | ||
output.push( character ); //push each line to the output array | ||
} | ||
else { | ||
output.push( Colorize( outputLines[ line ] ) ); //colorize line | ||
} | ||
write = output.join(`\n`); //convert to one line | ||
output = AlignText( output, outputLines[ line ].length ); //calculate alignment based on lineLength | ||
} | ||
} | ||
@@ -429,6 +468,8 @@ else { //all other fontfaces need the font-file and some more work | ||
let output = AddLine( [] ); //create first lines with buffer | ||
let lineLength = CharLength( CFonts.FONTFACE.buffer ); //count each output character per line and start with the buffer | ||
let maxChars = 0; //count each character we print for maxLength option | ||
output = AddLine( [] ); //create first lines with buffer | ||
lines ++; | ||
output = AddLetterSpacing( output ); //add letter spacing to the beginning | ||
@@ -456,2 +497,4 @@ lineLength += CharLength( CFonts.FONTFACE.letterspace ) * CFonts.OPTIONS.letterSpacing; //count the space for the letter spacing | ||
if(maxChars >= CFonts.OPTIONS.maxLength && CFonts.OPTIONS.maxLength != 0 || CHAR === `|` || lineLength > WinSize.width) { | ||
lines ++; | ||
CFonts.debugging.report( | ||
@@ -490,11 +533,9 @@ `NEWLINE: maxChars: ${maxChars}, ` + | ||
output = AlignText( output, lineLength ); //alignment last line | ||
write = output.join(`\n`); //convert to one line | ||
} | ||
write = output.join(`\n`); //convert to a string | ||
if( CFonts.FONTFACE.colors <= 1 ) { //add text color if only one | ||
let color = CFonts.OPTIONS.colors[0] || `white`; | ||
write = Chalk[ color.toLowerCase() ]( write ); | ||
write = Colorize( write ); | ||
} | ||
@@ -506,5 +547,15 @@ | ||
} | ||
else { | ||
write = `\n` + write; | ||
} | ||
write = Chalk[ 'bg' + CFonts.OPTIONS.background ]( write ) //result in one string | ||
console.log( Chalk[ 'bg' + CFonts.OPTIONS.background ]( write ) ); //write out | ||
return { | ||
string: write, | ||
array: output, | ||
lines: lines, | ||
options: CFonts.OPTIONS, | ||
} | ||
}, | ||
@@ -514,2 +565,17 @@ | ||
//-------------------------------------------------------------------------------------------------------------------------------------------------------------- | ||
// Public function | ||
// say, print to console | ||
// | ||
// @param same as render method | ||
//-------------------------------------------------------------------------------------------------------------------------------------------------------------- | ||
say: ( INPUT = '', SETTINGS = {} ) => { | ||
CFonts.debugging.report(`Running say`, 1); | ||
let write = CFonts.render( INPUT, SETTINGS ); | ||
console.log( write.string ); //write out | ||
}, | ||
//-------------------------------------------------------------------------------------------------------------------------------------------------------------- | ||
// Debugging prettiness | ||
@@ -516,0 +582,0 @@ // |
{ | ||
"name": "cfonts", | ||
"description": "Sexy fonts for the console", | ||
"version": "1.0.1", | ||
"version": "1.0.2", | ||
"homepage": "https://github.com/dominikwilkowski/cfonts", | ||
@@ -6,0 +6,0 @@ "author": { |
@@ -45,13 +45,13 @@ ```shell | ||
```js | ||
var CFonts = require('cfonts'); | ||
const CFonts = require('cfonts'); | ||
CFonts.say('Hello|world!', { | ||
'font': 'block', //define the font face | ||
'align': 'left', //define text alignment | ||
'colors': ['white'], //define all colors | ||
'background': 'Black', //define the background color | ||
'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: ['white'], //define all colors | ||
background: 'Black', //define the background color | ||
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 | ||
}); | ||
@@ -62,3 +62,16 @@ ``` | ||
You can use CFonts in your project without the direct output to the console: | ||
```js | ||
const CFonts = require('cfonts'); | ||
const prettyFont = CFonts.render('Hello|world!', {/* same settings object as above */}); | ||
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 | ||
``` | ||
## Usage | ||
@@ -135,2 +148,3 @@ | ||
- ; | ||
- , | ||
- ` ` (space) | ||
@@ -189,2 +203,3 @@ | ||
- `chrome` [colors: 3] | ||
- `huge` [colors: 2] | ||
@@ -227,2 +242,3 @@ ```shell | ||
- `gray` | ||
- `candy` | ||
@@ -320,9 +336,10 @@ ```shell | ||
## Release History | ||
* 1.0.1 - added chrome font, fonttest | ||
* 1.0.0 - refactor, added alignment and line height option, new cli commands, added simpleBlock | ||
* 0.0.13 - fixed simple3d | ||
* 0.0.12 - fixed simple3d and added to grunt test | ||
* 0.0.11 - added simple3d font | ||
* 1.0.2 - fixed background in `console` font, added comma, added font `huge`, added render method, added candy color | ||
* 1.0.1 - added `chrome` font, fonttest | ||
* 1.0.0 - refactor, added alignment and line height option, new cli commands, added `simpleBlock` | ||
* 0.0.13 - fixed `simple3d` | ||
* 0.0.12 - fixed `simple3d` and added to grunt test | ||
* 0.0.11 - added `simple3d` font | ||
* 0.0.10 - added npmignore, added to docs | ||
* 0.0.9 - added console font | ||
* 0.0.9 - added `console` font | ||
* 0.0.8 - fixed bugs, docs | ||
@@ -329,0 +346,0 @@ * 0.0.7 - changed to settings object |
/*************************************************************************************************************************************************************** | ||
* | ||
* cfonts | ||
* cfonts, Sexy fonts for the console. (CLI output) | ||
* | ||
* Sexy fonts for the console. (CLI output) | ||
* Testing the each font file: | ||
* - Font file has all font attributes? | ||
* - All characters included? | ||
* - All characters have the correct width? | ||
* - All characters have consistent lines? | ||
* | ||
@@ -40,3 +44,3 @@ * @license https://github.com/dominikwilkowski/cfonts/blob/master/LICENSE GNU GPLv2 | ||
"0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "!", | ||
"?", ".", "+", "-", "_", "=", "@", "#", "$", "%", "&", "(", ")", "/", ":", ";", " " | ||
"?", ".", "+", "-", "_", "=", "@", "#", "$", "%", "&", "(", ")", "/", ":", ";", ",", " " | ||
], | ||
@@ -50,2 +54,3 @@ FONTFACES: [ //All allowed fonts | ||
'chrome', | ||
'huge', | ||
], | ||
@@ -52,0 +57,0 @@ |
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
183241
17
4566
350