Skip to content

Commit

Permalink
making 1.4.0 even better, more optimal and fancier
Browse files Browse the repository at this point in the history
-rename of random collection
-terminal testrun is aestetic as hell
-feacherfull overload...
UP NEXT: removing comments and other codecleaning
  • Loading branch information
Sarverott committed Jan 9, 2024
1 parent 4e5c364 commit 121356e
Show file tree
Hide file tree
Showing 7 changed files with 96 additions and 38 deletions.
70 changes: 40 additions & 30 deletions _testrun-cli.js
Original file line number Diff line number Diff line change
Expand Up @@ -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(
// "",
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -119,7 +123,7 @@ function NEW_PROMPT(){
console.log();

console.log();
CLI.colorPrint("--------------", CLI.reverse);
console.log(CLI.rainbowize("--------------","BACK"));
console.log();

CLI.colorPrint(
Expand All @@ -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",
Expand Down Expand Up @@ -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
Expand All @@ -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<textTMP.length;i++){
outputTMP+=`\x1b[3${i%6+1}m`;
outputTMP+=textTMP.charAt(i);
}
outputTMP+='\x1b[0m';
console.log(outputTMP);
console.log("\n ... \n");
console.log(`\x1b[1mEXECUTING ${CLI.rainbowize("user-friendly escape sequence of programm...")} `);
console.log(REPOS_INFO);
console.log(STANDARD_HEADER);
console.log('\tThank you for testing/using/depending/requiring!');
console.log("\t\t\tBYE!");
console.log(COLORFULL_HEADER);
console.log('\n\tThank you for testing/using/depending/requiring!');
console.log("\t\t\tBYE!\n");
process.exit(0);
}
function ON_PROMPT_LINE(line){
CLI.ring();
//process.stdout.write(CLI.paintIt(CLI.reset));
//line=line.split(" ")
//switch(){
// case 'hello':
Expand All @@ -237,29 +257,19 @@ function ON_PROMPT_LINE(line){
//}
//line


const inputScript = new vm.Script(line);
vm.createContext(TOOLBOX);
//for (let i = 0; i < 10; ++i) {var textTMP=" user-friendly escape sequence of programm... ";
//textTMP=" . . . ";
var outputTMP=' ';
for(var i=0;i<5;i++){
outputTMP+=`\x1b[3${Math.floor(Math.random()*5%6+1)}m`;
outputTMP+='- ';
}
console.log(outputTMP+'\x1b[0m');
//console.log("\x1b[2m . . . \x1b[0m");
console.log(CLI.rainbowize(" - - - - - "));

try{
console.log(inputScript.runInContext(TOOLBOX));
}catch(e){
console.log(e);
}
outputTMP=' ';
for(var i=0;i<5;i++){
outputTMP+=`\x1b[3${Math.floor(Math.random()*6%6+1)}m`;
outputTMP+='- ';
}
console.log(outputTMP+'\x1b[0m');

console.log(CLI.rainbowize(" - - - - - "));


//}
Expand Down
4 changes: 2 additions & 2 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "carnival-toolbox",
"version": "1.4.0",
"version": "1.4.1",
"description": "a collection of all kind of scripts, codes and tools with universal appliance - this toolkit should fits great to your disguises, outfits and attires",
"main": "_index.js",
"scripts": {
Expand Down
2 changes: 2 additions & 0 deletions resources/text/repos-info.ptxml
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
<pretty-terminal>

&#9; <b-red>NPM:</b-red> <f-red>https://www.npmjs.com/package/carnival-toolbox</f-red>
&#9; <b-cyan>GitHub:</b-cyan> <f-cyan>https://github.com/Sarverott/carnival-toolbox</f-cyan>

&#9;&#9;&#9; <dim>~~~ Sett Sarverott @ 2024 ~~~</dim>
&#9;&#9; <dim>~~~ published on terms of MIT license ~~~</dim>

</pretty-terminal>
2 changes: 1 addition & 1 deletion src/_index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down
9 changes: 8 additions & 1 deletion src/random-string.js → src/random-stuff.js
Original file line number Diff line number Diff line change
Expand Up @@ -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}
45 changes: 42 additions & 3 deletions src/terminal-tricks.js
Original file line number Diff line number Diff line change
Expand Up @@ -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:"./"}){
Expand Down Expand Up @@ -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<data.length; i++){
if(
["\n","\r"].includes(data.charAt(i))
){
result += `\x1b[${colorCodes[mode].black}m`;
//result += `\x1b[${colorCodes.reset}m`;
}else{
result += `\x1b[${colorCodes[mode][arrayLottery(useColors)]}m`;
}
result += data.charAt(i);
}
result += '\x1b[0m';
return result;
}
lines(...lines){
return lines.join("\n");
}
Expand Down Expand Up @@ -64,15 +100,18 @@ class CliTool{
}
return result;
}
ring(i=1){
process.stdout.write(this.BELL(i));
}
loadPTXML(name){
var fileContent=fs.readFileSync(
path.join(
this.ptxmls,
`${name}.ptxml`
)
).toString("utf8").trim();
fileContent=xmlToys.xmlEscCodesReplace(fileContent);
fileContent=xmlToys.xmlTagsReplace(fileContent, CliTool.PTXML_REPLACE_COLORS);
fileContent=xmlEscCodesReplace(fileContent);
fileContent=xmlTagsReplace(fileContent, CliTool.PTXML_REPLACE_COLORS);
return fileContent;
}
}
Expand Down

0 comments on commit 121356e

Please sign in to comment.