cfonts-node 2.10.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of cfonts-node might be problematic. Click here for more details.

Files changed (46) hide show
  1. package/LICENSE +339 -0
  2. package/README.md +484 -0
  3. package/fonts/3d.json +658 -0
  4. package/fonts/block.json +481 -0
  5. package/fonts/chrome.json +304 -0
  6. package/fonts/grid.json +481 -0
  7. package/fonts/huge.json +776 -0
  8. package/fonts/pallet.json +481 -0
  9. package/fonts/shade.json +599 -0
  10. package/fonts/simple.json +363 -0
  11. package/fonts/simple3d.json +540 -0
  12. package/fonts/simpleBlock.json +540 -0
  13. package/fonts/slick.json +481 -0
  14. package/fonts/tiny.json +245 -0
  15. package/package.json +117 -0
  16. package/src/AddChar.js +51 -0
  17. package/src/AddLetterSpacing.js +59 -0
  18. package/src/AddLine.js +58 -0
  19. package/src/AddShortcuts.js +40 -0
  20. package/src/AlignText.js +68 -0
  21. package/src/Chalk.js +40 -0
  22. package/src/CharLength.js +55 -0
  23. package/src/CheckInput.js +192 -0
  24. package/src/CleanInput.js +47 -0
  25. package/src/Color.js +118 -0
  26. package/src/Colorize.js +84 -0
  27. package/src/Config.js +1 -0
  28. package/src/Debugging.js +108 -0
  29. package/src/DisplayHelp.js +50 -0
  30. package/src/DisplayVersion.js +31 -0
  31. package/src/GetFirstCharacterPosition.js +38 -0
  32. package/src/GetFont.js +49 -0
  33. package/src/GetLongestLine.js +31 -0
  34. package/src/Gradient.js +549 -0
  35. package/src/Log.js +42 -0
  36. package/src/Options.js +162 -0
  37. package/src/ParseArgs.js +82 -0
  38. package/src/RemoveChar.js +0 -0
  39. package/src/Render.js +257 -0
  40. package/src/RenderConsole.js +102 -0
  41. package/src/Say.js +50 -0
  42. package/src/Size.js +42 -0
  43. package/src/UpperCaseFirst.js +35 -0
  44. package/src/bin.js +16 -0
  45. package/src/constants.js +255 -0
  46. package/src/index.js +98 -0
