From f7b5be9c17c7503e5e32839feca2b10b8e9c2166 Mon Sep 17 00:00:00 2001 From: FriedlandAaron <3793162+FriedlandAaron@users.noreply.github.com> Date: Tue, 4 Jun 2024 13:55:57 +0300 Subject: [PATCH 01/12] implement rust api raw mode flag --- rust/src/args.rs | 3 +++ rust/src/config.rs | 14 +++++++++++++- rust/src/render.rs | 12 ++++++++++++ 3 files changed, 28 insertions(+), 1 deletion(-) diff --git a/rust/src/args.rs b/rust/src/args.rs index 39a08a7..1bb8519 100644 --- a/rust/src/args.rs +++ b/rust/src/args.rs @@ -503,6 +503,9 @@ pub fn parse(args: Vec) -> Result { "debug" => { options.debug = true; } + "raw_mode" => { + options.raw_mode = true; + } _ => {} }, OptionType::Env => { diff --git a/rust/src/config.rs b/rust/src/config.rs index c6b1fa9..0095a91 100644 --- a/rust/src/config.rs +++ b/rust/src/config.rs @@ -278,6 +278,8 @@ pub struct Options { pub debug: bool, /// The depth of the debug infos pub debug_level: u16, + /// To render string newlines properly in 'raw mode' in terminals + pub raw_mode: bool, } impl Default for Options { @@ -301,6 +303,7 @@ impl Default for Options { version: false, debug: false, debug_level: 1, + raw_mode: false, } } } @@ -350,7 +353,7 @@ pub struct CliOption<'a> { /// The `CLIOPTIONS` define each of the flags our cli app respects. /// /// It's also used to generate the help -pub const CLIOPTIONS: [CliOption; 16] = [ +pub const CLIOPTIONS: [CliOption; 17] = [ CliOption { key: "version", name: "--version", @@ -495,4 +498,13 @@ pub const CLIOPTIONS: [CliOption; 16] = [ example: "--debug-level 2", kind: OptionType::Number, }, + CliOption { + key: "raw_mode", + name: "--raw-mode", + shortcut: "-r", + fallback_shortcut: "", + description: "Use to enable proper newline rendering for 'raw mode' in terminals", + example: "--raw-mode", + kind: OptionType::Bool, + }, ]; diff --git a/rust/src/render.rs b/rust/src/render.rs index 94e566f..cfbb601 100644 --- a/rust/src/render.rs +++ b/rust/src/render.rs @@ -215,6 +215,18 @@ pub fn render(options: Options) -> RenderedString { d("render() formatted for Env::Browser", 1, Dt::Log, &options, &mut std::io::stdout()); } + // Handle raw mode only in Cli env + if options.env == Env::Cli { + if options.raw_mode { + for v in output.iter_mut() { + *v = v.replace('\n', "\r\n"); + } + text = text.replace('\n', "\r\n"); + } + } + + d(&format!("render() final output string: {:?}", text), 1, Dt::Log, &options, &mut std::io::stdout()); + RenderedString { text, vec: output, From a21ce83546c8da552492a988a53e225073c6f288 Mon Sep 17 00:00:00 2001 From: FriedlandAaron <3793162+FriedlandAaron@users.noreply.github.com> Date: Tue, 4 Jun 2024 13:59:29 +0300 Subject: [PATCH 02/12] add doc tests for raw mode --- rust/src/args.rs | 5 ++++- rust/src/render.rs | 14 ++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/rust/src/args.rs b/rust/src/args.rs index 1bb8519..141ba42 100644 --- a/rust/src/args.rs +++ b/rust/src/args.rs @@ -36,6 +36,7 @@ use crate::debug::{d, Dt}; /// options.version = true; /// options.debug = true; /// options.debug_level = 3; +/// options.raw_mode = true; /// /// // All shortcut flags /// assert_eq!( @@ -68,6 +69,7 @@ use crate::debug::{d, Dt}; /// "-d".to_string(), /// "-x".to_string(), /// "3".to_string(), +/// "-r".to_string(), /// ]) /// .unwrap(), /// options @@ -90,7 +92,7 @@ use crate::debug::{d, Dt}; /// "9".to_string(), /// "-z".to_string(), /// "2".to_string(), -/// "-sithvd".to_string(), // <-- stacked boolean flags +/// "-sithvdr".to_string(), // <-- stacked boolean flags /// "-m".to_string(), /// "100".to_string(), /// "-g".to_string(), @@ -130,6 +132,7 @@ use crate::debug::{d, Dt}; /// "browser".to_string(), /// "--debug-level".to_string(), /// "3".to_string(), +/// "--raw-mode".to_string(), /// ]) /// .unwrap(), /// options diff --git a/rust/src/render.rs b/rust/src/render.rs index cfbb601..ba2be66 100644 --- a/rust/src/render.rs +++ b/rust/src/render.rs @@ -50,6 +50,20 @@ pub struct RenderedString { /// " █▀█ ██▄ █▄▄ █▄▄ █▄█\n\n" /// ) /// ); +/// let output = render(Options { +/// text: String::from("hello"), +/// font: Fonts::FontTiny, +/// raw_mode: true, +/// ..Options::default() +/// }); +/// assert_eq!( +/// output.text, +/// format!("{}{}{}", +/// "\r\n\r\n", +/// " █ █ █▀▀ █ █ █▀█\r\n", +/// " █▀█ ██▄ █▄▄ █▄▄ █▄█\r\n\r\n" +/// ) +/// ); /// } /// ``` /// From a9af5b3397dff9a0b4cfe6000a67740147df9c56 Mon Sep 17 00:00:00 2001 From: FriedlandAaron <3793162+FriedlandAaron@users.noreply.github.com> Date: Tue, 4 Jun 2024 14:08:40 +0300 Subject: [PATCH 03/12] update doc test to test all long-form flags --- rust/src/args.rs | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/rust/src/args.rs b/rust/src/args.rs index 141ba42..3762039 100644 --- a/rust/src/args.rs +++ b/rust/src/args.rs @@ -123,7 +123,13 @@ use crate::debug::{d, Dt}; /// "9".to_string(), /// "--line-height".to_string(), /// "2".to_string(), -/// "-sithvd".to_string(), +/// "--spaceless".to_string(), +/// "--independent-gradient".to_string(), +/// "--transition-gradient".to_string(), +/// "--help".to_string(), +/// "--version".to_string(), +/// "--debug".to_string(), +/// "--raw-mode".to_string(), /// "--max-length".to_string(), /// "100".to_string(), /// "--gradient".to_string(), @@ -132,7 +138,6 @@ use crate::debug::{d, Dt}; /// "browser".to_string(), /// "--debug-level".to_string(), /// "3".to_string(), -/// "--raw-mode".to_string(), /// ]) /// .unwrap(), /// options From 1ceee7c5396dd4bd157ea08c6129edba5834a1d2 Mon Sep 17 00:00:00 2001 From: FriedlandAaron <3793162+FriedlandAaron@users.noreply.github.com> Date: Sat, 8 Jun 2024 17:47:29 +0300 Subject: [PATCH 04/12] implement node api raw mode flag --- nodejs/src/Options.js | 5 +++++ nodejs/src/Render.js | 12 ++++++++++++ nodejs/src/constants.js | 7 +++++++ nodejs/src/index.js | 8 +++++--- 4 files changed, 29 insertions(+), 3 deletions(-) diff --git a/nodejs/src/Options.js b/nodejs/src/Options.js index 8ec2ecb..d81a81f 100644 --- a/nodejs/src/Options.js +++ b/nodejs/src/Options.js @@ -39,6 +39,7 @@ const Options = { independentGradient: false, transitionGradient: false, env: 'node', + rawMode: false, }; this.store = { ...defaults }; // cloning @@ -73,6 +74,7 @@ const Options = { * @param {object} options.allowedColors - All allowed font colors * @param {object} options.allowedBG - All allowed background colors * @param {object} options.allowedFont - All allowed fontfaces + * @param {boolean} options.rawMode - A switch for raw mode in terminals */ set set({ font = '', @@ -91,6 +93,7 @@ const Options = { allowedColors = COLORS, allowedBG = BGCOLORS, allowedFont = FONTFACES, + rawMode, }) { this.store.font = font !== '' ? allowedFont[font.toLowerCase()] || font : this.store.font; @@ -137,6 +140,8 @@ const Options = { transitionGradient !== undefined ? transitionGradient : this.store.transitionGradient; this.store.env = env !== undefined ? env : this.store.env; + + this.store.rawMode = rawMode !== undefined ? rawMode : this.store.rawMode; }, }; diff --git a/nodejs/src/Render.js b/nodejs/src/Render.js index 41b062e..8378cce 100644 --- a/nodejs/src/Render.js +++ b/nodejs/src/Render.js @@ -242,6 +242,18 @@ const Render = (input, SETTINGS = {}, debug = DEBUG.enabled, debuglevel = DEBUG. ``; } + // handle raw mode + if (OPTIONS.env === 'node') { + if (OPTIONS.rawMode === true) { + const re = /\n/g; + const newline = '\r\n'; + write = write.replace(re, newline); + output = output.map((x) => { + return x.replace(re, newline); + }); + } + } + return { string: write, array: output, diff --git a/nodejs/src/constants.js b/nodejs/src/constants.js index 9a891f5..10b8752 100644 --- a/nodejs/src/constants.js +++ b/nodejs/src/constants.js @@ -303,6 +303,13 @@ const CLIOPTIONS = { options: true, default: 1, }, + '--raw-mode': { + description: 'Use to render string newlines properly in raw mode in terminals', + example: '--raw-mode', + short: '-r', + fallback_shortcut: false, + default: false, + }, }; const PACKAGE = require('../package.json'); diff --git a/nodejs/src/index.js b/nodejs/src/index.js index b44b25e..f7fca5a 100644 --- a/nodejs/src/index.js +++ b/nodejs/src/index.js @@ -49,10 +49,11 @@ const Cli = (inputOptions = CLIOPTIONS, inputArgs = process.argv) => { ` independentGradient: ${args['independent-gradient']},\n` + ` transitionGradient: ${args['transition-gradient']},\n` + ` env: ${args.env},\n` + - ` }, ${args.debug}, ${args.debugLevel} );`, + ` rawMode: ${args['raw-mode']},\n` + + ` }, ${args.debug}, ${args['debug-level']} );`, 3, args.debug, - args.debugLevel + args['debug-level'] ); if (args.help) { @@ -89,9 +90,10 @@ const Cli = (inputOptions = CLIOPTIONS, inputArgs = process.argv) => { independentGradient: args['independent-gradient'], transitionGradient: args['transition-gradient'], env: args.env, + rawMode: args['raw-mode'], }, args.debug, - args.debugLevel + args['debug-level'] ); }; From 21acfda44d79499ff20d60fd1567eecf838c8ced Mon Sep 17 00:00:00 2001 From: FriedlandAaron <3793162+FriedlandAaron@users.noreply.github.com> Date: Sun, 9 Jun 2024 09:41:14 +0300 Subject: [PATCH 05/12] add and update tests for raw mode support --- nodejs/test/unit/Cli.spec.js | 1 + nodejs/test/unit/Options.spec.js | 40 ++++ nodejs/test/unit/ParseArgs.spec.js | 1 + nodejs/test/unit/Render.spec.js | 208 +++++++++++++++++ nodejs/test/unit/bin.spec.js | 364 +++++++++++++++++++++++++++++ rust/tests/args_test.rs | 20 +- rust/tests/end-to-end_test.rs | 215 +++++++++++++++++ 7 files changed, 846 insertions(+), 3 deletions(-) diff --git a/nodejs/test/unit/Cli.spec.js b/nodejs/test/unit/Cli.spec.js index 8ff45fa..b3c3dba 100644 --- a/nodejs/test/unit/Cli.spec.js +++ b/nodejs/test/unit/Cli.spec.js @@ -22,6 +22,7 @@ beforeEach(() => { gradient: false, independentGradient: false, transitionGradient: false, + rawMode: false, }; Options.set = DEFAULTS; diff --git a/nodejs/test/unit/Options.spec.js b/nodejs/test/unit/Options.spec.js index 016dd42..7ac893b 100644 --- a/nodejs/test/unit/Options.spec.js +++ b/nodejs/test/unit/Options.spec.js @@ -20,6 +20,7 @@ test(`Options - Should return default options`, () => { independentGradient: false, transitionGradient: false, env: 'node', + rawMode: false, }; Options.reset(); @@ -55,6 +56,7 @@ test(`Options - Should be able to handle casing`, () => { independentGradient: false, transitionGradient: false, env: 'node', + rawMode: false, }); }); @@ -84,6 +86,7 @@ test(`Options - Should be able to handle background and backgroundColor`, () => independentGradient: false, transitionGradient: false, env: 'node', + rawMode: false, }); }); @@ -106,6 +109,7 @@ test(`Options - Should merge font option with defaults`, () => { independentGradient: false, transitionGradient: false, env: 'node', + rawMode: false, }); }); @@ -128,6 +132,7 @@ test(`Options - Should merge align option with defaults`, () => { independentGradient: false, transitionGradient: false, env: 'node', + rawMode: false, }); }); @@ -150,6 +155,7 @@ test(`Options - Should merge colors option with defaults`, () => { independentGradient: false, transitionGradient: false, env: 'node', + rawMode: false, }); }); @@ -172,6 +178,7 @@ test(`Options - Should merge background option with defaults`, () => { independentGradient: false, transitionGradient: false, env: 'node', + rawMode: false, }); }); @@ -194,6 +201,7 @@ test(`Options - Should merge backgroundColor option with defaults`, () => { independentGradient: false, transitionGradient: false, env: 'node', + rawMode: false, }); }); @@ -216,6 +224,7 @@ test(`Options - Should merge letterSpacing option with defaults`, () => { independentGradient: false, transitionGradient: false, env: 'node', + rawMode: false, }); }); @@ -238,6 +247,7 @@ test(`Options - Should merge lineHeight option with defaults`, () => { independentGradient: false, transitionGradient: false, env: 'node', + rawMode: false, }); }); @@ -260,6 +270,7 @@ test(`Options - Should merge space option with defaults`, () => { independentGradient: false, transitionGradient: false, env: 'node', + rawMode: false, }); }); @@ -282,6 +293,7 @@ test(`Options - Should merge maxLength option with defaults`, () => { independentGradient: false, transitionGradient: false, env: 'node', + rawMode: false, }); }); @@ -304,6 +316,7 @@ test(`Options - Should merge string-gradient option with defaults`, () => { independentGradient: false, transitionGradient: false, env: 'node', + rawMode: false, }); }); @@ -326,6 +339,7 @@ test(`Options - Should merge array-gradient option with defaults`, () => { independentGradient: false, transitionGradient: false, env: 'node', + rawMode: false, }); }); @@ -348,6 +362,7 @@ test(`Options - Should merge independentGradient option with defaults`, () => { independentGradient: true, transitionGradient: false, env: 'node', + rawMode: false, }); }); @@ -370,6 +385,7 @@ test(`Options - Should merge independentGradient option with defaults`, () => { independentGradient: false, transitionGradient: true, env: 'node', + rawMode: false, }); }); @@ -392,5 +408,29 @@ test(`Options - Should merge env option with defaults`, () => { independentGradient: false, transitionGradient: false, env: 'browser', + rawMode: false, + }); +}); + +test(`Options - Should merge raw-mode option with defaults`, () => { + Options.reset(); + Options.set = { + rawMode: true, + }; + + expect(Options.get).toEqual({ + font: 'block', + align: 'left', + colors: [], + background: 'transparent', + letterSpacing: 1, + lineHeight: 1, + space: true, + maxLength: 0, + gradient: false, + independentGradient: false, + transitionGradient: false, + env: 'node', + rawMode: true, }); }); diff --git a/nodejs/test/unit/ParseArgs.spec.js b/nodejs/test/unit/ParseArgs.spec.js index c952b05..dac6f44 100644 --- a/nodejs/test/unit/ParseArgs.spec.js +++ b/nodejs/test/unit/ParseArgs.spec.js @@ -63,6 +63,7 @@ test(`ParseArgs - Return defaults without arguments`, () => { text: undefined, version: false, env: 'node', + 'raw-mode': false, }; process.argv = ['node', 'script']; // we have to remove process.argv so args passed to our testing lib don't break our test diff --git a/nodejs/test/unit/Render.spec.js b/nodejs/test/unit/Render.spec.js index 73e49af..a1af163 100644 --- a/nodejs/test/unit/Render.spec.js +++ b/nodejs/test/unit/Render.spec.js @@ -23,6 +23,7 @@ beforeEach(() => { independentGradient: false, transitionGradient: false, env: 'node', + rawMode: false, }; Options.set = DEFAULTS; }); @@ -68,6 +69,7 @@ test(`Render - Render console string`, () => { independentGradient: false, transitionGradient: false, env: 'node', + rawMode: false, }); }); @@ -99,6 +101,7 @@ test(`Render - Render console string with a color`, () => { independentGradient: false, transitionGradient: false, env: 'node', + rawMode: false, }); }); @@ -135,6 +138,7 @@ test(`Render - Render console string with gradient will ignore color`, () => { independentGradient: false, transitionGradient: false, env: 'node', + rawMode: false, }); }); @@ -197,6 +201,7 @@ test(`Render - Render block font`, () => { independentGradient: false, transitionGradient: false, env: 'node', + rawMode: false, }); }); @@ -243,6 +248,7 @@ test(`Render - Render letter spacing`, () => { independentGradient: false, transitionGradient: false, env: 'node', + rawMode: false, }); const test2 = Render( @@ -286,6 +292,7 @@ test(`Render - Render letter spacing`, () => { independentGradient: false, transitionGradient: false, env: 'node', + rawMode: false, }); }); @@ -331,6 +338,7 @@ test(`Render - Center align block font`, () => { independentGradient: false, transitionGradient: false, env: 'node', + rawMode: false, }); }); @@ -376,6 +384,7 @@ test(`Render - Right align block font`, () => { independentGradient: false, transitionGradient: false, env: 'node', + rawMode: false, }); }); @@ -420,6 +429,7 @@ test(`Render - Top align block font`, () => { independentGradient: false, transitionGradient: false, env: 'node', + rawMode: false, }); }); @@ -465,6 +475,7 @@ test(`Render - Bottom align block font`, () => { independentGradient: false, transitionGradient: false, env: 'node', + rawMode: false, }); }); @@ -510,6 +521,7 @@ test(`Render - Ignore alignment top when combining it with space option`, () => independentGradient: false, transitionGradient: false, env: 'node', + rawMode: false, }); }); @@ -555,6 +567,7 @@ test(`Render - Ignore alignment bottom when combining it with space option`, () independentGradient: false, transitionGradient: false, env: 'node', + rawMode: false, }); }); @@ -605,6 +618,7 @@ test(`Render - Break into new line on smaller viewports`, () => { independentGradient: false, transitionGradient: false, env: 'node', + rawMode: false, }); }); @@ -642,6 +656,7 @@ test(`Render - Fallback to huge viewport in browser environments`, () => { independentGradient: false, transitionGradient: false, env: 'browser', + rawMode: false, }); }); @@ -692,6 +707,7 @@ test(`Render - Respect maxLength over viewport in browser env`, () => { independentGradient: false, transitionGradient: false, env: 'browser', + rawMode: false, }); }); @@ -729,6 +745,7 @@ test(`Render - Add background color in browser environments`, () => { independentGradient: false, transitionGradient: false, env: 'browser', + rawMode: false, }); }); @@ -779,6 +796,7 @@ test(`Render - Add line break`, () => { independentGradient: false, transitionGradient: false, env: 'node', + rawMode: false, }); }); @@ -830,6 +848,7 @@ test(`Render - Add line height`, () => { independentGradient: false, transitionGradient: false, env: 'node', + rawMode: false, }); }); @@ -867,6 +886,7 @@ test(`Render - Non supported characters are ignored`, () => { independentGradient: false, transitionGradient: false, env: 'node', + rawMode: false, }); }); @@ -903,6 +923,7 @@ test(`Render - Remove space`, () => { independentGradient: false, transitionGradient: false, env: 'node', + rawMode: false, }); }); @@ -942,6 +963,7 @@ test(`Render - Add background color`, () => { independentGradient: false, transitionGradient: false, env: 'node', + rawMode: false, }); }); @@ -958,3 +980,189 @@ test(`Render - Returns false if font is not known`, () => { expect(test).toBe(false); }); + +test(`Render - Render console string in raw mode`, () => { + const test = Render( + 'text', + { + font: 'console', + rawMode: true, + }, + false, + 1, + { width: 100, height: 10 } + ); + + expect(test.string).toBe('\r\n\r\ntext\r\n\r\n'); + expect(test.array).toEqual(['\r\n\r\ntext\r\n\r\n']); + expect(test.lines).toBe(1); + expect(test.options).toEqual({ + font: 'console', + align: 'left', + colors: [], + background: 'transparent', + letterSpacing: 0, + lineHeight: 0, + space: true, + maxLength: 0, + gradient: false, + independentGradient: false, + transitionGradient: false, + env: 'node', + rawMode: true, + }); +}); + +test(`Render - Break into new line on smaller viewports in raw mode`, () => { + const test = Render('text', { rawMode: true }, false, 1, { width: 20, height: 10 }); + + expect(test.string).toBe( + '\r\n\r\n' + + ' ████████╗ ███████╗\r\n' + + ' ╚══██╔══╝ ██╔════╝\r\n' + + ' ██║ █████╗ \r\n' + + ' ██║ ██╔══╝ \r\n' + + ' ██║ ███████╗\r\n' + + ' ╚═╝ ╚══════╝\r\n\r\n' + + ' ██╗ ██╗ ████████╗\r\n' + + ' ╚██╗██╔╝ ╚══██╔══╝\r\n' + + ' ╚███╔╝ ██║ \r\n' + + ' ██╔██╗ ██║ \r\n' + + ' ██╔╝ ██╗ ██║ \r\n' + + ' ╚═╝ ╚═╝ ╚═╝ \r\n\r\n' + ); + expect(test.array).toEqual([ + '\r\n\r\n ████████╗ ███████╗', + ' ╚══██╔══╝ ██╔════╝', + ' ██║ █████╗ ', + ' ██║ ██╔══╝ ', + ' ██║ ███████╗', + ' ╚═╝ ╚══════╝', + '', + ' ██╗ ██╗ ████████╗', + ' ╚██╗██╔╝ ╚══██╔══╝', + ' ╚███╔╝ ██║ ', + ' ██╔██╗ ██║ ', + ' ██╔╝ ██╗ ██║ ', + ' ╚═╝ ╚═╝ ╚═╝ \r\n\r\n', + ]); + expect(test.lines).toBe(2); + expect(test.options).toEqual({ + font: 'block', + align: 'left', + colors: [], + background: 'transparent', + letterSpacing: 1, + lineHeight: 1, + space: true, + maxLength: 0, + gradient: false, + independentGradient: false, + transitionGradient: false, + env: 'node', + rawMode: true, + }); +}); + +test(`Render - Add line break in raw mode`, () => { + const test = Render('te|xt', { rawMode: true }, false, 1, { width: 100, height: 10 }); + + expect(test.string).toBe( + '\r\n\r\n' + + ' ████████╗ ███████╗\r\n' + + ' ╚══██╔══╝ ██╔════╝\r\n' + + ' ██║ █████╗ \r\n' + + ' ██║ ██╔══╝ \r\n' + + ' ██║ ███████╗\r\n' + + ' ╚═╝ ╚══════╝\r\n\r\n' + + ' ██╗ ██╗ ████████╗\r\n' + + ' ╚██╗██╔╝ ╚══██╔══╝\r\n' + + ' ╚███╔╝ ██║ \r\n' + + ' ██╔██╗ ██║ \r\n' + + ' ██╔╝ ██╗ ██║ \r\n' + + ' ╚═╝ ╚═╝ ╚═╝ \r\n\r\n' + ); + expect(test.array).toEqual([ + '\r\n\r\n ████████╗ ███████╗', + ' ╚══██╔══╝ ██╔════╝', + ' ██║ █████╗ ', + ' ██║ ██╔══╝ ', + ' ██║ ███████╗', + ' ╚═╝ ╚══════╝', + '', + ' ██╗ ██╗ ████████╗', + ' ╚██╗██╔╝ ╚══██╔══╝', + ' ╚███╔╝ ██║ ', + ' ██╔██╗ ██║ ', + ' ██╔╝ ██╗ ██║ ', + ' ╚═╝ ╚═╝ ╚═╝ \r\n\r\n', + ]); + expect(test.lines).toBe(2); + expect(test.options).toEqual({ + font: 'block', + align: 'left', + colors: [], + background: 'transparent', + letterSpacing: 1, + lineHeight: 1, + space: true, + maxLength: 0, + gradient: false, + independentGradient: false, + transitionGradient: false, + env: 'node', + rawMode: true, + }); +}); + +test(`Render - Add line height in raw mode`, () => { + const test = Render('te|xt', { lineHeight: 2, rawMode: true }, false, 1, { width: 100, height: 10 }); + + expect(test.string).toBe( + '\r\n\r\n' + + ' ████████╗ ███████╗\r\n' + + ' ╚══██╔══╝ ██╔════╝\r\n' + + ' ██║ █████╗ \r\n' + + ' ██║ ██╔══╝ \r\n' + + ' ██║ ███████╗\r\n' + + ' ╚═╝ ╚══════╝\r\n\r\n\r\n' + + ' ██╗ ██╗ ████████╗\r\n' + + ' ╚██╗██╔╝ ╚══██╔══╝\r\n' + + ' ╚███╔╝ ██║ \r\n' + + ' ██╔██╗ ██║ \r\n' + + ' ██╔╝ ██╗ ██║ \r\n' + + ' ╚═╝ ╚═╝ ╚═╝ \r\n\r\n' + ); + expect(test.array).toEqual([ + '\r\n\r\n ████████╗ ███████╗', + ' ╚══██╔══╝ ██╔════╝', + ' ██║ █████╗ ', + ' ██║ ██╔══╝ ', + ' ██║ ███████╗', + ' ╚═╝ ╚══════╝', + '', + '', + ' ██╗ ██╗ ████████╗', + ' ╚██╗██╔╝ ╚══██╔══╝', + ' ╚███╔╝ ██║ ', + ' ██╔██╗ ██║ ', + ' ██╔╝ ██╗ ██║ ', + ' ╚═╝ ╚═╝ ╚═╝ \r\n\r\n', + ]); + expect(test.lines).toBe(2); + expect(test.options).toEqual({ + font: 'block', + align: 'left', + colors: [], + background: 'transparent', + letterSpacing: 1, + lineHeight: 2, + space: true, + maxLength: 0, + gradient: false, + independentGradient: false, + transitionGradient: false, + env: 'node', + rawMode: true, + }); +}); diff --git a/nodejs/test/unit/bin.spec.js b/nodejs/test/unit/bin.spec.js index 3d10e39..c25f6bf 100644 --- a/nodejs/test/unit/bin.spec.js +++ b/nodejs/test/unit/bin.spec.js @@ -460,3 +460,367 @@ test(`Bin - Will run all flags, gradient, i flag and transition with chrome font expect(output.stdout).toBe(expected); expect(output.stderr).toBe(''); }); + +// raw mode tests +// last line break in expected results in tests is created by console output, therefore it is not expected +// to be '\r\n' +test(`Bin - Will run all non-gradient flags (including raw-mode) with console`, () => { + const output = Spawn( + 'node', + [ + path.normalize(`${__dirname}/../../src/bin.js`), + 'abc|xxx', + '-f', + 'console', + '-a', + 'right', + '-c', + 'red', + '-b', + 'white', + '-l', + '3', + '-z', + '4', + '-s', + '-m', + '80', + '-r', + ], + { + encoding: 'utf8', + env: { ...process.env }, + } + ); + + const expected = + '' + + '\x1B[47m\r\n' + + ' \x1B[31m\x1B[39m\x1B[31m\x1B[39m\x1B[31m\x1B[39m\x1B[31ma\x1B[39m\x1B[31m\x1B[39m\x1B[31m\x1B[39m\x1B[31m\x1B[39m\x1B[31mb\x1B[39m\x1B[31m\x1B[39m\x1B[31m\x1B[39m\x1B[31m\x1B[39m\x1B[31mc\x1B[39m\r\n' + + '\r\n' + + '\r\n' + + '\r\n' + + '\r\n' + + ' \x1B[31m\x1B[39m\x1B[31m\x1B[39m\x1B[31m\x1B[39m\x1B[31mx\x1B[39m\x1B[31m\x1B[39m\x1B[31m\x1B[39m\x1B[31m\x1B[39m\x1B[31mx\x1B[39m\x1B[31m\x1B[39m\x1B[31m\x1B[39m\x1B[31m\x1B[39m\x1B[31mx\x1B[39m\x1B[49m\n'; + + expect(output.stdout).toBe(expected); + expect(output.stderr).toBe(''); +}); + +test(`Bin - Will run all flags (including raw-mode) and gradient with console`, () => { + const output = Spawn( + 'node', + [ + path.normalize(`${__dirname}/../../src/bin.js`), + 'abc|xxx', + '-f', + 'console', + '-a', + 'right', + '-g', + 'red,blue', + '-b', + 'white', + '-l', + '3', + '-z', + '4', + '-s', + '-m', + '80', + '-r', + ], + { + encoding: 'utf8', + env: { ...process.env }, + } + ); + + const expected = + '' + + '\x1B[47m\r\n' + + ' \x1B[38;2;255;0;0ma\x1B[39m\x1B[38;2;255;127;0m \x1B[39m\x1B[38;2;255;255;0m \x1B[39m\x1B[38;2;127;255;0m \x1B[39m\x1B[38;2;0;255;0mb\x1B[39m\x1B[38;2;0;255;127m \x1B[39m\x1B[38;2;0;255;255m \x1B[39m\x1B[38;2;0;127;255m \x1B[39m\x1B[38;2;0;0;255mc\x1B[39m\r\n' + + '\r\n' + + '\r\n' + + '\r\n' + + '\r\n' + + ' \x1B[38;2;255;0;0mx\x1B[39m\x1B[38;2;255;127;0m \x1B[39m\x1B[38;2;255;255;0m \x1B[39m\x1B[38;2;127;255;0m \x1B[39m\x1B[38;2;0;255;0mx\x1B[39m\x1B[38;2;0;255;127m \x1B[39m\x1B[38;2;0;255;255m \x1B[39m\x1B[38;2;0;127;255m \x1B[39m\x1B[38;2;0;0;255mx\x1B[39m\x1B[49m\n'; + + expect(output.stdout).toBe(expected); + expect(output.stderr).toBe(''); +}); + +test(`Bin - Will run all flags (including raw-mode), gradient and i flag with console`, () => { + const output = Spawn( + 'node', + [ + path.normalize(`${__dirname}/../../src/bin.js`), + 'abc|xx', + '-f', + 'console', + '-a', + 'right', + '-g', + 'red,blue', + '-i', + '-b', + 'white', + '-l', + '3', + '-z', + '4', + '-s', + '-m', + '80', + '-r', + ], + { + encoding: 'utf8', + env: { ...process.env }, + } + ); + + const expected = + '' + + '\x1B[47m\r\n' + + ' \x1B[38;2;255;0;0ma\x1B[39m\x1B[38;2;255;127;0m \x1B[39m\x1B[38;2;255;255;0m \x1B[39m\x1B[38;2;127;255;0m \x1B[39m\x1B[38;2;0;255;0mb\x1B[39m\x1B[38;2;0;255;127m \x1B[39m\x1B[38;2;0;255;255m \x1B[39m\x1B[38;2;0;127;255m \x1B[39m\x1B[38;2;0;0;255mc\x1B[39m\r\n' + + '\r\n' + + '\r\n' + + '\r\n' + + '\r\n' + + ' \x1B[38;2;255;0;0mx\x1B[39m\x1B[38;2;255;255;0m \x1B[39m\x1B[38;2;0;255;0m \x1B[39m\x1B[38;2;0;255;255m \x1B[39m\x1B[38;2;0;0;255mx\x1B[39m\x1B[49m\n'; + + expect(output.stdout).toBe(expected); + expect(output.stderr).toBe(''); +}); + +test(`Bin - Will run all flags (including raw-mode), gradient, i flag and transition with console`, () => { + const output = Spawn( + 'node', + [ + path.normalize(`${__dirname}/../../src/bin.js`), + 'abc|xx', + '-f', + 'console', + '-a', + 'right', + '-g', + 'red,blue', + '-i', + '-t', + '-b', + 'white', + '-l', + '3', + '-z', + '4', + '-s', + '-m', + '80', + '-r', + ], + { + encoding: 'utf8', + env: { ...process.env }, + } + ); + + const expected = + '' + + '\x1B[47m\r\n' + + ' \x1B[38;2;255;0;0ma\x1B[39m\x1B[38;2;223;0;31m \x1B[39m\x1B[38;2;191;0;63m \x1B[39m\x1B[38;2;159;0;95m \x1B[39m\x1B[38;2;127;0;127mb\x1B[39m\x1B[38;2;95;0;159m \x1B[39m\x1B[38;2;63;0;191m \x1B[39m\x1B[38;2;31;0;223m \x1B[39m\x1B[38;2;0;0;255mc\x1B[39m\r\n' + + '\r\n' + + '\r\n' + + '\r\n' + + '\r\n' + + ' \x1B[38;2;255;0;0mx\x1B[39m\x1B[38;2;191;0;63m \x1B[39m\x1B[38;2;127;0;127m \x1B[39m\x1B[38;2;63;0;191m \x1B[39m\x1B[38;2;0;0;255mx\x1B[39m\x1B[49m\n'; + + expect(output.stdout).toBe(expected); + expect(output.stderr).toBe(''); +}); + +test(`Bin - Will run all non-gradient flags (including raw-mode) with chrome font`, () => { + const output = Spawn( + 'node', + [ + path.normalize(`${__dirname}/../../src/bin.js`), + 'abc|aa', + '-f', + 'chrome', + '-a', + 'right', + '-c', + 'blue,green,yellow', + '-b', + 'red', + '-l', + '4', + '-z', + '3', + '-s', + '-m', + '80', + '-r', + ], + { + encoding: 'utf8', + env: { ...process.env }, + } + ); + + const expected = + '' + + '\x1B[41m\r\n' + + ' \x1B[34m╔═╗\x1B[39m \x1B[34m╔╗ \x1B[39m \x1B[34m╔═╗\x1B[39m\r\n' + + ' \x1B[32m╠═╣\x1B[39m \x1B[32m╠╩╗\x1B[39m \x1B[32m║ \x1B[39m\r\n' + + ' \x1B[33m╩ ╩\x1B[39m \x1B[33m╚═╝\x1B[39m \x1B[33m╚═╝\x1B[39m\r\n' + + '\r\n' + + '\r\n' + + '\r\n' + + ' \x1B[34m╔═╗\x1B[39m \x1B[34m╔═╗\x1B[39m\r\n' + + ' \x1B[32m╠═╣\x1B[39m \x1B[32m╠═╣\x1B[39m\r\n' + + ' \x1B[33m╩ ╩\x1B[39m \x1B[33m╩ ╩\x1B[39m\x1B[49m\n'; + + expect(output.stdout).toBe(expected); + expect(output.stderr).toBe(''); +}); + +test(`Bin - Will run all flags (including raw-mode) and gradient with chrome font`, () => { + const output = Spawn( + 'node', + [ + path.normalize(`${__dirname}/../../src/bin.js`), + 'abc|aa', + '-f', + 'chrome', + '-a', + 'right', + '-g', + 'blue,green', + '-b', + 'red', + '-l', + '4', + '-z', + '3', + '-s', + '-m', + '80', + '-r', + ], + { + encoding: 'utf8', + env: { ...process.env }, + } + ); + + const expected = + '' + + '\x1B[41m\r\n' + + ' \x1B[38;2;0;0;255m╔\x1B[39m\x1B[38;2;63;0;255m═\x1B[39m\x1B[38;2;127;0;255m╗\x1B[39m\x1B[38;2;191;0;255m \x1B[39m\x1B[38;2;255;0;255m \x1B[39m\x1B[38;2;255;0;191m \x1B[39m\x1B[38;2;255;0;127m \x1B[39m\x1B[38;2;255;0;63m╔\x1B[39m\x1B[38;2;255;0;0m╗\x1B[39m\x1B[38;2;255;63;0m \x1B[39m\x1B[38;2;255;127;0m \x1B[39m\x1B[38;2;255;191;0m \x1B[39m\x1B[38;2;255;255;0m \x1B[39m\x1B[38;2;191;255;0m \x1B[39m\x1B[38;2;127;255;0m╔\x1B[39m\x1B[38;2;63;255;0m═\x1B[39m\x1B[38;2;0;255;0m╗\x1B[39m\r\n' + + ' \x1B[38;2;0;0;255m╠\x1B[39m\x1B[38;2;63;0;255m═\x1B[39m\x1B[38;2;127;0;255m╣\x1B[39m\x1B[38;2;191;0;255m \x1B[39m\x1B[38;2;255;0;255m \x1B[39m\x1B[38;2;255;0;191m \x1B[39m\x1B[38;2;255;0;127m \x1B[39m\x1B[38;2;255;0;63m╠\x1B[39m\x1B[38;2;255;0;0m╩\x1B[39m\x1B[38;2;255;63;0m╗\x1B[39m\x1B[38;2;255;127;0m \x1B[39m\x1B[38;2;255;191;0m \x1B[39m\x1B[38;2;255;255;0m \x1B[39m\x1B[38;2;191;255;0m \x1B[39m\x1B[38;2;127;255;0m║\x1B[39m\x1B[38;2;63;255;0m \x1B[39m\x1B[38;2;0;255;0m \x1B[39m\r\n' + + ' \x1B[38;2;0;0;255m╩\x1B[39m\x1B[38;2;63;0;255m \x1B[39m\x1B[38;2;127;0;255m╩\x1B[39m\x1B[38;2;191;0;255m \x1B[39m\x1B[38;2;255;0;255m \x1B[39m\x1B[38;2;255;0;191m \x1B[39m\x1B[38;2;255;0;127m \x1B[39m\x1B[38;2;255;0;63m╚\x1B[39m\x1B[38;2;255;0;0m═\x1B[39m\x1B[38;2;255;63;0m╝\x1B[39m\x1B[38;2;255;127;0m \x1B[39m\x1B[38;2;255;191;0m \x1B[39m\x1B[38;2;255;255;0m \x1B[39m\x1B[38;2;191;255;0m \x1B[39m\x1B[38;2;127;255;0m╚\x1B[39m\x1B[38;2;63;255;0m═\x1B[39m\x1B[38;2;0;255;0m╝\x1B[39m\r\n' + + '\r\n' + + '\r\n' + + '\r\n' + + ' \x1B[38;2;0;0;255m \x1B[39m\x1B[38;2;63;0;255m \x1B[39m\x1B[38;2;127;0;255m \x1B[39m\x1B[38;2;191;0;255m \x1B[39m\x1B[38;2;255;0;255m \x1B[39m\x1B[38;2;255;0;191m \x1B[39m\x1B[38;2;255;0;127m \x1B[39m\x1B[38;2;255;0;63m╔\x1B[39m\x1B[38;2;255;0;0m═\x1B[39m\x1B[38;2;255;63;0m╗\x1B[39m\x1B[38;2;255;127;0m \x1B[39m\x1B[38;2;255;191;0m \x1B[39m\x1B[38;2;255;255;0m \x1B[39m\x1B[38;2;191;255;0m \x1B[39m\x1B[38;2;127;255;0m╔\x1B[39m\x1B[38;2;63;255;0m═\x1B[39m\x1B[38;2;0;255;0m╗\x1B[39m\r\n' + + ' \x1B[38;2;0;0;255m \x1B[39m\x1B[38;2;63;0;255m \x1B[39m\x1B[38;2;127;0;255m \x1B[39m\x1B[38;2;191;0;255m \x1B[39m\x1B[38;2;255;0;255m \x1B[39m\x1B[38;2;255;0;191m \x1B[39m\x1B[38;2;255;0;127m \x1B[39m\x1B[38;2;255;0;63m╠\x1B[39m\x1B[38;2;255;0;0m═\x1B[39m\x1B[38;2;255;63;0m╣\x1B[39m\x1B[38;2;255;127;0m \x1B[39m\x1B[38;2;255;191;0m \x1B[39m\x1B[38;2;255;255;0m \x1B[39m\x1B[38;2;191;255;0m \x1B[39m\x1B[38;2;127;255;0m╠\x1B[39m\x1B[38;2;63;255;0m═\x1B[39m\x1B[38;2;0;255;0m╣\x1B[39m\r\n' + + ' \x1B[38;2;0;0;255m \x1B[39m\x1B[38;2;63;0;255m \x1B[39m\x1B[38;2;127;0;255m \x1B[39m\x1B[38;2;191;0;255m \x1B[39m\x1B[38;2;255;0;255m \x1B[39m\x1B[38;2;255;0;191m \x1B[39m\x1B[38;2;255;0;127m \x1B[39m\x1B[38;2;255;0;63m╩\x1B[39m\x1B[38;2;255;0;0m \x1B[39m\x1B[38;2;255;63;0m╩\x1B[39m\x1B[38;2;255;127;0m \x1B[39m\x1B[38;2;255;191;0m \x1B[39m\x1B[38;2;255;255;0m \x1B[39m\x1B[38;2;191;255;0m \x1B[39m\x1B[38;2;127;255;0m╩\x1B[39m\x1B[38;2;63;255;0m \x1B[39m\x1B[38;2;0;255;0m╩\x1B[39m\x1B[49m\n'; + + expect(output.stdout).toBe(expected); + expect(output.stderr).toBe(''); +}); + +test(`Bin - Will run all flags (including raw-mode), gradient and i flag with chrome font`, () => { + const output = Spawn( + 'node', + [ + path.normalize(`${__dirname}/../../src/bin.js`), + 'abc|aa', + '-f', + 'chrome', + '-a', + 'right', + '-g', + 'blue,green', + '-i', + '-b', + 'red', + '-l', + '4', + '-z', + '3', + '-s', + '-m', + '80', + '-r', + ], + { + encoding: 'utf8', + env: { ...process.env }, + } + ); + + const expected = + '' + + '\x1B[41m\r\n' + + ' \x1B[38;2;0;0;255m╔\x1B[39m\x1B[38;2;63;0;255m═\x1B[39m\x1B[38;2;127;0;255m╗\x1B[39m\x1B[38;2;191;0;255m \x1B[39m\x1B[38;2;255;0;255m \x1B[39m\x1B[38;2;255;0;191m \x1B[39m\x1B[38;2;255;0;127m \x1B[39m\x1B[38;2;255;0;63m╔\x1B[39m\x1B[38;2;255;0;0m╗\x1B[39m\x1B[38;2;255;63;0m \x1B[39m\x1B[38;2;255;127;0m \x1B[39m\x1B[38;2;255;191;0m \x1B[39m\x1B[38;2;255;255;0m \x1B[39m\x1B[38;2;191;255;0m \x1B[39m\x1B[38;2;127;255;0m╔\x1B[39m\x1B[38;2;63;255;0m═\x1B[39m\x1B[38;2;0;255;0m╗\x1B[39m\r\n' + + ' \x1B[38;2;0;0;255m╠\x1B[39m\x1B[38;2;63;0;255m═\x1B[39m\x1B[38;2;127;0;255m╣\x1B[39m\x1B[38;2;191;0;255m \x1B[39m\x1B[38;2;255;0;255m \x1B[39m\x1B[38;2;255;0;191m \x1B[39m\x1B[38;2;255;0;127m \x1B[39m\x1B[38;2;255;0;63m╠\x1B[39m\x1B[38;2;255;0;0m╩\x1B[39m\x1B[38;2;255;63;0m╗\x1B[39m\x1B[38;2;255;127;0m \x1B[39m\x1B[38;2;255;191;0m \x1B[39m\x1B[38;2;255;255;0m \x1B[39m\x1B[38;2;191;255;0m \x1B[39m\x1B[38;2;127;255;0m║\x1B[39m\x1B[38;2;63;255;0m \x1B[39m\x1B[38;2;0;255;0m \x1B[39m\r\n' + + ' \x1B[38;2;0;0;255m╩\x1B[39m\x1B[38;2;63;0;255m \x1B[39m\x1B[38;2;127;0;255m╩\x1B[39m\x1B[38;2;191;0;255m \x1B[39m\x1B[38;2;255;0;255m \x1B[39m\x1B[38;2;255;0;191m \x1B[39m\x1B[38;2;255;0;127m \x1B[39m\x1B[38;2;255;0;63m╚\x1B[39m\x1B[38;2;255;0;0m═\x1B[39m\x1B[38;2;255;63;0m╝\x1B[39m\x1B[38;2;255;127;0m \x1B[39m\x1B[38;2;255;191;0m \x1B[39m\x1B[38;2;255;255;0m \x1B[39m\x1B[38;2;191;255;0m \x1B[39m\x1B[38;2;127;255;0m╚\x1B[39m\x1B[38;2;63;255;0m═\x1B[39m\x1B[38;2;0;255;0m╝\x1B[39m\r\n' + + '\r\n' + + '\r\n' + + '\r\n' + + ' \x1B[38;2;0;0;255m╔\x1B[39m\x1B[38;2;113;0;255m═\x1B[39m\x1B[38;2;226;0;255m╗\x1B[39m\x1B[38;2;255;0;170m \x1B[39m\x1B[38;2;255;0;56m \x1B[39m\x1B[38;2;255;56;0m \x1B[39m\x1B[38;2;255;170;0m \x1B[39m\x1B[38;2;226;255;0m╔\x1B[39m\x1B[38;2;113;255;0m═\x1B[39m\x1B[38;2;0;255;0m╗\x1B[39m\r\n' + + ' \x1B[38;2;0;0;255m╠\x1B[39m\x1B[38;2;113;0;255m═\x1B[39m\x1B[38;2;226;0;255m╣\x1B[39m\x1B[38;2;255;0;170m \x1B[39m\x1B[38;2;255;0;56m \x1B[39m\x1B[38;2;255;56;0m \x1B[39m\x1B[38;2;255;170;0m \x1B[39m\x1B[38;2;226;255;0m╠\x1B[39m\x1B[38;2;113;255;0m═\x1B[39m\x1B[38;2;0;255;0m╣\x1B[39m\r\n' + + ' \x1B[38;2;0;0;255m╩\x1B[39m\x1B[38;2;113;0;255m \x1B[39m\x1B[38;2;226;0;255m╩\x1B[39m\x1B[38;2;255;0;170m \x1B[39m\x1B[38;2;255;0;56m \x1B[39m\x1B[38;2;255;56;0m \x1B[39m\x1B[38;2;255;170;0m \x1B[39m\x1B[38;2;226;255;0m╩\x1B[39m\x1B[38;2;113;255;0m \x1B[39m\x1B[38;2;0;255;0m╩\x1B[39m\x1B[49m\n'; + + expect(output.stdout).toBe(expected); + expect(output.stderr).toBe(''); +}); + +test(`Bin - Will run all flags (including raw-mode), gradient, i flag and transition with chrome font`, () => { + const output = Spawn( + 'node', + [ + path.normalize(`${__dirname}/../../src/bin.js`), + 'abc|aa', + '-f', + 'chrome', + '-a', + 'right', + '-g', + 'blue,green', + '-i', + '-t', + '-b', + 'red', + '-l', + '4', + '-z', + '3', + '-s', + '-m', + '80', + '-r', + ], + { + encoding: 'utf8', + env: { ...process.env }, + } + ); + + const expected = + '\x1B[41m\r\n' + + ' \x1B[38;2;0;0;255m╔\x1B[39m\x1B[38;2;0;15;239m═\x1B[39m\x1B[38;2;0;31;223m╗\x1B[39m\x1B[38;2;0;47;207m \x1B[39m\x1B[38;2;0;63;191m \x1B[39m\x1B[38;2;0;79;175m \x1B[39m\x1B[38;2;0;95;159m \x1B[39m\x1B[38;2;0;111;143m╔\x1B[39m\x1B[38;2;0;127;127m╗\x1B[39m\x1B[38;2;0;143;111m \x1B[39m\x1B[38;2;0;159;95m \x1B[39m\x1B[38;2;0;175;79m \x1B[39m\x1B[38;2;0;191;63m \x1B[39m\x1B[38;2;0;207;47m \x1B[39m\x1B[38;2;0;223;31m╔\x1B[39m\x1B[38;2;0;239;15m═\x1B[39m\x1B[38;2;0;255;0m╗\x1B[39m\r\n' + + ' \x1B[38;2;0;0;255m╠\x1B[39m\x1B[38;2;0;15;239m═\x1B[39m\x1B[38;2;0;31;223m╣\x1B[39m\x1B[38;2;0;47;207m \x1B[39m\x1B[38;2;0;63;191m \x1B[39m\x1B[38;2;0;79;175m \x1B[39m\x1B[38;2;0;95;159m \x1B[39m\x1B[38;2;0;111;143m╠\x1B[39m\x1B[38;2;0;127;127m╩\x1B[39m\x1B[38;2;0;143;111m╗\x1B[39m\x1B[38;2;0;159;95m \x1B[39m\x1B[38;2;0;175;79m \x1B[39m\x1B[38;2;0;191;63m \x1B[39m\x1B[38;2;0;207;47m \x1B[39m\x1B[38;2;0;223;31m║\x1B[39m\x1B[38;2;0;239;15m \x1B[39m\x1B[38;2;0;255;0m \x1B[39m\r\n' + + ' \x1B[38;2;0;0;255m╩\x1B[39m\x1B[38;2;0;15;239m \x1B[39m\x1B[38;2;0;31;223m╩\x1B[39m\x1B[38;2;0;47;207m \x1B[39m\x1B[38;2;0;63;191m \x1B[39m\x1B[38;2;0;79;175m \x1B[39m\x1B[38;2;0;95;159m \x1B[39m\x1B[38;2;0;111;143m╚\x1B[39m\x1B[38;2;0;127;127m═\x1B[39m\x1B[38;2;0;143;111m╝\x1B[39m\x1B[38;2;0;159;95m \x1B[39m\x1B[38;2;0;175;79m \x1B[39m\x1B[38;2;0;191;63m \x1B[39m\x1B[38;2;0;207;47m \x1B[39m\x1B[38;2;0;223;31m╚\x1B[39m\x1B[38;2;0;239;15m═\x1B[39m\x1B[38;2;0;255;0m╝\x1B[39m\r\n' + + '\r\n' + + '\r\n' + + '\r\n' + + ' \x1B[38;2;0;0;255m╔\x1B[39m\x1B[38;2;0;28;226m═\x1B[39m\x1B[38;2;0;56;198m╗\x1B[39m\x1B[38;2;0;85;170m \x1B[39m\x1B[38;2;0;113;141m \x1B[39m\x1B[38;2;0;141;113m \x1B[39m\x1B[38;2;0;170;85m \x1B[39m\x1B[38;2;0;198;56m╔\x1B[39m\x1B[38;2;0;226;28m═\x1B[39m\x1B[38;2;0;255;0m╗\x1B[39m\r\n' + + ' \x1B[38;2;0;0;255m╠\x1B[39m\x1B[38;2;0;28;226m═\x1B[39m\x1B[38;2;0;56;198m╣\x1B[39m\x1B[38;2;0;85;170m \x1B[39m\x1B[38;2;0;113;141m \x1B[39m\x1B[38;2;0;141;113m \x1B[39m\x1B[38;2;0;170;85m \x1B[39m\x1B[38;2;0;198;56m╠\x1B[39m\x1B[38;2;0;226;28m═\x1B[39m\x1B[38;2;0;255;0m╣\x1B[39m\r\n' + + ' \x1B[38;2;0;0;255m╩\x1B[39m\x1B[38;2;0;28;226m \x1B[39m\x1B[38;2;0;56;198m╩\x1B[39m\x1B[38;2;0;85;170m \x1B[39m\x1B[38;2;0;113;141m \x1B[39m\x1B[38;2;0;141;113m \x1B[39m\x1B[38;2;0;170;85m \x1B[39m\x1B[38;2;0;198;56m╩\x1B[39m\x1B[38;2;0;226;28m \x1B[39m\x1B[38;2;0;255;0m╩\x1B[39m\x1B[49m\n'; + + expect(output.stdout).toBe(expected); + expect(output.stderr).toBe(''); +}); diff --git a/rust/tests/args_test.rs b/rust/tests/args_test.rs index 794d261..5bf9e76 100644 --- a/rust/tests/args_test.rs +++ b/rust/tests/args_test.rs @@ -128,6 +128,7 @@ mod args { options.transition_gradient = true; options.version = true; options.debug = true; + options.raw_mode = true; // long flags assert_eq!( @@ -140,6 +141,7 @@ mod args { "--independent-gradient".to_string(), "--transition-gradient".to_string(), "--debug".to_string(), + "--raw-mode".to_string(), ]) .unwrap(), options @@ -156,13 +158,17 @@ mod args { "-i".to_string(), "-t".to_string(), "-d".to_string(), + "-r".to_string(), ]) .unwrap(), options ); // stacked flags - assert_eq!(parse(vec!["path/to/bin".to_string(), "my text".to_string(), "-vhsitd".to_string(),]).unwrap(), options); + assert_eq!( + parse(vec!["path/to/bin".to_string(), "my text".to_string(), "-vhsitdr".to_string(),]).unwrap(), + options + ); } #[test] @@ -1829,6 +1835,7 @@ mod args { options.version = true; options.debug = true; options.debug_level = 3; + options.raw_mode = true; assert_eq!( parse(vec![ @@ -1860,6 +1867,7 @@ mod args { "-d".to_string(), "-x".to_string(), "3".to_string(), + "-r".to_string(), ]) .unwrap(), options @@ -1881,7 +1889,7 @@ mod args { "9".to_string(), "-z".to_string(), "2".to_string(), - "-sithvd".to_string(), + "-sithvdr".to_string(), "-m".to_string(), "100".to_string(), "-g".to_string(), @@ -1911,7 +1919,13 @@ mod args { "9".to_string(), "--line-height".to_string(), "2".to_string(), - "-sithvd".to_string(), + "--spaceless".to_string(), + "--independent-gradient".to_string(), + "--transition-gradient".to_string(), + "--help".to_string(), + "--version".to_string(), + "--debug".to_string(), + "--raw-mode".to_string(), "--max-length".to_string(), "100".to_string(), "--gradient".to_string(), diff --git a/rust/tests/end-to-end_test.rs b/rust/tests/end-to-end_test.rs index 0081b7d..d7849ed 100644 --- a/rust/tests/end-to-end_test.rs +++ b/rust/tests/end-to-end_test.rs @@ -2156,6 +2156,221 @@ fn get_all_tests() -> Vec { force_color: String::from(""), no_color: false, }, + // Raw mode string tests + // Last line break in expected results in tests is created by console output, therefore it is not expected + // to be '\r\n' + Test { + name: String::from("Raw mode string test"), + args: vec!["test".to_string(), "--raw-mode".to_string()], + fixture: concat!( + "\r\n\r\n", + " ████████╗ ███████╗ ███████╗ ████████╗\r\n", + " ╚══██╔══╝ ██╔════╝ ██╔════╝ ╚══██╔══╝\r\n", + " ██║ █████╗ ███████╗ ██║ \r\n", + " ██║ ██╔══╝ ╚════██║ ██║ \r\n", + " ██║ ███████╗ ███████║ ██║ \r\n", + " ╚═╝ ╚══════╝ ╚══════╝ ╚═╝ \r\n\r\n", + "\n").to_string(), + force_color: String::from(""), + no_color: false, + }, + Test { + name: String::from("Raw mode string test (short flag)"), + args: vec!["test".to_string(), "-r".to_string()], + fixture: concat!( + "\r\n\r\n", + " ████████╗ ███████╗ ███████╗ ████████╗\r\n", + " ╚══██╔══╝ ██╔════╝ ██╔════╝ ╚══██╔══╝\r\n", + " ██║ █████╗ ███████╗ ██║ \r\n", + " ██║ ██╔══╝ ╚════██║ ██║ \r\n", + " ██║ ███████╗ ███████║ ██║ \r\n", + " ╚═╝ ╚══════╝ ╚══════╝ ╚═╝ \r\n\r\n", + "\n").to_string(), + force_color: String::from(""), + no_color: false, + }, + Test { + name: String::from("Align center raw mode string"), + args: vec!["test".to_string(), "-a".to_string() ,"center".to_string(), "--raw-mode".to_string()], + fixture: concat!("\r\n\r\n", + " ████████╗ ███████╗ ███████╗ ████████╗\r\n", + " ╚══██╔══╝ ██╔════╝ ██╔════╝ ╚══██╔══╝\r\n", + " ██║ █████╗ ███████╗ ██║ \r\n", + " ██║ ██╔══╝ ╚════██║ ██║ \r\n", + " ██║ ███████╗ ███████║ ██║ \r\n", + " ╚═╝ ╚══════╝ ╚══════╝ ╚═╝ \r\n\r\n", + "\n").to_string(), + force_color: String::from(""), + no_color: false, + }, + Test { + name: String::from("Align right raw mode string"), + args: vec!["test".to_string(), "-a".to_string() ,"right".to_string(), "--raw-mode".to_string()], + fixture: concat!("\r\n\r\n", + " ████████╗ ███████╗ ███████╗ ████████╗\r\n", + " ╚══██╔══╝ ██╔════╝ ██╔════╝ ╚══██╔══╝\r\n", + " ██║ █████╗ ███████╗ ██║ \r\n", + " ██║ ██╔══╝ ╚════██║ ██║ \r\n", + " ██║ ███████╗ ███████║ ██║ \r\n", + " ╚═╝ ╚══════╝ ╚══════╝ ╚═╝ \r\n\r\n", + "\n").to_string(), + force_color: String::from(""), + no_color: false, + }, + Test { + name: String::from("Align top raw mode string"), + args: vec!["test".to_string(), "-a".to_string() ,"top".to_string(), "--raw-mode".to_string()], + fixture: concat!("", + " ████████╗ ███████╗ ███████╗ ████████╗\r\n", + " ╚══██╔══╝ ██╔════╝ ██╔════╝ ╚══██╔══╝\r\n", + " ██║ █████╗ ███████╗ ██║ \r\n", + " ██║ ██╔══╝ ╚════██║ ██║ \r\n", + " ██║ ███████╗ ███████║ ██║ \r\n", + " ╚═╝ ╚══════╝ ╚══════╝ ╚═╝ \r\n\r\n\r\n\r\n", + "\n").to_string(), + force_color: String::from(""), + no_color: false, + }, + Test { + name: String::from("Align bottom raw mode string"), + args: vec!["test".to_string(), "-a".to_string() ,"bottom".to_string(), "--raw-mode".to_string()], + fixture: concat!("\r\n\r\n\r\n\r\n", + " ████████╗ ███████╗ ███████╗ ████████╗\r\n", + " ╚══██╔══╝ ██╔════╝ ██╔════╝ ╚══██╔══╝\r\n", + " ██║ █████╗ ███████╗ ██║ \r\n", + " ██║ ██╔══╝ ╚════██║ ██║ \r\n", + " ██║ ███████╗ ███████║ ██║ \r\n", + " ╚═╝ ╚══════╝ ╚══════╝ ╚═╝ ", + "\n").to_string(), + force_color: String::from(""), + no_color: false, + }, + Test { + name: String::from("Letter spacing 2 raw mode string"), + args: vec!["test".to_string(), "-l".to_string() ,"2".to_string(), "--raw-mode".to_string()], + fixture: concat!("\r\n\r\n", + " ████████╗ ███████╗ ███████╗ ████████╗\r\n", + " ╚══██╔══╝ ██╔════╝ ██╔════╝ ╚══██╔══╝\r\n", + " ██║ █████╗ ███████╗ ██║ \r\n", + " ██║ ██╔══╝ ╚════██║ ██║ \r\n", + " ██║ ███████╗ ███████║ ██║ \r\n", + " ╚═╝ ╚══════╝ ╚══════╝ ╚═╝ \r\n\r\n", + "\n").to_string(), + force_color: String::from(""), + no_color: false, + }, + Test { + name: String::from("Letter spacing 10 raw mode string"), + args: vec!["test".to_string(), "-l".to_string() ,"10".to_string(), "--raw-mode".to_string()], + fixture: concat!("\r\n\r\n", + " ████████╗ ███████╗ ███████╗ ████████╗\r\n", + " ╚══██╔══╝ ██╔════╝ ██╔════╝ ╚══██╔══╝\r\n", + " ██║ █████╗ ███████╗ ██║ \r\n", + " ██║ ██╔══╝ ╚════██║ ██║ \r\n", + " ██║ ███████╗ ███████║ ██║ \r\n", + " ╚═╝ ╚══════╝ ╚══════╝ ╚═╝ \r\n\r\n", + "\n").to_string(), + force_color: String::from(""), + no_color: false, + }, + Test { + name: String::from("Line break raw mode string"), + args: vec!["test|line".to_string(), "--raw-mode".to_string()], + fixture: concat!("\r\n\r\n", + " ████████╗ ███████╗ ███████╗ ████████╗\r\n", + " ╚══██╔══╝ ██╔════╝ ██╔════╝ ╚══██╔══╝\r\n", + " ██║ █████╗ ███████╗ ██║ \r\n", + " ██║ ██╔══╝ ╚════██║ ██║ \r\n", + " ██║ ███████╗ ███████║ ██║ \r\n", + " ╚═╝ ╚══════╝ ╚══════╝ ╚═╝ \r\n", + "\r\n", + " ██╗ ██╗ ███╗ ██╗ ███████╗\r\n", + " ██║ ██║ ████╗ ██║ ██╔════╝\r\n", + " ██║ ██║ ██╔██╗ ██║ █████╗ \r\n", + " ██║ ██║ ██║╚██╗██║ ██╔══╝ \r\n", + " ███████╗ ██║ ██║ ╚████║ ███████╗\r\n", + " ╚══════╝ ╚═╝ ╚═╝ ╚═══╝ ╚══════╝\r\n\r\n", + "\n").to_string(), + force_color: String::from(""), + no_color: false, + }, + Test { + name: String::from("Line height raw mode string"), + args: vec!["test|line".to_string(), "-z".to_string(), "5".to_string(), "--raw-mode".to_string()], + fixture: concat!("\r\n\r\n", + " ████████╗ ███████╗ ███████╗ ████████╗\r\n", + " ╚══██╔══╝ ██╔════╝ ██╔════╝ ╚══██╔══╝\r\n", + " ██║ █████╗ ███████╗ ██║ \r\n", + " ██║ ██╔══╝ ╚════██║ ██║ \r\n", + " ██║ ███████╗ ███████║ ██║ \r\n", + " ╚═╝ ╚══════╝ ╚══════╝ ╚═╝ \r\n", + "\r\n\r\n\r\n\r\n\r\n", + " ██╗ ██╗ ███╗ ██╗ ███████╗\r\n", + " ██║ ██║ ████╗ ██║ ██╔════╝\r\n", + " ██║ ██║ ██╔██╗ ██║ █████╗ \r\n", + " ██║ ██║ ██║╚██╗██║ ██╔══╝ \r\n", + " ███████╗ ██║ ██║ ╚████║ ███████╗\r\n", + " ╚══════╝ ╚═╝ ╚═╝ ╚═══╝ ╚══════╝\r\n\r\n", + "\n").to_string(), + force_color: String::from(""), + no_color: false, + }, + Test { + name: String::from("Spaceless raw mode string"), + args: vec!["test".to_string(), "-s".to_string(), "--raw-mode".to_string()], + fixture: concat!("", + " ████████╗ ███████╗ ███████╗ ████████╗\r\n", + " ╚══██╔══╝ ██╔════╝ ██╔════╝ ╚══██╔══╝\r\n", + " ██║ █████╗ ███████╗ ██║ \r\n", + " ██║ ██╔══╝ ╚════██║ ██║ \r\n", + " ██║ ███████╗ ███████║ ██║ \r\n", + " ╚═╝ ╚══════╝ ╚══════╝ ╚═╝ ", + "\n").to_string(), + force_color: String::from(""), + no_color: false, + }, + Test { + name: String::from("Max length at 2 raw mode string"), + args: vec!["test".to_string(), "-m".to_string(), "2".to_string(), "--raw-mode".to_string()], + fixture: concat!("\r\n\r\n", + " ████████╗ ███████╗\r\n", + " ╚══██╔══╝ ██╔════╝\r\n", + " ██║ █████╗ \r\n", + " ██║ ██╔══╝ \r\n", + " ██║ ███████╗\r\n", + " ╚═╝ ╚══════╝\r\n", + "\r\n", + " ███████╗ ████████╗\r\n", + " ██╔════╝ ╚══██╔══╝\r\n", + " ███████╗ ██║ \r\n", + " ╚════██║ ██║ \r\n", + " ███████║ ██║ \r\n", + " ╚══════╝ ╚═╝ \r\n\r\n", + "\n").to_string(), + force_color: String::from(""), + no_color: false, + }, + Test { + name: String::from("Max length at 3 raw mode string"), + args: vec!["test".to_string(), "-m".to_string(), "3".to_string(), "--raw-mode".to_string()], + fixture: concat!("\r\n\r\n", + " ████████╗ ███████╗ ███████╗\r\n", + " ╚══██╔══╝ ██╔════╝ ██╔════╝\r\n", + " ██║ █████╗ ███████╗\r\n", + " ██║ ██╔══╝ ╚════██║\r\n", + " ██║ ███████╗ ███████║\r\n", + " ╚═╝ ╚══════╝ ╚══════╝\r\n", + "\r\n", + " ████████╗\r\n", + " ╚══██╔══╝\r\n", + " ██║ \r\n", + " ██║ \r\n", + " ██║ \r\n", + " ╚═╝ \r\n\r\n", + "\n").to_string(), + force_color: String::from(""), + no_color: false, + }, ]; tests From 42125c191a5b1d724816149a8ea659e49b39fb6b Mon Sep 17 00:00:00 2001 From: FriedlandAaron <3793162+FriedlandAaron@users.noreply.github.com> Date: Sun, 9 Jun 2024 10:06:17 +0300 Subject: [PATCH 06/12] fix lint warnings --- rust/src/args.rs | 16 ++++++++-------- rust/src/render.rs | 24 +++++++++++------------- 2 files changed, 19 insertions(+), 21 deletions(-) diff --git a/rust/src/args.rs b/rust/src/args.rs index 3762039..e580711 100644 --- a/rust/src/args.rs +++ b/rust/src/args.rs @@ -69,7 +69,7 @@ use crate::debug::{d, Dt}; /// "-d".to_string(), /// "-x".to_string(), /// "3".to_string(), -/// "-r".to_string(), +/// "-r".to_string(), /// ]) /// .unwrap(), /// options @@ -123,13 +123,13 @@ use crate::debug::{d, Dt}; /// "9".to_string(), /// "--line-height".to_string(), /// "2".to_string(), -/// "--spaceless".to_string(), -/// "--independent-gradient".to_string(), -/// "--transition-gradient".to_string(), -/// "--help".to_string(), -/// "--version".to_string(), -/// "--debug".to_string(), -/// "--raw-mode".to_string(), +/// "--spaceless".to_string(), +/// "--independent-gradient".to_string(), +/// "--transition-gradient".to_string(), +/// "--help".to_string(), +/// "--version".to_string(), +/// "--debug".to_string(), +/// "--raw-mode".to_string(), /// "--max-length".to_string(), /// "100".to_string(), /// "--gradient".to_string(), diff --git a/rust/src/render.rs b/rust/src/render.rs index ba2be66..d34966f 100644 --- a/rust/src/render.rs +++ b/rust/src/render.rs @@ -50,13 +50,13 @@ pub struct RenderedString { /// " █▀█ ██▄ █▄▄ █▄▄ █▄█\n\n" /// ) /// ); -/// let output = render(Options { -/// text: String::from("hello"), -/// font: Fonts::FontTiny, -/// raw_mode: true, -/// ..Options::default() -/// }); -/// assert_eq!( +/// let output = render(Options { +/// text: String::from("hello"), +/// font: Fonts::FontTiny, +/// raw_mode: true, +/// ..Options::default() +/// }); +/// assert_eq!( /// output.text, /// format!("{}{}{}", /// "\r\n\r\n", @@ -230,13 +230,11 @@ pub fn render(options: Options) -> RenderedString { } // Handle raw mode only in Cli env - if options.env == Env::Cli { - if options.raw_mode { - for v in output.iter_mut() { - *v = v.replace('\n', "\r\n"); - } - text = text.replace('\n', "\r\n"); + if options.env == Env::Cli && options.raw_mode { + for v in output.iter_mut() { + *v = v.replace('\n', "\r\n"); } + text = text.replace('\n', "\r\n"); } d(&format!("render() final output string: {:?}", text), 1, Dt::Log, &options, &mut std::io::stdout()); From 219048ce5cac4e63733bae69970db1fcb3a78b40 Mon Sep 17 00:00:00 2001 From: FriedlandAaron <3793162+FriedlandAaron@users.noreply.github.com> Date: Sun, 9 Jun 2024 13:32:37 +0300 Subject: [PATCH 07/12] update help for raw mode flag --- nodejs/src/constants.js | 2 +- rust/src/config.rs | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/nodejs/src/constants.js b/nodejs/src/constants.js index 10b8752..697caa5 100644 --- a/nodejs/src/constants.js +++ b/nodejs/src/constants.js @@ -304,7 +304,7 @@ const CLIOPTIONS = { default: 1, }, '--raw-mode': { - description: 'Use to render string newlines properly in raw mode in terminals', + description: 'Use to enable proper newline rendering in raw mode in the terminal by adding \\r to line breaks', example: '--raw-mode', short: '-r', fallback_shortcut: false, diff --git a/rust/src/config.rs b/rust/src/config.rs index 0095a91..2518e72 100644 --- a/rust/src/config.rs +++ b/rust/src/config.rs @@ -503,7 +503,7 @@ pub const CLIOPTIONS: [CliOption; 17] = [ name: "--raw-mode", shortcut: "-r", fallback_shortcut: "", - description: "Use to enable proper newline rendering for 'raw mode' in terminals", + description: "Use to enable proper newline rendering in raw mode in the terminal by adding \\r to line breaks", example: "--raw-mode", kind: OptionType::Bool, }, From d749d0f2c24022d6238b2ca112ea7627906ced3e Mon Sep 17 00:00:00 2001 From: FriedlandAaron <3793162+FriedlandAaron@users.noreply.github.com> Date: Sun, 9 Jun 2024 13:34:07 +0300 Subject: [PATCH 08/12] reposition raw mode arg --- rust/src/args.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/rust/src/args.rs b/rust/src/args.rs index e580711..8f87923 100644 --- a/rust/src/args.rs +++ b/rust/src/args.rs @@ -32,11 +32,11 @@ use crate::debug::{d, Dt}; /// options.independent_gradient = true; /// options.transition_gradient = true; /// options.env = Env::Browser; +/// options.raw_mode = true; /// options.help = true; /// options.version = true; /// options.debug = true; /// options.debug_level = 3; -/// options.raw_mode = true; /// /// // All shortcut flags /// assert_eq!( @@ -64,12 +64,12 @@ use crate::debug::{d, Dt}; /// "-t".to_string(), /// "-e".to_string(), /// "browser".to_string(), +/// "-r".to_string(), /// "-h".to_string(), /// "-v".to_string(), /// "-d".to_string(), /// "-x".to_string(), /// "3".to_string(), -/// "-r".to_string(), /// ]) /// .unwrap(), /// options From 6a3ea7cf989e6ab869b0800e5f19399b3dcac01b Mon Sep 17 00:00:00 2001 From: FriedlandAaron <3793162+FriedlandAaron@users.noreply.github.com> Date: Sun, 9 Jun 2024 13:34:26 +0300 Subject: [PATCH 09/12] fix formatting --- rust/src/render.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/rust/src/render.rs b/rust/src/render.rs index d34966f..63a6f04 100644 --- a/rust/src/render.rs +++ b/rust/src/render.rs @@ -50,12 +50,14 @@ pub struct RenderedString { /// " █▀█ ██▄ █▄▄ █▄▄ █▄█\n\n" /// ) /// ); -/// let output = render(Options { +/// +/// let output = render(Options { /// text: String::from("hello"), /// font: Fonts::FontTiny, /// raw_mode: true, /// ..Options::default() /// }); +/// /// assert_eq!( /// output.text, /// format!("{}{}{}", From 0f4d20ab8dd8b608278564f14f4401612e9d8b87 Mon Sep 17 00:00:00 2001 From: FriedlandAaron <3793162+FriedlandAaron@users.noreply.github.com> Date: Sun, 9 Jun 2024 14:00:23 +0300 Subject: [PATCH 10/12] manual alignment of test text --- nodejs/test/unit/Render.spec.js | 363 +++++++++++++++++--------------- 1 file changed, 190 insertions(+), 173 deletions(-) diff --git a/nodejs/test/unit/Render.spec.js b/nodejs/test/unit/Render.spec.js index a1af163..29432cb 100644 --- a/nodejs/test/unit/Render.spec.js +++ b/nodejs/test/unit/Render.spec.js @@ -180,12 +180,13 @@ test(`Render - Render block font`, () => { ' ╚═╝ ╚══════╝ ╚═╝ ╚═╝ ╚═╝ \n\n' ); expect(test.array).toEqual([ - '\n\n ████████╗ ███████╗ ██╗ ██╗ ████████╗', - ' ╚══██╔══╝ ██╔════╝ ╚██╗██╔╝ ╚══██╔══╝', - ' ██║ █████╗ ╚███╔╝ ██║ ', - ' ██║ ██╔══╝ ██╔██╗ ██║ ', - ' ██║ ███████╗ ██╔╝ ██╗ ██║ ', - ' ╚═╝ ╚══════╝ ╚═╝ ╚═╝ ╚═╝ \n\n', + '\n\n' + + ' ████████╗ ███████╗ ██╗ ██╗ ████████╗', + ' ╚══██╔══╝ ██╔════╝ ╚██╗██╔╝ ╚══██╔══╝', + ' ██║ █████╗ ╚███╔╝ ██║ ', + ' ██║ ██╔══╝ ██╔██╗ ██║ ', + ' ██║ ███████╗ ██╔╝ ██╗ ██║ ', + ' ╚═╝ ╚══════╝ ╚═╝ ╚═╝ ╚═╝ \n\n', ]); expect(test.lines).toBe(1); expect(test.options).toEqual({ @@ -227,12 +228,13 @@ test(`Render - Render letter spacing`, () => { '\n' ); expect(test1.array).toEqual([ - '\n\n ████████╗ ███████╗ ██╗ ██╗ ████████╗', - ' ╚══██╔══╝ ██╔════╝ ╚██╗██╔╝ ╚══██╔══╝', - ' ██║ █████╗ ╚███╔╝ ██║ ', - ' ██║ ██╔══╝ ██╔██╗ ██║ ', - ' ██║ ███████╗ ██╔╝ ██╗ ██║ ', - ' ╚═╝ ╚══════╝ ╚═╝ ╚═╝ ╚═╝ \n\n', + '\n\n' + + ' ████████╗ ███████╗ ██╗ ██╗ ████████╗', + ' ╚══██╔══╝ ██╔════╝ ╚██╗██╔╝ ╚══██╔══╝', + ' ██║ █████╗ ╚███╔╝ ██║ ', + ' ██║ ██╔══╝ ██╔██╗ ██║ ', + ' ██║ ███████╗ ██╔╝ ██╗ ██║ ', + ' ╚═╝ ╚══════╝ ╚═╝ ╚═╝ ╚═╝ \n\n', ]); expect(test1.lines).toBe(1); expect(test1.options).toEqual({ @@ -271,12 +273,13 @@ test(`Render - Render letter spacing`, () => { ' ╚═╝ ╚══════╝ ╚═╝ ╚═╝ ╚═╝ \n\n' ); expect(test2.array).toEqual([ - '\n\n ████████╗ ███████╗ ██╗ ██╗ ████████╗', - ' ╚══██╔══╝ ██╔════╝ ╚██╗██╔╝ ╚══██╔══╝', - ' ██║ █████╗ ╚███╔╝ ██║ ', - ' ██║ ██╔══╝ ██╔██╗ ██║ ', - ' ██║ ███████╗ ██╔╝ ██╗ ██║ ', - ' ╚═╝ ╚══════╝ ╚═╝ ╚═╝ ╚═╝ \n\n', + '\n\n' + + ' ████████╗ ███████╗ ██╗ ██╗ ████████╗', + ' ╚══██╔══╝ ██╔════╝ ╚██╗██╔╝ ╚══██╔══╝', + ' ██║ █████╗ ╚███╔╝ ██║ ', + ' ██║ ██╔══╝ ██╔██╗ ██║ ', + ' ██║ ███████╗ ██╔╝ ██╗ ██║ ', + ' ╚═╝ ╚══════╝ ╚═╝ ╚═╝ ╚═╝ \n\n', ]); expect(test2.lines).toBe(1); expect(test2.options).toEqual({ @@ -317,12 +320,13 @@ test(`Render - Center align block font`, () => { ' ╚═╝ ╚══════╝ ╚═╝ ╚═╝ ╚═╝ \n\n' ); expect(test.array).toEqual([ - '\n\n ████████╗ ███████╗ ██╗ ██╗ ████████╗', - ' ╚══██╔══╝ ██╔════╝ ╚██╗██╔╝ ╚══██╔══╝', - ' ██║ █████╗ ╚███╔╝ ██║ ', - ' ██║ ██╔══╝ ██╔██╗ ██║ ', - ' ██║ ███████╗ ██╔╝ ██╗ ██║ ', - ' ╚═╝ ╚══════╝ ╚═╝ ╚═╝ ╚═╝ \n\n', + '\n\n' + + ' ████████╗ ███████╗ ██╗ ██╗ ████████╗', + ' ╚══██╔══╝ ██╔════╝ ╚██╗██╔╝ ╚══██╔══╝', + ' ██║ █████╗ ╚███╔╝ ██║ ', + ' ██║ ██╔══╝ ██╔██╗ ██║ ', + ' ██║ ███████╗ ██╔╝ ██╗ ██║ ', + ' ╚═╝ ╚══════╝ ╚═╝ ╚═╝ ╚═╝ \n\n', ]); expect(test.lines).toBe(1); expect(test.options).toEqual({ @@ -363,12 +367,13 @@ test(`Render - Right align block font`, () => { ' ╚═╝ ╚══════╝ ╚═╝ ╚═╝ ╚═╝ \n\n' ); expect(test.array).toEqual([ - '\n\n ████████╗ ███████╗ ██╗ ██╗ ████████╗', - ' ╚══██╔══╝ ██╔════╝ ╚██╗██╔╝ ╚══██╔══╝', - ' ██║ █████╗ ╚███╔╝ ██║ ', - ' ██║ ██╔══╝ ██╔██╗ ██║ ', - ' ██║ ███████╗ ██╔╝ ██╗ ██║ ', - ' ╚═╝ ╚══════╝ ╚═╝ ╚═╝ ╚═╝ \n\n', + '\n\n' + + ' ████████╗ ███████╗ ██╗ ██╗ ████████╗', + ' ╚══██╔══╝ ██╔════╝ ╚██╗██╔╝ ╚══██╔══╝', + ' ██║ █████╗ ╚███╔╝ ██║ ', + ' ██║ ██╔══╝ ██╔██╗ ██║ ', + ' ██║ ███████╗ ██╔╝ ██╗ ██║ ', + ' ╚═╝ ╚══════╝ ╚═╝ ╚═╝ ╚═╝ \n\n', ]); expect(test.lines).toBe(1); expect(test.options).toEqual({ @@ -401,11 +406,11 @@ test(`Render - Top align block font`, () => { expect(test.string).toBe( ' ████████╗ ███████╗ ██╗ ██╗ ████████╗\n' + - ' ╚══██╔══╝ ██╔════╝ ╚██╗██╔╝ ╚══██╔══╝\n' + - ' ██║ █████╗ ╚███╔╝ ██║ \n' + - ' ██║ ██╔══╝ ██╔██╗ ██║ \n' + - ' ██║ ███████╗ ██╔╝ ██╗ ██║ \n' + - ' ╚═╝ ╚══════╝ ╚═╝ ╚═╝ ╚═╝ \n\n\n\n' + ' ╚══██╔══╝ ██╔════╝ ╚██╗██╔╝ ╚══██╔══╝\n' + + ' ██║ █████╗ ╚███╔╝ ██║ \n' + + ' ██║ ██╔══╝ ██╔██╗ ██║ \n' + + ' ██║ ███████╗ ██╔╝ ██╗ ██║ \n' + + ' ╚═╝ ╚══════╝ ╚═╝ ╚═╝ ╚═╝ \n\n\n\n' ); expect(test.array).toEqual([ ' ████████╗ ███████╗ ██╗ ██╗ ████████╗', @@ -454,12 +459,13 @@ test(`Render - Bottom align block font`, () => { ' ╚═╝ ╚══════╝ ╚═╝ ╚═╝ ╚═╝ ' ); expect(test.array).toEqual([ - '\n\n\n\n ████████╗ ███████╗ ██╗ ██╗ ████████╗', - ' ╚══██╔══╝ ██╔════╝ ╚██╗██╔╝ ╚══██╔══╝', - ' ██║ █████╗ ╚███╔╝ ██║ ', - ' ██║ ██╔══╝ ██╔██╗ ██║ ', - ' ██║ ███████╗ ██╔╝ ██╗ ██║ ', - ' ╚═╝ ╚══════╝ ╚═╝ ╚═╝ ╚═╝ ', + '\n\n\n\n' + + ' ████████╗ ███████╗ ██╗ ██╗ ████████╗', + ' ╚══██╔══╝ ██╔════╝ ╚██╗██╔╝ ╚══██╔══╝', + ' ██║ █████╗ ╚███╔╝ ██║ ', + ' ██║ ██╔══╝ ██╔██╗ ██║ ', + ' ██║ ███████╗ ██╔╝ ██╗ ██║ ', + ' ╚═╝ ╚══════╝ ╚═╝ ╚═╝ ╚═╝ ', ]); expect(test.lines).toBe(1); expect(test.options).toEqual({ @@ -493,11 +499,11 @@ test(`Render - Ignore alignment top when combining it with space option`, () => expect(test.string).toBe( ' ████████╗ ███████╗ ██╗ ██╗ ████████╗\n' + - ' ╚══██╔══╝ ██╔════╝ ╚██╗██╔╝ ╚══██╔══╝\n' + - ' ██║ █████╗ ╚███╔╝ ██║ \n' + - ' ██║ ██╔══╝ ██╔██╗ ██║ \n' + - ' ██║ ███████╗ ██╔╝ ██╗ ██║ \n' + - ' ╚═╝ ╚══════╝ ╚═╝ ╚═╝ ╚═╝ ' + ' ╚══██╔══╝ ██╔════╝ ╚██╗██╔╝ ╚══██╔══╝\n' + + ' ██║ █████╗ ╚███╔╝ ██║ \n' + + ' ██║ ██╔══╝ ██╔██╗ ██║ \n' + + ' ██║ ███████╗ ██╔╝ ██╗ ██║ \n' + + ' ╚═╝ ╚══════╝ ╚═╝ ╚═╝ ╚═╝ ' ); expect(test.array).toEqual([ ' ████████╗ ███████╗ ██╗ ██╗ ████████╗', @@ -539,11 +545,11 @@ test(`Render - Ignore alignment bottom when combining it with space option`, () expect(test.string).toBe( ' ████████╗ ███████╗ ██╗ ██╗ ████████╗\n' + - ' ╚══██╔══╝ ██╔════╝ ╚██╗██╔╝ ╚══██╔══╝\n' + - ' ██║ █████╗ ╚███╔╝ ██║ \n' + - ' ██║ ██╔══╝ ██╔██╗ ██║ \n' + - ' ██║ ███████╗ ██╔╝ ██╗ ██║ \n' + - ' ╚═╝ ╚══════╝ ╚═╝ ╚═╝ ╚═╝ ' + ' ╚══██╔══╝ ██╔════╝ ╚██╗██╔╝ ╚══██╔══╝\n' + + ' ██║ █████╗ ╚███╔╝ ██║ \n' + + ' ██║ ██╔══╝ ██╔██╗ ██║ \n' + + ' ██║ ███████╗ ██╔╝ ██╗ ██║ \n' + + ' ╚═╝ ╚══════╝ ╚═╝ ╚═╝ ╚═╝ ' ); expect(test.array).toEqual([ ' ████████╗ ███████╗ ██╗ ██╗ ████████╗', @@ -590,19 +596,20 @@ test(`Render - Break into new line on smaller viewports`, () => { ' ╚═╝ ╚═╝ ╚═╝ \n\n' ); expect(test.array).toEqual([ - '\n\n ████████╗ ███████╗', - ' ╚══██╔══╝ ██╔════╝', - ' ██║ █████╗ ', - ' ██║ ██╔══╝ ', - ' ██║ ███████╗', - ' ╚═╝ ╚══════╝', - '', - ' ██╗ ██╗ ████████╗', - ' ╚██╗██╔╝ ╚══██╔══╝', - ' ╚███╔╝ ██║ ', - ' ██╔██╗ ██║ ', - ' ██╔╝ ██╗ ██║ ', - ' ╚═╝ ╚═╝ ╚═╝ \n\n', + '\n\n' + + ' ████████╗ ███████╗', + ' ╚══██╔══╝ ██╔════╝', + ' ██║ █████╗ ', + ' ██║ ██╔══╝ ', + ' ██║ ███████╗', + ' ╚═╝ ╚══════╝', + '', + ' ██╗ ██╗ ████████╗', + ' ╚██╗██╔╝ ╚══██╔══╝', + ' ╚███╔╝ ██║ ', + ' ██╔██╗ ██║ ', + ' ██╔╝ ██╗ ██║ ', + ' ╚═╝ ╚═╝ ╚═╝ \n\n', ]); expect(test.lines).toBe(2); expect(test.options).toEqual({ @@ -635,12 +642,13 @@ test(`Render - Fallback to huge viewport in browser environments`, () => { ' ╚═╝ ╚══════╝ ╚═╝ ╚═╝ ╚═╝ \n\n' ); expect(test.array).toEqual([ - '\n\n ████████╗ ███████╗ ██╗ ██╗ ████████╗', - ' ╚══██╔══╝ ██╔════╝ ╚██╗██╔╝ ╚══██╔══╝', - ' ██║ █████╗ ╚███╔╝ ██║ ', - ' ██║ ██╔══╝ ██╔██╗ ██║ ', - ' ██║ ███████╗ ██╔╝ ██╗ ██║ ', - ' ╚═╝ ╚══════╝ ╚═╝ ╚═╝ ╚═╝ \n\n', + '\n\n' + + ' ████████╗ ███████╗ ██╗ ██╗ ████████╗', + ' ╚══██╔══╝ ██╔════╝ ╚██╗██╔╝ ╚══██╔══╝', + ' ██║ █████╗ ╚███╔╝ ██║ ', + ' ██║ ██╔══╝ ██╔██╗ ██║ ', + ' ██║ ███████╗ ██╔╝ ██╗ ██║ ', + ' ╚═╝ ╚══════╝ ╚═╝ ╚═╝ ╚═╝ \n\n', ]); expect(test.lines).toBe(1); expect(test.options).toEqual({ @@ -679,19 +687,20 @@ test(`Render - Respect maxLength over viewport in browser env`, () => { ' ╚═╝ ╚═╝ ╚═╝ \n\n' ); expect(test.array).toEqual([ - '\n\n ████████╗ ███████╗', - ' ╚══██╔══╝ ██╔════╝', - ' ██║ █████╗ ', - ' ██║ ██╔══╝ ', - ' ██║ ███████╗', - ' ╚═╝ ╚══════╝', - '', - ' ██╗ ██╗ ████████╗', - ' ╚██╗██╔╝ ╚══██╔══╝', - ' ╚███╔╝ ██║ ', - ' ██╔██╗ ██║ ', - ' ██╔╝ ██╗ ██║ ', - ' ╚═╝ ╚═╝ ╚═╝ \n\n', + '\n\n' + + ' ████████╗ ███████╗', + ' ╚══██╔══╝ ██╔════╝', + ' ██║ █████╗ ', + ' ██║ ██╔══╝ ', + ' ██║ ███████╗', + ' ╚═╝ ╚══════╝', + '', + ' ██╗ ██╗ ████████╗', + ' ╚██╗██╔╝ ╚══██╔══╝', + ' ╚███╔╝ ██║ ', + ' ██╔██╗ ██║ ', + ' ██╔╝ ██╗ ██║ ', + ' ╚═╝ ╚═╝ ╚═╝ \n\n', ]); expect(test.lines).toBe(2); expect(test.options).toEqual({ @@ -724,12 +733,13 @@ test(`Render - Add background color in browser environments`, () => { ' ╚═╝ ╚══════╝ ╚═╝ ╚═╝ ╚═╝ \n\n' ); expect(test.array).toEqual([ - '\n\n ████████╗ ███████╗ ██╗ ██╗ ████████╗', - ' ╚══██╔══╝ ██╔════╝ ╚██╗██╔╝ ╚══██╔══╝', - ' ██║ █████╗ ╚███╔╝ ██║ ', - ' ██║ ██╔══╝ ██╔██╗ ██║ ', - ' ██║ ███████╗ ██╔╝ ██╗ ██║ ', - ' ╚═╝ ╚══════╝ ╚═╝ ╚═╝ ╚═╝ \n\n', + '\n\n' + + ' ████████╗ ███████╗ ██╗ ██╗ ████████╗', + ' ╚══██╔══╝ ██╔════╝ ╚██╗██╔╝ ╚══██╔══╝', + ' ██║ █████╗ ╚███╔╝ ██║ ', + ' ██║ ██╔══╝ ██╔██╗ ██║ ', + ' ██║ ███████╗ ██╔╝ ██╗ ██║ ', + ' ╚═╝ ╚══════╝ ╚═╝ ╚═╝ ╚═╝ \n\n', ]); expect(test.lines).toBe(1); expect(test.options).toEqual({ @@ -768,19 +778,20 @@ test(`Render - Add line break`, () => { ' ╚═╝ ╚═╝ ╚═╝ \n\n' ); expect(test.array).toEqual([ - '\n\n ████████╗ ███████╗', - ' ╚══██╔══╝ ██╔════╝', - ' ██║ █████╗ ', - ' ██║ ██╔══╝ ', - ' ██║ ███████╗', - ' ╚═╝ ╚══════╝', - '', - ' ██╗ ██╗ ████████╗', - ' ╚██╗██╔╝ ╚══██╔══╝', - ' ╚███╔╝ ██║ ', - ' ██╔██╗ ██║ ', - ' ██╔╝ ██╗ ██║ ', - ' ╚═╝ ╚═╝ ╚═╝ \n\n', + '\n\n' + + ' ████████╗ ███████╗', + ' ╚══██╔══╝ ██╔════╝', + ' ██║ █████╗ ', + ' ██║ ██╔══╝ ', + ' ██║ ███████╗', + ' ╚═╝ ╚══════╝', + '', + ' ██╗ ██╗ ████████╗', + ' ╚██╗██╔╝ ╚══██╔══╝', + ' ╚███╔╝ ██║ ', + ' ██╔██╗ ██║ ', + ' ██╔╝ ██╗ ██║ ', + ' ╚═╝ ╚═╝ ╚═╝ \n\n', ]); expect(test.lines).toBe(2); expect(test.options).toEqual({ @@ -819,20 +830,21 @@ test(`Render - Add line height`, () => { ' ╚═╝ ╚═╝ ╚═╝ \n\n' ); expect(test.array).toEqual([ - '\n\n ████████╗ ███████╗', - ' ╚══██╔══╝ ██╔════╝', - ' ██║ █████╗ ', - ' ██║ ██╔══╝ ', - ' ██║ ███████╗', - ' ╚═╝ ╚══════╝', - '', - '', - ' ██╗ ██╗ ████████╗', - ' ╚██╗██╔╝ ╚══██╔══╝', - ' ╚███╔╝ ██║ ', - ' ██╔██╗ ██║ ', - ' ██╔╝ ██╗ ██║ ', - ' ╚═╝ ╚═╝ ╚═╝ \n\n', + '\n\n' + + ' ████████╗ ███████╗', + ' ╚══██╔══╝ ██╔════╝', + ' ██║ █████╗ ', + ' ██║ ██╔══╝ ', + ' ██║ ███████╗', + ' ╚═╝ ╚══════╝', + '', + '', + ' ██╗ ██╗ ████████╗', + ' ╚██╗██╔╝ ╚══██╔══╝', + ' ╚███╔╝ ██║ ', + ' ██╔██╗ ██║ ', + ' ██╔╝ ██╗ ██║ ', + ' ╚═╝ ╚═╝ ╚═╝ \n\n', ]); expect(test.lines).toBe(2); expect(test.options).toEqual({ @@ -865,12 +877,13 @@ test(`Render - Non supported characters are ignored`, () => { ' ╚═╝ ╚══════╝ ╚═╝ ╚═╝ ╚═╝ \n\n' ); expect(test.array).toEqual([ - '\n\n ████████╗ ███████╗ ██╗ ██╗ ████████╗', - ' ╚══██╔══╝ ██╔════╝ ╚██╗██╔╝ ╚══██╔══╝', - ' ██║ █████╗ ╚███╔╝ ██║ ', - ' ██║ ██╔══╝ ██╔██╗ ██║ ', - ' ██║ ███████╗ ██╔╝ ██╗ ██║ ', - ' ╚═╝ ╚══════╝ ╚═╝ ╚═╝ ╚═╝ \n\n', + '\n\n' + + ' ████████╗ ███████╗ ██╗ ██╗ ████████╗', + ' ╚══██╔══╝ ██╔════╝ ╚██╗██╔╝ ╚══██╔══╝', + ' ██║ █████╗ ╚███╔╝ ██║ ', + ' ██║ ██╔══╝ ██╔██╗ ██║ ', + ' ██║ ███████╗ ██╔╝ ██╗ ██║ ', + ' ╚═╝ ╚══════╝ ╚═╝ ╚═╝ ╚═╝ \n\n', ]); expect(test.lines).toBe(1); expect(test.options).toEqual({ @@ -895,11 +908,11 @@ test(`Render - Remove space`, () => { expect(test.string).toBe( ' ████████╗ ███████╗ ██╗ ██╗ ████████╗\n' + - ' ╚══██╔══╝ ██╔════╝ ╚██╗██╔╝ ╚══██╔══╝\n' + - ' ██║ █████╗ ╚███╔╝ ██║ \n' + - ' ██║ ██╔══╝ ██╔██╗ ██║ \n' + - ' ██║ ███████╗ ██╔╝ ██╗ ██║ \n' + - ' ╚═╝ ╚══════╝ ╚═╝ ╚═╝ ╚═╝ ' + ' ╚══██╔══╝ ██╔════╝ ╚██╗██╔╝ ╚══██╔══╝\n' + + ' ██║ █████╗ ╚███╔╝ ██║ \n' + + ' ██║ ██╔══╝ ██╔██╗ ██║ \n' + + ' ██║ ███████╗ ██╔╝ ██╗ ██║ \n' + + ' ╚═╝ ╚══════╝ ╚═╝ ╚═╝ ╚═╝ ' ); expect(test.array).toEqual([ ' ████████╗ ███████╗ ██╗ ██╗ ████████╗', @@ -942,12 +955,13 @@ test(`Render - Add background color`, () => { '\u001b[49m' ); expect(test.array).toEqual([ - '\u001b[41m\n\n\n ████████╗ ███████╗ ██╗ ██╗ ████████╗', - ' ╚══██╔══╝ ██╔════╝ ╚██╗██╔╝ ╚══██╔══╝', - ' ██║ █████╗ ╚███╔╝ ██║ ', - ' ██║ ██╔══╝ ██╔██╗ ██║ ', - ' ██║ ███████╗ ██╔╝ ██╗ ██║ ', - ' ╚═╝ ╚══════╝ ╚═╝ ╚═╝ ╚═╝ \n\n\u001b[49m', + '\u001b[41m\n\n\n' + + ' ████████╗ ███████╗ ██╗ ██╗ ████████╗', + ' ╚══██╔══╝ ██╔════╝ ╚██╗██╔╝ ╚══██╔══╝', + ' ██║ █████╗ ╚███╔╝ ██║ ', + ' ██║ ██╔══╝ ██╔██╗ ██║ ', + ' ██║ ███████╗ ██╔╝ ██╗ ██║ ', + ' ╚═╝ ╚══════╝ ╚═╝ ╚═╝ ╚═╝ \n\n\u001b[49m', ]); expect(test.lines).toBe(1); expect(test.options).toEqual({ @@ -1032,19 +1046,20 @@ test(`Render - Break into new line on smaller viewports in raw mode`, () => { ' ╚═╝ ╚═╝ ╚═╝ \r\n\r\n' ); expect(test.array).toEqual([ - '\r\n\r\n ████████╗ ███████╗', - ' ╚══██╔══╝ ██╔════╝', - ' ██║ █████╗ ', - ' ██║ ██╔══╝ ', - ' ██║ ███████╗', - ' ╚═╝ ╚══════╝', - '', - ' ██╗ ██╗ ████████╗', - ' ╚██╗██╔╝ ╚══██╔══╝', - ' ╚███╔╝ ██║ ', - ' ██╔██╗ ██║ ', - ' ██╔╝ ██╗ ██║ ', - ' ╚═╝ ╚═╝ ╚═╝ \r\n\r\n', + '\r\n\r\n' + + ' ████████╗ ███████╗', + ' ╚══██╔══╝ ██╔════╝', + ' ██║ █████╗ ', + ' ██║ ██╔══╝ ', + ' ██║ ███████╗', + ' ╚═╝ ╚══════╝', + '', + ' ██╗ ██╗ ████████╗', + ' ╚██╗██╔╝ ╚══██╔══╝', + ' ╚███╔╝ ██║ ', + ' ██╔██╗ ██║ ', + ' ██╔╝ ██╗ ██║ ', + ' ╚═╝ ╚═╝ ╚═╝ \r\n\r\n', ]); expect(test.lines).toBe(2); expect(test.options).toEqual({ @@ -1083,19 +1098,20 @@ test(`Render - Add line break in raw mode`, () => { ' ╚═╝ ╚═╝ ╚═╝ \r\n\r\n' ); expect(test.array).toEqual([ - '\r\n\r\n ████████╗ ███████╗', - ' ╚══██╔══╝ ██╔════╝', - ' ██║ █████╗ ', - ' ██║ ██╔══╝ ', - ' ██║ ███████╗', - ' ╚═╝ ╚══════╝', - '', - ' ██╗ ██╗ ████████╗', - ' ╚██╗██╔╝ ╚══██╔══╝', - ' ╚███╔╝ ██║ ', - ' ██╔██╗ ██║ ', - ' ██╔╝ ██╗ ██║ ', - ' ╚═╝ ╚═╝ ╚═╝ \r\n\r\n', + '\r\n\r\n' + + ' ████████╗ ███████╗', + ' ╚══██╔══╝ ██╔════╝', + ' ██║ █████╗ ', + ' ██║ ██╔══╝ ', + ' ██║ ███████╗', + ' ╚═╝ ╚══════╝', + '', + ' ██╗ ██╗ ████████╗', + ' ╚██╗██╔╝ ╚══██╔══╝', + ' ╚███╔╝ ██║ ', + ' ██╔██╗ ██║ ', + ' ██╔╝ ██╗ ██║ ', + ' ╚═╝ ╚═╝ ╚═╝ \r\n\r\n', ]); expect(test.lines).toBe(2); expect(test.options).toEqual({ @@ -1134,20 +1150,21 @@ test(`Render - Add line height in raw mode`, () => { ' ╚═╝ ╚═╝ ╚═╝ \r\n\r\n' ); expect(test.array).toEqual([ - '\r\n\r\n ████████╗ ███████╗', - ' ╚══██╔══╝ ██╔════╝', - ' ██║ █████╗ ', - ' ██║ ██╔══╝ ', - ' ██║ ███████╗', - ' ╚═╝ ╚══════╝', - '', - '', - ' ██╗ ██╗ ████████╗', - ' ╚██╗██╔╝ ╚══██╔══╝', - ' ╚███╔╝ ██║ ', - ' ██╔██╗ ██║ ', - ' ██╔╝ ██╗ ██║ ', - ' ╚═╝ ╚═╝ ╚═╝ \r\n\r\n', + '\r\n\r\n' + + ' ████████╗ ███████╗', + ' ╚══██╔══╝ ██╔════╝', + ' ██║ █████╗ ', + ' ██║ ██╔══╝ ', + ' ██║ ███████╗', + ' ╚═╝ ╚══════╝', + '', + '', + ' ██╗ ██╗ ████████╗', + ' ╚██╗██╔╝ ╚══██╔══╝', + ' ╚███╔╝ ██║ ', + ' ██╔██╗ ██║ ', + ' ██╔╝ ██╗ ██║ ', + ' ╚═╝ ╚═╝ ╚═╝ \r\n\r\n', ]); expect(test.lines).toBe(2); expect(test.options).toEqual({ From 6b6386450ebf59c8caf3c96627c4d661645e3abe Mon Sep 17 00:00:00 2001 From: FriedlandAaron <3793162+FriedlandAaron@users.noreply.github.com> Date: Mon, 10 Jun 2024 09:55:10 +0300 Subject: [PATCH 11/12] change space to spaceless in nodejs implementation --- nodejs/src/Options.js | 8 ++--- nodejs/src/Render.js | 2 +- nodejs/src/index.js | 4 +-- nodejs/test/unit/Options.spec.js | 38 ++++++++++----------- nodejs/test/unit/Render.spec.js | 58 ++++++++++++++++---------------- 5 files changed, 55 insertions(+), 55 deletions(-) diff --git a/nodejs/src/Options.js b/nodejs/src/Options.js index d81a81f..ca0fd0e 100644 --- a/nodejs/src/Options.js +++ b/nodejs/src/Options.js @@ -33,7 +33,7 @@ const Options = { background: 'transparent', letterSpacing: 1, lineHeight: 1, - space: true, + spaceless: false, maxLength: 0, gradient: false, independentGradient: false, @@ -65,7 +65,7 @@ const Options = { * @param {string} options.backgroundColor - Alias for background * @param {number} options.letterSpacing - Space between letters, Default: set by selected font face * @param {number} options.lineHeight - Space between lines, Default: 1 - * @param {boolean} options.space - Output space before and after output, Default: true + * @param {boolean} options.spaceless - Don't output space before and after output, Default: false * @param {number} options.maxLength - Maximum amount of characters per line, Default width of console window * @param {(string|array|boolean)} options.gradient - Gradient color pair, Default: false * @param {boolean} options.independentGradient - A switch to calculate gradient per line or not @@ -84,7 +84,7 @@ const Options = { backgroundColor, letterSpacing, lineHeight, - space, + spaceless, maxLength, gradient, independentGradient, @@ -120,7 +120,7 @@ const Options = { ? 0 : this.store.lineHeight; - this.store.space = typeof space === 'boolean' ? space : this.store.space; + this.store.spaceless = typeof spaceless === 'boolean' ? spaceless : this.store.spaceless; this.store.maxLength = maxLength !== undefined ? maxLength : this.store.maxLength; diff --git a/nodejs/src/Render.js b/nodejs/src/Render.js index 8378cce..0639605 100644 --- a/nodejs/src/Render.js +++ b/nodejs/src/Render.js @@ -210,7 +210,7 @@ const Render = (input, SETTINGS = {}, debug = DEBUG.enabled, debuglevel = DEBUG. }); } - if (OPTIONS.space) { + if (!OPTIONS.spaceless) { // add space if (OPTIONS.align === 'top') { output[output.length - 1] = `${output[output.length - 1]}\n\n\n\n`; diff --git a/nodejs/src/index.js b/nodejs/src/index.js index f7fca5a..562add8 100644 --- a/nodejs/src/index.js +++ b/nodejs/src/index.js @@ -43,7 +43,7 @@ const Cli = (inputOptions = CLIOPTIONS, inputArgs = process.argv) => { ` background: "${args.background}",\n` + ` letterSpacing: ${args['letter-spacing']},\n` + ` lineHeight: ${args['line-height']},\n` + - ` space: ${!args.spaceless},\n` + + ` spaceless: ${args.spaceless},\n` + ` maxLength: ${args['max-length']},\n` + ` gradient: ${args.gradient},\n` + ` independentGradient: ${args['independent-gradient']},\n` + @@ -84,7 +84,7 @@ const Cli = (inputOptions = CLIOPTIONS, inputArgs = process.argv) => { background: args.background, letterSpacing: args['letter-spacing'], lineHeight: args['line-height'], - space: !args.spaceless, + spaceless: args.spaceless, maxLength: args['max-length'], gradient: args.gradient, independentGradient: args['independent-gradient'], diff --git a/nodejs/test/unit/Options.spec.js b/nodejs/test/unit/Options.spec.js index 7ac893b..35e92e2 100644 --- a/nodejs/test/unit/Options.spec.js +++ b/nodejs/test/unit/Options.spec.js @@ -14,7 +14,7 @@ test(`Options - Should return default options`, () => { background: 'transparent', letterSpacing: 1, lineHeight: 1, - space: true, + spaceless: false, maxLength: 0, gradient: false, independentGradient: false, @@ -50,7 +50,7 @@ test(`Options - Should be able to handle casing`, () => { background: 'bgCOLor2', letterSpacing: 1, lineHeight: 1, - space: true, + spaceless: false, maxLength: 0, gradient: false, independentGradient: false, @@ -80,7 +80,7 @@ test(`Options - Should be able to handle background and backgroundColor`, () => background: 'bgcoLOR3', letterSpacing: 1, lineHeight: 1, - space: true, + spaceless: false, maxLength: 0, gradient: false, independentGradient: false, @@ -103,7 +103,7 @@ test(`Options - Should merge font option with defaults`, () => { background: 'transparent', letterSpacing: 1, lineHeight: 1, - space: true, + spaceless: false, maxLength: 0, gradient: false, independentGradient: false, @@ -126,7 +126,7 @@ test(`Options - Should merge align option with defaults`, () => { background: 'transparent', letterSpacing: 1, lineHeight: 1, - space: true, + spaceless: false, maxLength: 0, gradient: false, independentGradient: false, @@ -149,7 +149,7 @@ test(`Options - Should merge colors option with defaults`, () => { background: 'transparent', letterSpacing: 1, lineHeight: 1, - space: true, + spaceless: false, maxLength: 0, gradient: false, independentGradient: false, @@ -172,7 +172,7 @@ test(`Options - Should merge background option with defaults`, () => { background: 'xxx', letterSpacing: 1, lineHeight: 1, - space: true, + spaceless: false, maxLength: 0, gradient: false, independentGradient: false, @@ -195,7 +195,7 @@ test(`Options - Should merge backgroundColor option with defaults`, () => { background: 'xxx', letterSpacing: 1, lineHeight: 1, - space: true, + spaceless: false, maxLength: 0, gradient: false, independentGradient: false, @@ -218,7 +218,7 @@ test(`Options - Should merge letterSpacing option with defaults`, () => { background: 'transparent', letterSpacing: 555, lineHeight: 1, - space: true, + spaceless: false, maxLength: 0, gradient: false, independentGradient: false, @@ -241,7 +241,7 @@ test(`Options - Should merge lineHeight option with defaults`, () => { background: 'transparent', letterSpacing: 1, lineHeight: 555, - space: true, + spaceless: false, maxLength: 0, gradient: false, independentGradient: false, @@ -254,7 +254,7 @@ test(`Options - Should merge lineHeight option with defaults`, () => { test(`Options - Should merge space option with defaults`, () => { Options.reset(); Options.set = { - space: false, + spaceless: true, }; expect(Options.get).toEqual({ @@ -264,7 +264,7 @@ test(`Options - Should merge space option with defaults`, () => { background: 'transparent', letterSpacing: 1, lineHeight: 1, - space: false, + spaceless: true, maxLength: 0, gradient: false, independentGradient: false, @@ -287,7 +287,7 @@ test(`Options - Should merge maxLength option with defaults`, () => { background: 'transparent', letterSpacing: 1, lineHeight: 1, - space: true, + spaceless: false, maxLength: 555, gradient: false, independentGradient: false, @@ -310,7 +310,7 @@ test(`Options - Should merge string-gradient option with defaults`, () => { background: 'transparent', letterSpacing: 1, lineHeight: 1, - space: true, + spaceless: false, maxLength: 0, gradient: ['red', 'green'], independentGradient: false, @@ -333,7 +333,7 @@ test(`Options - Should merge array-gradient option with defaults`, () => { background: 'transparent', letterSpacing: 1, lineHeight: 1, - space: true, + spaceless: false, maxLength: 0, gradient: ['red', 'green'], independentGradient: false, @@ -356,7 +356,7 @@ test(`Options - Should merge independentGradient option with defaults`, () => { background: 'transparent', letterSpacing: 1, lineHeight: 1, - space: true, + spaceless: false, maxLength: 0, gradient: false, independentGradient: true, @@ -379,7 +379,7 @@ test(`Options - Should merge independentGradient option with defaults`, () => { background: 'transparent', letterSpacing: 1, lineHeight: 1, - space: true, + spaceless: false, maxLength: 0, gradient: false, independentGradient: false, @@ -402,7 +402,7 @@ test(`Options - Should merge env option with defaults`, () => { background: 'transparent', letterSpacing: 1, lineHeight: 1, - space: true, + spaceless: false, maxLength: 0, gradient: false, independentGradient: false, @@ -425,7 +425,7 @@ test(`Options - Should merge raw-mode option with defaults`, () => { background: 'transparent', letterSpacing: 1, lineHeight: 1, - space: true, + spaceless: false, maxLength: 0, gradient: false, independentGradient: false, diff --git a/nodejs/test/unit/Render.spec.js b/nodejs/test/unit/Render.spec.js index 29432cb..6519394 100644 --- a/nodejs/test/unit/Render.spec.js +++ b/nodejs/test/unit/Render.spec.js @@ -17,7 +17,7 @@ beforeEach(() => { background: 'transparent', letterSpacing: 1, lineHeight: 1, - space: true, + spaceless: false, maxLength: 0, gradient: false, independentGradient: false, @@ -63,7 +63,7 @@ test(`Render - Render console string`, () => { background: 'transparent', letterSpacing: 0, lineHeight: 0, - space: true, + spaceless: false, maxLength: 0, gradient: false, independentGradient: false, @@ -95,7 +95,7 @@ test(`Render - Render console string with a color`, () => { background: 'transparent', letterSpacing: 0, lineHeight: 0, - space: true, + spaceless: false, maxLength: 0, gradient: false, independentGradient: false, @@ -132,7 +132,7 @@ test(`Render - Render console string with gradient will ignore color`, () => { background: 'transparent', letterSpacing: 0, lineHeight: 0, - space: true, + spaceless: false, maxLength: 0, gradient: ['red', 'blue'], independentGradient: false, @@ -196,7 +196,7 @@ test(`Render - Render block font`, () => { background: 'transparent', letterSpacing: 1, lineHeight: 1, - space: true, + spaceless: false, maxLength: 0, gradient: false, independentGradient: false, @@ -244,7 +244,7 @@ test(`Render - Render letter spacing`, () => { background: 'transparent', letterSpacing: 2, lineHeight: 1, - space: true, + spaceless: false, maxLength: 0, gradient: false, independentGradient: false, @@ -289,7 +289,7 @@ test(`Render - Render letter spacing`, () => { background: 'transparent', letterSpacing: 10, lineHeight: 1, - space: true, + spaceless: false, maxLength: 0, gradient: false, independentGradient: false, @@ -336,7 +336,7 @@ test(`Render - Center align block font`, () => { background: 'transparent', letterSpacing: 1, lineHeight: 1, - space: true, + spaceless: false, maxLength: 0, gradient: false, independentGradient: false, @@ -383,7 +383,7 @@ test(`Render - Right align block font`, () => { background: 'transparent', letterSpacing: 1, lineHeight: 1, - space: true, + spaceless: false, maxLength: 0, gradient: false, independentGradient: false, @@ -428,7 +428,7 @@ test(`Render - Top align block font`, () => { background: 'transparent', letterSpacing: 1, lineHeight: 1, - space: true, + spaceless: false, maxLength: 0, gradient: false, independentGradient: false, @@ -475,7 +475,7 @@ test(`Render - Bottom align block font`, () => { background: 'transparent', letterSpacing: 1, lineHeight: 1, - space: true, + spaceless: false, maxLength: 0, gradient: false, independentGradient: false, @@ -489,7 +489,7 @@ test(`Render - Ignore alignment top when combining it with space option`, () => const test = Render( 'text', { - space: false, + spaceless: true, align: 'top', }, false, @@ -521,7 +521,7 @@ test(`Render - Ignore alignment top when combining it with space option`, () => background: 'transparent', letterSpacing: 1, lineHeight: 1, - space: false, + spaceless: true, maxLength: 0, gradient: false, independentGradient: false, @@ -535,7 +535,7 @@ test(`Render - Ignore alignment bottom when combining it with space option`, () const test = Render( 'text', { - space: false, + spaceless: true, align: 'bottom', }, false, @@ -567,7 +567,7 @@ test(`Render - Ignore alignment bottom when combining it with space option`, () background: 'transparent', letterSpacing: 1, lineHeight: 1, - space: false, + spaceless: true, maxLength: 0, gradient: false, independentGradient: false, @@ -619,7 +619,7 @@ test(`Render - Break into new line on smaller viewports`, () => { background: 'transparent', letterSpacing: 1, lineHeight: 1, - space: true, + spaceless: false, maxLength: 0, gradient: false, independentGradient: false, @@ -658,7 +658,7 @@ test(`Render - Fallback to huge viewport in browser environments`, () => { background: 'transparent', letterSpacing: 1, lineHeight: 1, - space: true, + spaceless: false, maxLength: 0, gradient: false, independentGradient: false, @@ -710,7 +710,7 @@ test(`Render - Respect maxLength over viewport in browser env`, () => { background: 'transparent', letterSpacing: 1, lineHeight: 1, - space: true, + spaceless: false, maxLength: 20, gradient: false, independentGradient: false, @@ -749,7 +749,7 @@ test(`Render - Add background color in browser environments`, () => { background: 'black', letterSpacing: 1, lineHeight: 1, - space: true, + spaceless: false, maxLength: 0, gradient: false, independentGradient: false, @@ -801,7 +801,7 @@ test(`Render - Add line break`, () => { background: 'transparent', letterSpacing: 1, lineHeight: 1, - space: true, + spaceless: false, maxLength: 0, gradient: false, independentGradient: false, @@ -854,7 +854,7 @@ test(`Render - Add line height`, () => { background: 'transparent', letterSpacing: 1, lineHeight: 2, - space: true, + spaceless: false, maxLength: 0, gradient: false, independentGradient: false, @@ -893,7 +893,7 @@ test(`Render - Non supported characters are ignored`, () => { background: 'transparent', letterSpacing: 1, lineHeight: 1, - space: true, + spaceless: false, maxLength: 0, gradient: false, independentGradient: false, @@ -904,7 +904,7 @@ test(`Render - Non supported characters are ignored`, () => { }); test(`Render - Remove space`, () => { - const test = Render('text', { space: false }, false, 1, { width: 100, height: 10 }); + const test = Render('text', { spaceless: true }, false, 1, { width: 100, height: 10 }); expect(test.string).toBe( ' ████████╗ ███████╗ ██╗ ██╗ ████████╗\n' + @@ -930,7 +930,7 @@ test(`Render - Remove space`, () => { background: 'transparent', letterSpacing: 1, lineHeight: 1, - space: false, + spaceless: true, maxLength: 0, gradient: false, independentGradient: false, @@ -971,7 +971,7 @@ test(`Render - Add background color`, () => { background: 'red', letterSpacing: 1, lineHeight: 1, - space: true, + spaceless: false, maxLength: 0, gradient: false, independentGradient: false, @@ -1017,7 +1017,7 @@ test(`Render - Render console string in raw mode`, () => { background: 'transparent', letterSpacing: 0, lineHeight: 0, - space: true, + spaceless: false, maxLength: 0, gradient: false, independentGradient: false, @@ -1069,7 +1069,7 @@ test(`Render - Break into new line on smaller viewports in raw mode`, () => { background: 'transparent', letterSpacing: 1, lineHeight: 1, - space: true, + spaceless: false, maxLength: 0, gradient: false, independentGradient: false, @@ -1121,7 +1121,7 @@ test(`Render - Add line break in raw mode`, () => { background: 'transparent', letterSpacing: 1, lineHeight: 1, - space: true, + spaceless: false, maxLength: 0, gradient: false, independentGradient: false, @@ -1174,7 +1174,7 @@ test(`Render - Add line height in raw mode`, () => { background: 'transparent', letterSpacing: 1, lineHeight: 2, - space: true, + spaceless: false, maxLength: 0, gradient: false, independentGradient: false, From 484fc0d346eae016bacd0adff546570970d214fd Mon Sep 17 00:00:00 2001 From: FriedlandAaron <3793162+FriedlandAaron@users.noreply.github.com> Date: Wed, 12 Jun 2024 18:34:51 +0300 Subject: [PATCH 12/12] handle line break at start of render function --- nodejs/src/Render.js | 30 ++++++++++++------------------ rust/src/render.rs | 29 ++++++++++++++--------------- 2 files changed, 26 insertions(+), 33 deletions(-) diff --git a/nodejs/src/Render.js b/nodejs/src/Render.js index 0639605..b8457e5 100644 --- a/nodejs/src/Render.js +++ b/nodejs/src/Render.js @@ -130,6 +130,12 @@ const Render = (input, SETTINGS = {}, debug = DEBUG.enabled, debuglevel = DEBUG. let lineLength = CharLength(FONTFACE.buffer, FONTFACE.lines, OPTIONS); // count each output character per line and start with the buffer let maxChars = 0; // count each character we print for maxLength option + // handle raw mode + let line_break = '\n'; + if (OPTIONS.env === 'node' && OPTIONS.rawMode === true) { + line_break = '\r\n'; + } + output = AddLine([], FONTFACE.lines, FONTFACE.buffer, OPTIONS.lineHeight); // create first lines with buffer lines++; @@ -213,23 +219,23 @@ const Render = (input, SETTINGS = {}, debug = DEBUG.enabled, debuglevel = DEBUG. if (!OPTIONS.spaceless) { // add space if (OPTIONS.align === 'top') { - output[output.length - 1] = `${output[output.length - 1]}\n\n\n\n`; + output[output.length - 1] = `${output[output.length - 1]}${line_break}${line_break}${line_break}${line_break}`; } else if (OPTIONS.align === 'bottom') { - output[0] = `\n\n\n\n${output[0]}`; + output[0] = `${line_break}${line_break}${line_break}${line_break}${output[0]}`; } else { - output[0] = `\n\n${output[0]}`; - output[output.length - 1] = `${output[output.length - 1]}\n\n`; + output[0] = `${line_break}${line_break}${output[0]}`; + output[output.length - 1] = `${output[output.length - 1]}${line_break}${line_break}`; } } if (OPTIONS.background !== 'transparent' && OPTIONS.env === 'node') { const { open: openNew, close: closeNew } = Color(OPTIONS.background, true); - output[0] = `${openNew}\n${output[0]}`; + output[0] = `${openNew}${line_break}${output[0]}`; output[output.length - 1] = `${output[output.length - 1]}${closeNew}`; } - let write = output.join(OPTIONS.env === 'node' ? `\n` : '
\n'); + let write = output.join(OPTIONS.env === 'node' ? `${line_break}` : `
${line_break}`); if (OPTIONS.env === 'browser') { const { open: bgColor } = Color(OPTIONS.background, true); @@ -242,18 +248,6 @@ const Render = (input, SETTINGS = {}, debug = DEBUG.enabled, debuglevel = DEBUG. ``; } - // handle raw mode - if (OPTIONS.env === 'node') { - if (OPTIONS.rawMode === true) { - const re = /\n/g; - const newline = '\r\n'; - write = write.replace(re, newline); - output = output.map((x) => { - return x.replace(re, newline); - }); - } - } - return { string: write, array: output, diff --git a/rust/src/render.rs b/rust/src/render.rs index 63a6f04..1bc0a66 100644 --- a/rust/src/render.rs +++ b/rust/src/render.rs @@ -122,6 +122,13 @@ pub fn render(options: Options) -> RenderedString { &mut std::io::stdout(), ); + // set line break character based on env + let line_break = if options.env == Env::Cli && options.raw_mode { + "\r\n" + } else { + "\n" + }; + add_line(&mut output, font.lines, &options); lines += 1; @@ -196,12 +203,12 @@ pub fn render(options: Options) -> RenderedString { if !options.spaceless { match options.align { - Align::Top => output.push(String::from("\n\n\n")), - Align::Bottom => output[0] = String::from("\n\n\n\n") + &output[0], + Align::Top => output.push(format!("{line_break}{line_break}{line_break}")), + Align::Bottom => output[0] = format!("{line_break}{line_break}{line_break}{line_break}") + &output[0], Align::Left | Align::Center | Align::Right => { - output[0] = String::from("\n\n") + &output[0]; + output[0] = format!("{line_break}{line_break}") + &output[0]; let last_index = output.len() - 1; - output[last_index] = format!("{}\n\n", output[last_index]); + output[last_index] = format!("{}{line_break}{line_break}", output[last_index]); } } d("render() added space", 1, Dt::Log, &options, &mut std::io::stdout()); @@ -209,15 +216,15 @@ pub fn render(options: Options) -> RenderedString { if options.background != BgColors::Transparent && options.env == Env::Cli { let (open, close) = get_background_color(&options.background); - output[0] = format!("{}\n", open) + &output[0]; + output[0] = format!("{}{line_break}", open) + &output[0]; let last_index = output.len() - 1; output[last_index] = format!("{}{}", output[last_index], close); d("render() added background", 1, Dt::Log, &options, &mut std::io::stdout()); } let mut text = match options.env { - Env::Cli => output.join("\n"), - Env::Browser => output.join("
\n"), + Env::Cli => output.join(line_break), + Env::Browser => output.join(format!("
{line_break}").as_str()), }; if options.env == Env::Browser { @@ -231,14 +238,6 @@ pub fn render(options: Options) -> RenderedString { d("render() formatted for Env::Browser", 1, Dt::Log, &options, &mut std::io::stdout()); } - // Handle raw mode only in Cli env - if options.env == Env::Cli && options.raw_mode { - for v in output.iter_mut() { - *v = v.replace('\n', "\r\n"); - } - text = text.replace('\n', "\r\n"); - } - d(&format!("render() final output string: {:?}", text), 1, Dt::Log, &options, &mut std::io::stdout()); RenderedString {