From 121356e7da4df3d9c4698f18c67fb80bc7a23b87 Mon Sep 17 00:00:00 2001 From: Sett Sarverott Date: Tue, 9 Jan 2024 09:08:36 +0100 Subject: [PATCH] making 1.4.0 even better, more optimal and fancier -rename of random collection -terminal testrun is aestetic as hell -feacherfull overload... UP NEXT: removing comments and other codecleaning --- _testrun-cli.js | 70 +++++++++++++---------- package-lock.json | 4 +- package.json | 2 +- resources/text/repos-info.ptxml | 2 + src/_index.js | 2 +- src/{random-string.js => random-stuff.js} | 9 ++- src/terminal-tricks.js | 45 ++++++++++++++- 7 files changed, 96 insertions(+), 38 deletions(-) rename src/{random-string.js => random-stuff.js} (92%) diff --git a/_testrun-cli.js b/_testrun-cli.js index 66294ee..b3934e2 100644 --- a/_testrun-cli.js +++ b/_testrun-cli.js @@ -15,6 +15,10 @@ const STANDARD_HEADER=CLI.colorize( CLI.textart("header-logo"), [CLI.reverse, CLI.reset] ); +const COLORFULL_HEADER=CLI.paintIt(CLI.FRONT.black)+CLI.rainbowize( + CLI.textart("header-logo"), + "BACK" +); //const REPOS_INFO=CLI.lines( // "", @@ -76,7 +80,7 @@ function NEW_PROMPT(){ }); Object.defineProperty(TOOLBOX, "help", { get(){ - console.log("\t\t # # # ABOUT CARNIVAL TOOLBOX # # #"); + console.log(`\t\t ${CLI.rainbowize("# # #")} ABOUT CARNIVAL TOOLBOX ${CLI.rainbowize("# # #")}`); console.log("\t For detailed documentation, and usage guides go to official website of project."); console.log(); console.log(REPOS_INFO); @@ -119,7 +123,7 @@ function NEW_PROMPT(){ console.log(); console.log(); - CLI.colorPrint("--------------", CLI.reverse); + console.log(CLI.rainbowize("--------------","BACK")); console.log(); CLI.colorPrint( @@ -140,7 +144,7 @@ function NEW_PROMPT(){ CLI.FRONT.yellow ); console.log(); - CLI.colorPrint("--------------", CLI.reverse); + console.log(CLI.rainbowize("--------------","BACK")); console.log(); //var descriptor={ // lvl:"library", @@ -187,7 +191,28 @@ function NEW_PROMPT(){ return readline.createInterface({ input: process.stdin, output: process.stdout, - prompt: "|~\x1b[44m\x1b[31m ▓▒░ \x1b[0m \x1b[7m CT :: Sandbox lab \x1b[0m \x1b[44m\x1b[31m ░▒▓ \x1b[0m~>" + prompt: ( + `: ${ + CLI.colorize('@~~~' , [CLI.FRONT.gray,CLI.reset]) + } ${ + CLI.colorize( + CLI.colorize('▓▒░', [CLI.FRONT.red,CLI.reset]), + [CLI.blink,CLI.reset] + ) + } CarnivalToolbox ${ + CLI.colorize( + CLI.colorize('::', [CLI.FRONT.green,CLI.reset]), + [CLI.blink,CLI.reset] + ) + } SandboxLab ${ + CLI.colorize( + CLI.colorize('░▒▓', [CLI.FRONT.blue,CLI.reset]), + [CLI.blink,CLI.reset] + ) + } ${ + CLI.colorize('~~~>' , [CLI.FRONT.gray,CLI.reset]) + } ` + ) }).on( 'line', ON_PROMPT_LINE @@ -197,22 +222,17 @@ function NEW_PROMPT(){ ); } function ON_PROMPT_CLOSED(){ - console.log(" ... "); - var textTMP=" user-friendly escape sequence of programm... "; - var outputTMP=`\x1b[1mEXECUTING `; - for(var i=0;i + NPM: https://www.npmjs.com/package/carnival-toolbox GitHub: https://github.com/Sarverott/carnival-toolbox ~~~ Sett Sarverott @ 2024 ~~~ ~~~ published on terms of MIT license ~~~ + diff --git a/src/_index.js b/src/_index.js index 963ebc7..0c38506 100644 --- a/src/_index.js +++ b/src/_index.js @@ -14,7 +14,7 @@ const CARNIVAL=new LibraryGuard(); CARNIVAL.load="case-gadgets"; CARNIVAL.load="json-gadgets"; -CARNIVAL.load='random-string'; +CARNIVAL.load='random-stuff'; CARNIVAL.load='cool-math-things'; CARNIVAL.load='custom-cryptography'; CARNIVAL.load='terminal-tricks'; diff --git a/src/random-string.js b/src/random-stuff.js similarity index 92% rename from src/random-string.js rename to src/random-stuff.js index 1ff9f12..7ff4484 100644 --- a/src/random-string.js +++ b/src/random-stuff.js @@ -67,4 +67,11 @@ function randStr(...args){ v4:randomString_V4 }[versionChoice](...args); } -module.exports={randStr} + +function arrayLottery(arr){ + return arr[Math.floor(Math.random()*arr.length)]; +} + + + +module.exports={randStr, arrayLottery} diff --git a/src/terminal-tricks.js b/src/terminal-tricks.js index 673ea0b..3c64b81 100644 --- a/src/terminal-tricks.js +++ b/src/terminal-tricks.js @@ -2,7 +2,9 @@ const readline = require('readline'); const repl = require('repl'); const fs = require('fs'); const path = require('path'); -const xmlToys = require("./xml-toys.js") + +const {arrayLottery} = require('./random-stuff.js'); +const {xmlEscCodesReplace, xmlTagsReplace} = require("./xml-toys.js"); class CliTool{ constructor(setup={textarts:"./"}){ @@ -37,6 +39,40 @@ class CliTool{ colorize(data, codes=[7,0]){ return `\x1b[${codes[0].toString()}m${data}\x1b[${codes[1].toString()}m`; } + paintIt(...codes){ + return codes.map( + (colorcode)=>`\x1b[${colorcode}m` + ).join(""); + } + rainbowize( + data, + mode="FRONT", + opts={ + //useColors:null, + //banCollors:["black", "gray", "white"] + } + ){ + var result = ``; + var banColors = ["black", "gray", "white"]; + if(opts.hasOwnProperty("banColors")) banColors = opts.banColors; + var useColors = Object.keys(colorCodes.FACTORS).filter( + (colorname)=> !banColors.includes(colorname) + ); + if(opts.hasOwnProperty("useColors")) useColors = opts.useColors; + for(var i=0; i