@@ -0,0 +1,31 @@
1
+ /***************************************************************************************************************************************************************
2
+ *
3
+ * cfonts
4
+ *
5
+ * Sexy fonts for the console. (CLI output)
6
+ *
7
+ * @license https://github.com/dominikwilkowski/cfonts/blob/released/LICENSE GNU GPLv2
8
+ * @author Dominik Wilkowski hi@dominik-wilkowski.com
9
+ * @repository https://github.com/dominikwilkowski/cfonts
10
+ *
11
+ * DisplayVersion
12
+ * Display the version of this package
13
+ *
14
+ **************************************************************************************************************************************************************/
15
+
16
+ 'use strict';
17
+
18
+ const { PACKAGE } = require('./constants.js');
19
+
20
+
21
+ /**
22
+ * Display the version of this package
23
+ */
24
+ const DisplayVersion = () => {
25
+ console.log( PACKAGE.version );
26
+ };
27
+
28
+
29
+ module.exports = exports = {
30
+ DisplayVersion,
31
+ };
@@ -0,0 +1,38 @@
1
+ /***************************************************************************************************************************************************************
2
+ *
3
+ * cfonts
4
+ *
5
+ * Sexy fonts for the console. (CLI output)
6
+ *
7
+ * @license https://github.com/dominikwilkowski/cfonts/blob/released/LICENSE GNU GPLv2
8
+ * @author Dominik Wilkowski hi@dominik-wilkowski.com
9
+ * @repository https://github.com/dominikwilkowski/cfonts
10
+ *
11
+ * GetFirstCharacterPosition
12
+ * Get the position of the first character out of all strings inside an array
13
+ *
14
+ **************************************************************************************************************************************************************/
15
+
16
+ 'use strict';
17
+
18
+
19
+ /**
20
+ * Get the position of the first character out of all strings inside an array
21
+ *
22
+ * @param {array} lines - An array of strings
23
+ *
24
+ * @return {number} - The position of the first character
25
+ */
26
+ function GetFirstCharacterPosition( lines ) {
27
+ const earliest = lines.reduce(
28
+ ( prevLine, line ) => ( ( line.length - line.trimStart().length ) < ( prevLine.length - prevLine.trimStart().length ) && line !== '' ? line : prevLine )
29
+ , lines[ 0 ]
30
+ );
31
+
32
+ return ( earliest.length - earliest.trimStart().length );
33
+ }
34
+
35
+
36
+ module.exports = exports = {
37
+ GetFirstCharacterPosition,
38
+ };
package/src/GetFont.js ADDED
@@ -0,0 +1,49 @@
1
+ /***************************************************************************************************************************************************************
2
+ *
3
+ * cfonts
4
+ *
5
+ * Sexy fonts for the console. (CLI output)
6
+ *
7
+ * @license https://github.com/dominikwilkowski/cfonts/blob/released/LICENSE GNU GPLv2
8
+ * @author Dominik Wilkowski hi@dominik-wilkowski.com
9
+ * @repository https://github.com/dominikwilkowski/cfonts
10
+ *
11
+ * GetFont
12
+ * Get a selected JSON font-file object
13
+ *
14
+ **************************************************************************************************************************************************************/
15
+
16
+ 'use strict';
17
+
18
+ const { Debugging } = require('./Debugging.js');
19
+
20
+
21
+ /**
22
+ * Get a selected JSON font-file object
23
+ *
24
+ * @param {string} font - The name of the font to be returned
25
+ *
26
+ * @return {object} - The font object of that file
27
+ */
28
+ const GetFont = ( font ) => {
29
+ Debugging.report( `Running GetFont`, 1 );
30
+
31
+ // try loading the font file
32
+ try {
33
+ let FONTFACE = require(`../fonts/${ font }.json`); // read font file
34
+
35
+ Debugging.report( `GetFont: Fontface path selected: "${ font }.json"`, 2 );
36
+
37
+ return FONTFACE;
38
+ }
39
+ catch( error ) {
40
+ Debugging.error( `Font file for "${ font }" errored out: ${ error }`, 2 );
41
+
42
+ return false;
43
+ }
44
+ };
45
+
46
+
47
+ module.exports = exports = {
48
+ GetFont,
49
+ };
@@ -0,0 +1,31 @@
1
+ /***************************************************************************************************************************************************************
2
+ *
3
+ * cfonts
4
+ *
5
+ * Sexy fonts for the console. (CLI output)
6
+ *
7
+ * @license https://github.com/dominikwilkowski/cfonts/blob/released/LICENSE GNU GPLv2
8
+ * @author Dominik Wilkowski hi@dominik-wilkowski.com
9
+ * @repository https://github.com/dominikwilkowski/cfonts
10
+ *
11
+ * GetLongestLine
12
+ * Return the longest line of an Array
13
+ *
14
+ **************************************************************************************************************************************************************/
15
+
16
+ 'use strict';
17
+
18
+
19
+ /**
20
+ * Return the longest line of an Array
21
+ *
22
+ * @param {array} lines - An array of strings
23
+ *
24
+ * @return {string} - The longest string from within the array
25
+ */
26
+ const GetLongestLine = lines => lines.reduce( ( longestLine, line ) => ( line.length > longestLine.length && line.length !== 0 ? line : longestLine ), '' );
27
+
28
+
29
+ module.exports = exports = {
30
+ GetLongestLine,
31
+ };
@@ -0,0 +1,549 @@
1
+ /***************************************************************************************************************************************************************
2
+ *
3
+ * cfonts
4
+ *
5
+ * Sexy fonts for the console. (CLI output)
6
+ *
7
+ * @license https://github.com/dominikwilkowski/cfonts/blob/released/LICENSE GNU GPLv2
8
+ * @author Dominik Wilkowski hi@dominik-wilkowski.com
9
+ * @repository https://github.com/dominikwilkowski/cfonts
10
+ *
11
+ * Rgb2hsv - Converts an RGB color value to HSV
12
+ * Hsv2rgb - Converts an HSV color value to RGB
13
+ * Rgb2hex - Converts RGB to HEX
14
+ * Hex2rgb - Convert HEX to RGB
15
+ * Hsv2hsvRad - Convert HSV coordinate to HSVrad (degree to radian)
16
+ * HsvRad2hsv - Convert HSVrad color to HSV (radian to degree)
17
+ * Hex2hsvRad - Convert HEX to HSVrad
18
+ * HsvRad2hex - Convert HSVrad to HEX
19
+ * GetLinear - Interpolate a linear path from a number to another number
20
+ * GetTheta - Interpolate a radial path from a number to another number
21
+ * GetGradientColors - Generate the most colorful delta between two colors
22
+ * PaintLines - Take a bunch of lines and color them in the colors provided
23
+ * Color2hex - Make sure a color is hex
24
+ * GetGaps - Calculate the gaps between an array of points
25
+ * TransitionBetweenHex - Generate colors between two given colors
26
+ * Transition - Generate n colors between x colors
27
+ * PaintGradient - Paint finished output in a gradient
28
+ *
29
+ **************************************************************************************************************************************************************/
30
+
31
+ 'use strict';
32
+
33
+
34
+ const { GetFirstCharacterPosition } = require('./GetFirstCharacterPosition.js');
35
+ const { GetLongestLine } = require('./GetLongestLine.js');
36
+ const { GRADIENTS } = require('./constants.js');
37
+ const { Debugging } = require('./Debugging.js');
38
+ const { Color } = require('./Color.js');
39
+
40
+ /**
41
+ * Converts an RGB color value to HSV
42
+ *
43
+ * @author https://github.com/Gavin-YYC/colorconvert
44
+ *
45
+ * @param {object} options - Arguments
46
+ * @param {number} options.r - The red color value
47
+ * @param {number} options.g - The green color value
48
+ * @param {number} options.b - The blue color value
49
+ *
50
+ * @return {array} - The HSV representation
51
+ */
52
+ function Rgb2hsv({ r, g, b }) {
53
+ r /= 255;
54
+ g /= 255;
55
+ b /= 255;
56
+
57
+ const max = Math.max( r, g, b );
58
+ const min = Math.min( r, g, b );
59
+ const diff = max - min;
60
+
61
+ let h = 0;
62
+ let v = max;
63
+ let s = max === 0 ? 0 : diff / max;
64
+
65
+ // h
66
+ if( max === min ) {
67
+ h = 0;
68
+ }
69
+ else if( max === r && g >= b ) {
70
+ h = 60 * ( ( g - b ) / diff );
71
+ }
72
+ else if( max === r && g < b ) {
73
+ h = 60 * ( ( g - b ) / diff ) + 360;
74
+ }
75
+ else if( max === g ) {
76
+ h = 60 * ( ( b - r ) / diff ) + 120;
77
+ }
78
+ else { // if( max === b ) {
79
+ h = 60 * ( ( r - g ) / diff ) + 240;
80
+ }
81
+
82
+ return [ h, ( s * 100 ), ( v * 100 ) ];
83
+ }
84
+
85
+ /**
86
+ * Converts an HSV color value to RGB
87
+ *
88
+ * @author https://github.com/Gavin-YYC/colorconvert
89
+ *
90
+ * @param {number} h - The hue
91
+ * @param {number} s - The saturation
92
+ * @param {number} v - The value
93
+ *
94
+ * @typedef {object} ReturnObject
95
+ * @property {number} r - The red value
96
+ * @property {number} g - The green value
97
+ * @property {number} b - The blue value
98
+ *
99
+ * @return {ReturnObject} - The RGB representation
100
+ */
101
+ function Hsv2rgb( h, s, v ) {
102
+ h /= 60;
103
+ s /= 100;
104
+ v /= 100;
105
+ const hi = Math.floor( h ) % 6;
106
+
107
+ const f = h - Math.floor( h );
108
+ const p = 255 * v * ( 1 - s );
109
+ const q = 255 * v * ( 1 - ( s * f ) );
110
+ const t = 255 * v * ( 1 - ( s * ( 1 - f ) ) );
111
+ v *= 255;
112
+
113
+ switch( hi ) {
114
+ case 0:
115
+ return { r: v, g: t, b: p };
116
+ case 1:
117
+ return { r: q, g: v, b: p };
118
+ case 2:
119
+ return { r: p, g: v, b: t };
120
+ case 3:
121
+ return { r: p, g: q, b: v };
122
+ case 4:
123
+ return { r: t, g: p, b: v };
124
+ case 5:
125
+ return { r: v, g: p, b: q };
126
+ }
127
+ }
128
+
129
+ /**
130
+ * Converts RGB to HEX
131
+ *
132
+ * @param {number} r - The Red value
133
+ * @param {number} g - The Green value
134
+ * @param {number} b - The Blue value
135
+ *
136
+ * @return {string} - A HEX color
137
+ */
138
+ function Rgb2hex( r, g, b ) {
139
+ const val = ( ( b | g << 8 | r << 16) | 1 << 24 ).toString( 16 ).slice( 1 );
140
+ return '#' + val.toLowerCase();
141
+ }
142
+
143
+ /**
144
+ * Convert HEX to RGB
145
+ *
146
+ * @param {string} hex - The HEX color
147
+ *
148
+ * @return {array} - An object with RGB values
149
+ */
150
+ function Hex2rgb( hex ) {
151
+ hex = hex.replace(/^#/, '');
152
+
153
+ if( hex.length > 6 ) {
154
+ hex = hex.slice( 0, 6 );
155
+ }
156
+
157
+ if( hex.length === 4 ) {
158
+ hex = hex.slice( 0, 3 );
159
+ }
160
+
161
+ if( hex.length === 3 ) {
162
+ hex = hex[ 0 ] + hex[ 0 ] + hex[ 1 ] + hex[ 1 ] + hex[ 2 ] + hex[ 2 ];
163
+ }
164
+
165
+ const num = parseInt( hex, 16 );
166
+ const r = num >> 16;
167
+ const g = ( num >> 8 ) & 255;
168
+ const b = num & 255;
169
+ const rgb = [ r, g, b ];
170
+
171
+ return rgb;
172
+ }
173
+
174
+ /**
175
+ * Convert HSV coordinate to HSVrad (degree to radian)
176
+ *
177
+ * @param {array} argument - The HSV representation of a color
178
+ *
179
+ * @return {array} - The HSVrad color
180
+ */
181
+ function Hsv2hsvRad([ h, s, v ]) {
182
+ return [ ( h * Math.PI ) / 180, s, v ];
183
+ }
184
+
185
+ /**
186
+ * Convert HSVrad color to HSV (radian to degree)
187
+ *
188
+ * @param {number} hRad - H in rad
189
+ * @param {number} s - S
190
+ * @param {number} v - V
191
+ *
192
+ * @return {array} - The HSV color
193
+ */
194
+ function HsvRad2hsv( hRad, s, v ) {
195
+ return [ ( hRad * 180 ) / Math.PI, s, v ];
196
+ }
197
+
198
+ /**
199
+ * Convert HEX to HSVrad
200
+ *
201
+ * @param {string} hex - A HEX color
202
+ *
203
+ * @return {array} - The HSVrad color
204
+ */
205
+ function Hex2hsvRad( hex ) {
206
+ const [ r, g, b, ] = Hex2rgb( hex );
207
+ const hsv = Rgb2hsv({ r, g, b, });
208
+ const hsvRad = Hsv2hsvRad( hsv );
209
+
210
+ return hsvRad;
211
+ }
212
+
213
+ /**
214
+ * Convert HSVrad to HEX
215
+ *
216
+ * @param {number} hRad - The hue in rad
217
+ * @param {number} s - The saturation
218
+ * @param {number} v - The value
219
+ *
220
+ * @return {string} - The HEX color
221
+ */
222
+ function HsvRad2hex( hRad, s, v ) {
223
+ const [ h ] = HsvRad2hsv( hRad, s, v );
224
+ const { r, g, b } = Hsv2rgb( h, s, v );
225
+ const hex = Rgb2hex( r, g, b );
226
+
227
+ return hex;
228
+ }
229
+
230
+ /**
231
+ * Interpolate a linear path from a number to another number
232
+ *
233
+ * @param {number} pointA - The number from which to start
234
+ * @param {number} pointB - The number to go to
235
+ * @param {number} n - The current step
236
+ * @param {number} steps - The amount of steps
237
+ *
238
+ * @return {number} - The number at step n
239
+ */
240
+ function GetLinear( pointA, pointB, n, steps ) {
241
+ if( steps === 0 ) {
242
+ return pointB;
243
+ }
244
+
245
+ return pointA + n * ( ( pointB - pointA ) / steps );
246
+ }
247
+
248
+ /**
249
+ * Interpolate a radial path from a number to another number
250
+ *
251
+ * @param {number} fromTheta - The radian from which to start
252
+ * @param {number} toTheta - The radian to go to
253
+ * @param {number} n - The current step
254
+ * @param {number} steps - The amount of steps
255
+ *
256
+ * @return {number} - The radian at step n
257
+ */
258
+ function GetTheta( fromTheta, toTheta, n, steps ) {
259
+ const TAU = 2 * Math.PI;
260
+ let longDistance;
261
+
262
+ if( steps === 0 ) {
263
+ return toTheta;
264
+ }
265
+
266
+ if( fromTheta > toTheta ) {
267
+ if( fromTheta - toTheta < Math.PI ) {
268
+ longDistance = TAU - ( fromTheta - toTheta );
269
+ }
270
+ else {
271
+ longDistance = toTheta - fromTheta;
272
+ }
273
+ }
274
+ else {
275
+ if( toTheta - fromTheta < Math.PI ) {
276
+ longDistance = ( toTheta - fromTheta ) - TAU;
277
+ }
278
+ else {
279
+ longDistance = -1 * ( fromTheta - toTheta );
280
+ }
281
+ }
282
+
283
+ let result = fromTheta + ( n * ( longDistance / steps ) );
284
+
285
+ if( result < 0 ) {
286
+ result += TAU;
287
+ }
288
+
289
+ if( result > TAU ) {
290
+ result -= TAU;
291
+ }
292
+
293
+ return result;
294
+ }
295
+
296
+ /**
297
+ * Generate the most colorful delta between two colors
298
+ *
299
+ * @param {string} fromColor - The color from which to start
300
+ * @param {string} toColor - The color to go to
301
+ * @param {number} steps - The amount of colors of the gradient
302
+ *
303
+ * @return {array} - An array of colors
304
+ */
305
+ function GetGradientColors( fromColor, toColor, steps ) {
306
+ const [ fromHRad, fromS, fromV ] = Hex2hsvRad( fromColor );
307
+ const [ toHRad, toS, toV ] = Hex2hsvRad( toColor );
308
+
309
+ const hexColors = [];
310
+
311
+ for( let n = 0; n < steps; n++ ) {
312
+ const hRad = GetTheta( fromHRad, toHRad, n, ( steps - 1 ) );
313
+ const s = GetLinear( fromS, toS, n, ( steps - 1 ) );
314
+ const v = GetLinear( fromV, toV, n, ( steps - 1 ) );
315
+
316
+ hexColors.push( HsvRad2hex( hRad, s, v ) );
317
+ }
318
+
319
+ return hexColors;
320
+ }
321
+
322
+
323
+ /**
324
+ * Take a bunch of lines and color them in the colors provided
325
+ *
326
+ * @param {array} lines - The lines to be colored
327
+ * @param {array} colors - The colors in an array
328
+ * @param {number} firstCharacterPosition - We may have to cut something off from the start when text is aligned center, right
329
+ *
330
+ * @return {array} - The lines in color
331
+ */
332
+ function PaintLines( lines, colors, firstCharacterPosition ) {
333
+ Debugging.report(`Running PaintLines`, 1);
334
+
335
+ Debugging.report( colors, 2 );
336
+
337
+ const space = ' '.repeat( firstCharacterPosition );
338
+
339
+ return lines
340
+ .map( line => {
341
+ const coloredLine = line
342
+ .slice( firstCharacterPosition )
343
+ .split('')
344
+ .map( ( char, i ) => {
345
+ const { open, close } = Color( colors[ i ] );
346
+ return `${ open }${ char }${ close }`;
347
+ })
348
+ .join('');
349
+
350
+ return `${ space }${ coloredLine }`;
351
+ });
352
+ }
353
+
354
+
355
+ /**
356
+ * Make sure a color is hex
357
+ *
358
+ * @param {string} color - The color
359
+ *
360
+ * @return {string} - The hex color
361
+ */
362
+ function Color2hex( color ) {
363
+ const colorMap = {
364
+ black: '#000000',
365
+ red: '#ff0000',
366
+ green: '#00ff00',
367
+ yellow: '#ffff00',
368
+ blue: '#0000ff',
369
+ magenta: '#ff00ff',
370
+ cyan: '#00ffff',
371
+ white: '#ffffff',
372
+ gray: '#808080',
373
+ grey: '#808080',
374
+ };
375
+
376
+ return colorMap[ color ] || color;
377
+ }
378
+
379
+
380
+ /**
381
+ * Calculate the gaps between an array of points
382
+ *
383
+ * @param {array} points - An array of points, it's not important what's in the array for this function
384
+ * @param {number} steps - The amount of steps we have to distribute between the above points
385
+ *
386
+ * @return {array} - An array of steps per gap
387
+ */
388
+ function GetGaps( points, steps ) {
389
+ // steps per gap
390
+ const gapSteps = Math.floor( ( steps - points.length ) / ( points.length - 1 ) );
391
+ // steps left over to be distributed
392
+ const rest = steps - ( points.length + gapSteps * ( points.length - 1 ) );
393
+ // the gaps array has one less items than our points (cause it's gaps between each of the points)
394
+ const gaps = Array( points.length - 1 ).fill( gapSteps );
395
+
396
+ // let's fill in the rest from the right
397
+ for( let i = 0; i < rest; i++ ) {
398
+ gaps[ gaps.length - 1 - i ] ++;
399
+ }
400
+
401
+ return gaps;
402
+ }
403
+
404
+ /**
405
+ * Generate colors between two given colors
406
+ *
407
+ * @param {string} fromHex - The color we start from in hex
408
+ * @param {string} toHex - The color we end up at in hex
409
+ * @param {number} steps - How many colors should be returned
410
+ *
411
+ * @return {array} - An array for colors
412
+ */
413
+ function TransitionBetweenHex( fromHex, toHex, steps ) {
414
+ const fromRgb = Hex2rgb( fromHex );
415
+ const toRgb = Hex2rgb( toHex );
416
+ const hexColors = [];
417
+ steps ++;
418
+
419
+ for( let n = 1; n < steps; n++ ) {
420
+ const red = GetLinear( fromRgb[ 0 ], toRgb[ 0 ], n, steps );
421
+ const green = GetLinear( fromRgb[ 1 ], toRgb[ 1 ], n, steps );
422
+ const blue = GetLinear( fromRgb[ 2 ], toRgb[ 2 ], n, steps );
423
+
424
+ hexColors.push( Rgb2hex( red, green, blue ) );
425
+ }
426
+
427
+ return hexColors;
428
+ }
429
+
430
+ /**
431
+ * Generate n colors between x colors
432
+ *
433
+ * @param {array} colors - An array of colors in hex
434
+ * @param {number} steps - The amount of colors to generate
435
+ * @param {object} gradients - An object of pre-packaged gradient colors
436
+ *
437
+ * @return {array} - An array of colors
438
+ */
439
+ function Transition( colors, steps, gradients = GRADIENTS ) {
440
+ let hexColors = [];
441
+ if( colors.length === 1 ) {
442
+ colors = gradients[ colors[ 0 ].toLowerCase() ];
443
+ }
444
+ else {
445
+ colors = colors.map( color => Color2hex( color ) );
446
+ }
447
+ const gaps = GetGaps( colors, steps );
448
+
449
+ if( steps <= 1 ) {
450
+ return [ colors[ colors.length - 1 ] ];
451
+ }
452
+
453
+ for( let i = 0; i < colors.length; i++ ) {
454
+ const gap = gaps[ i - 1 ];
455
+
456
+ if( colors[ i - 1 ] ) {
457
+ const gapColors = TransitionBetweenHex( colors[ i - 1 ], colors[ i ], gap );
458
+ hexColors = [ ...hexColors, ...gapColors ];
459
+ }
460
+
461
+ if( gap !== -1 ) {
462
+ hexColors.push( colors[ i ] );
463
+ }
464
+ }
465
+
466
+ return hexColors;
467
+ }
468
+
469
+
470
+ /**
471
+ * Paint finished output in a gradient
472
+ *
473
+ * @param {object} options - Arguments
474
+ * @param {array} options.output - The output to be painted
475
+ * @param {array} options.gradient - An array of two colors for start and end of gradient
476
+ * @param {number} options.lines - How many lines the output contains
477
+ * @param {number} options.lineHeight - The line height between lines
478
+ * @param {number} options.fontLines - The line height (line breaks) of a single font line
479
+ * @param {boolean} options.independentGradient - A switch to calculate gradient per line or not
480
+ * @param {boolean} options.transitionGradient - A switch for transition gradients
481
+ *
482
+ * @return {array} - The output array painted in ANSI colors
483
+ */
484
+ function PaintGradient({ output, gradient, lines, lineHeight, fontLines, independentGradient, transitionGradient }) {
485
+ Debugging.report(`Running PaintGradient`, 1);
486
+ let newOutput = [];
487
+
488
+ if( transitionGradient ) {
489
+ Debugging.report(`Gradient transition with colors: ${ JSON.stringify( gradient ) }`, 2);
490
+ }
491
+ else {
492
+ Debugging.report(`Gradient start: ${ gradient[ 0 ] } | Gradient end: ${ gradient[ 1 ] }`, 2);
493
+ }
494
+
495
+ let firstCharacterPosition;
496
+ let longestLine;
497
+
498
+ if( !independentGradient ) {
499
+ firstCharacterPosition = GetFirstCharacterPosition( output );
500
+ longestLine = GetLongestLine( output ).length;
501
+ }
502
+
503
+ for( let i = 0; i < lines; i++ ) {
504
+ const start = ( i * ( fontLines + lineHeight ) );
505
+ const end = fontLines + start;
506
+ const thisLine = output.slice( start, end );
507
+
508
+ if( independentGradient ) {
509
+ firstCharacterPosition = GetFirstCharacterPosition( thisLine );
510
+ longestLine = GetLongestLine( thisLine ).length;
511
+ }
512
+
513
+ const colorsNeeded = longestLine - firstCharacterPosition;
514
+ const linesInbetween = i === 0
515
+ ? []
516
+ : Array( lineHeight ).fill('');
517
+
518
+ Debugging.report(`longestLine: ${ longestLine } | firstCharacterPosition: ${ firstCharacterPosition }`, 2);
519
+
520
+ const colors = transitionGradient
521
+ ? Transition( gradient, colorsNeeded )
522
+ : GetGradientColors( Color2hex( gradient[ 0 ] ), Color2hex( gradient[ 1 ] ), colorsNeeded );
523
+
524
+ newOutput = [ ...newOutput, ...linesInbetween, ...PaintLines( thisLine, colors, firstCharacterPosition ) ];
525
+ }
526
+
527
+ return newOutput;
528
+ }
529
+
530
+
531
+ module.exports = exports = {
532
+ Rgb2hsv,
533
+ Hsv2rgb,
534
+ Rgb2hex,
535
+ Hex2rgb,
536
+ Hsv2hsvRad,
537
+ HsvRad2hsv,
538
+ Hex2hsvRad,
539
+ HsvRad2hex,
540
+ GetLinear,
541
+ GetTheta,
542
+ GetGradientColors,
543
+ PaintLines,
544
+ Color2hex,
545
+ GetGaps,
546
+ TransitionBetweenHex,
547
+ Transition,
548
+ PaintGradient,
549
+ };