npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

beautiful_terminal

v1.7.6

Published

this package is intended for people who develop applications in the terminal that would necessarily need to improve their appearance. if you are one of them you will not regret it! ;)

Downloads

40

Readme

beautiful_terminal package

The beautiful_terminal package is designed to enhance (color/modify) text in your command line application that does not support a graphical user interface (GUI).

Advantages =>

  • You can use any version of node js to use this package.
  • using this package is not difficult.
  • The syntax is not difficult.
  • And almost all terminals (especially modern ones) support it.
  • This package supports absolutely all colors.

installation =>

npm install beautiful_terminal

license

ISC

how to write code correctly =>

You can write the code in 2 ways

  1. Either you choose specific functions that you will use =>
const { _0m } = require("beautiful_terminal");
console.log(_0m);
  1. Or you define a variable/constant and use it to select specific functions =>
const bt = require("beautiful_terminal");
console.log(bt._0m);

I'll use the first method in the examples, but you can do it however you want.

colors =>

  • If you want to remove all decorations/colors from the text, use this => _0m

  • If you want to colorize the text normally, simply select the palette.<color>[0]. But if you want to colorize the font background, you can do the same, but in the array, it won't be 0, it will be 1. The Palette object contains several basic colors such as black, white, red, green, blue, yellow, orange, pink, cyan and gray.

  • However, if you're not satisfied with selecting from the basic color palette, you can create your own colors using the rgb(<r>,<g>,<b>) function or use the hexcolor("#<hex>") function. If you want to apply it to the background as well, just use rgb(<r>,<g>,<b>,<true or 1>), and the same applies to hexcolor!.

Here is a 2 simple examples of how to use colors:

const { palette, rgb, hexcolor, _0m } = require("beautiful_terminal");
console.log(palette.gray[0] + "Hello " + rgb(255, 235, 10) + "Java" + hexcolor("#000000") + palette.yellow[1] + "Script" + _0m + "!");

Here is second example:

const { palette, rgb, hexcolor, _0m } = require("beautiful_terminal");

const greenColor = rgb(43, 255, 5);
const redColor = hexcolor("#ff0000");
console.log(greenColor);
async function main(){
    console.log("Hecking started...");
    for(let i=0;i<=100;i+=10){  
        await new Promise((resolve) => { 
            setTimeout(resolve,1000);
        });
        console.log("hacking FBI "+ redColor + i + "%" + greenColor);
        if(i === 100){
            console.log("hecking successful");
        }
    }
}main();
  • If you only needed to remove the background from the text and keep its color, you can't use _0m (you can, but you'd have to re-enable the color and other features, which would make your syntax much longer), because it remove everything, and that's exactly why why you have a remove object available to resey exactly what you need. For example, if you only need to remove the background color, you can do it as remove.background. And remove.color when removing the text color.

here is an example of how to use remove:

const { _0m, palette, remove } = require("beautiful_terminal");

const redColor = palette.red[0];
const blueBgColor = palette.blue[1];

console.log(_0m + blueBgColor + redColor + "Hello" + remove.background + " JavaScript" + _0m);

decorations =>

  • Even if the colors are nice and are enough to decorate your application, sometimes it is not the same and you would need to decorate your text even more interestingly. For this purpose, I have created an object called decor which contains the following features such as bold font bold, italic font italic, underlined font underline, strikethrough font strikethrough, translucent font (dim) dim, baking contrast inverse and text hiding hidden.

  • This object behaves similarly to the colors decor.underline[0] BUT with the difference that the 2nd element in the array serves to cancel the given decoration.

Here is a 2 simple examples of how to use decorations:

you can combine it

const { _0m, decor, palette } = require("beautiful_terminal");

console.log(_0m + palette.red[0] + "Hello " + decor.bold[0] + "Java" + decor.bold[1] + decor.strikethrough[0] + "Script" + _0m + "!");
console.log(decor.bold[0] + decor.italics[0] + decor.underline[0] + "Hello JavaScript!" + _0m);

Here is second example:

const { _0m, decor, palette } = require("beautiful_terminal");
const readline = require("readline");

const redColor = palette.red[0];
const yellowColor = palette.yellow[0];
const pinkColor = palette.pink[0];
const greenColor = palette.green[0]
const ulFont = decor.underline[0];
const rmulFont = decor.underline[1];
const italicsFont = decor.italics[0];

const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
});

rl.question(`do you like ${yellowColor}${ulFont}bananas${_0m}: ${greenColor}${italicsFont}`,(data) => {
    if(data === "yes"){
        console.log(_0m + "I " + pinkColor +"love " + redColor + "<3 " + _0m + "you!");
    } else {
        console.log(_0m + redColor + ulFont + "ERROR" + rmulFont + " someting wrong :(" + _0m);
    }
    rl.close();
});
  • If you need to remove all decorations at once but at the same time you need to keep the color/background of the text, you can use the reset object again, reset.decor. With this object, you don't have to remove decorations one by one (dim is an exception).

here is an example of how to use remove with dekor:

const { _0m, remove, palette, decor } = require("beautiful_terminal");

const yellowColor = palette.yellow[0];
const ulFont = decor.underline[0];
const italicsFont = decor.italics[0];
const rmAllDecor = remove.decor;

console.log(_0m + yellowColor + ulFont + italicsFont + "Hello" + rmAllDecor + " JavaScript" + _0m);

gradient =>

  • Ok, you can adjust the color of the text, but would you like more?? No problem, the gradient function can improve your text even more!

  • This is what gradient(<color>,<color>,"your text",<true or 1 for background>); looks like. As you can see, 2 colors are specified. and at the end text is entered to perform the transition. when using the palette object or other functions, it doesn't matter whether you use the font color palette.red[0] or the background color palette.red[1]. Because it is specified as the last CLGUI parameter.

  • If you want the function to be applied to the background as well, just add one argument at the end (as with the rgb or hexcolor function true or 1) as you can see in the example.

Here is a simple example of how to use gradient:

const { _0m, rgb, hexcolor, gradient, palette } = require("beautiful_terminal");

console.log(gradient(hexcolor("#0516ff"),rgb(5, 255, 22),"Hello JavaScript!"));

console.log(gradient(palette.red[1],palette.black[0],"Hello JavaScript!"));

const pinkToYellow = gradient(rgb(255, 255, 0),hexcolor("#ff00ee"),"THIS FUNCTION IS AMAZING!!!",true);

console.log("How the gradient function works =>" + palette.white[0] + " Hi how are you. " + pinkToYellow + _0m);

command line GUI =>

  • This package should mainly be for improving the command line interface (CLI) and I would like to create something like a command line GUI as part of this package. It will not be a full-fledged GUI, but rather a universal and rather limited one. It's not finished yet, but I'd like to push it further and expand the capabilities of this function.

how to use it =>

  • It works in the that you call a function called CLGUI() (command line graphic user interface) and write all the parameters you need into it =>
CLGUI(
  ["<text>","<text>","<text>",<...],
  <color or decoration>,
  "<text separator>",
  "<button to move left>",
  "<button to move right>",
  "<button with which you can interact with the text>",
  "<button to move to the original position>",
  [<function for the element in the first array>,<...]);
  • for example, if you don't want to be able to move left, you enter null or "" in the parameter for the button to use for left movement.

here is an example to use:

const { CLGUI, decor, palette, hexcolor, _0m } = require("beautiful_terminal");
const fs = require("fs");
const os = require("os");

function timeInfo(){
    const currentTime = new Date();
    const hours = currentTime.getHours();
    const minutes = currentTime.getMinutes();
    const seconds = currentTime.getSeconds();
    console.log(`time is: ${hours}:${minutes}:${seconds}`);
}

function OSinfo(){
    console.log("os: " + hexcolor("#05ff7e") + os.platform() + _0m);  
    console.log("version: " + hexcolor("0000ff") + os.release() + _0m);
    console.log("CPU architecture: " + hexcolor("ff0000") + os.arch() + _0m);
}

function exit(){
    console.log("Press ENTER for end.")
}

CLGUI(
  ["info about time","info about os","exit","click here"],
  decor.underline[0] + hexcolor("#ff00cc"),
  "|",
  "a",
  "d",
  " ",
  "r",
  [timeInfo, OSinfo, exit]);
  • From version 1.6.5 you can also put in the parameters of the CLGUI function functions that must be waited for.

Here is an example of a useful application:

const { CLGUI, decor, palette, hexcolor, _0m } = require("beautiful_terminal");
const readline = require("readline");
const fs = require("fs");
const path = require("path");

// input function
function question(prompt) {
  const rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout
  });

  return new Promise((resolve, reject) => {
    rl.question(prompt, (answer) => {
      rl.close();
      resolve(answer);
    });
  });
}

// colors
const mainColor = hexcolor("#84ff00");
const errColor = palette.red[0] + decor.bold[0];

// show path function
let currentDirectory = process.cwd();
function showPath(){
  console.log("Current Directory: " + mainColor + currentDirectory + _0m);
}

// read directory function
function dirRead(){
  return new Promise((resolve, reject) => {
    fs.readdir(currentDirectory,(err,data)=>{
      if(err){
      console.log(errColor + "ERROR something wrong!" + _0m);
        console.log(err);
        reject();
      } else {
        console.log(mainColor + data.join(_0m + ", " + mainColor)); 
        resolve();
      }
    });
  });
}

// create file function
async function createFile(){
  await dirRead();
  const name = await question(_0m + "Enter a file name: " + mainColor);
  fs.writeFile(currentDirectory + "/" + name,"",(err)=>{
     if(err){
         console.log(errColor + "ERROR something wrong!" + _0m);
         console.log(err);
         
     } else {
         console.log(_0m + "file is created!");         
     }
});   
}

//delete file function
async function deleteFile(){
  await dirRead();
  const name = await question(_0m + "Enter a file name: " + mainColor);
  fs.unlink(currentDirectory + "/" + name,(err)=>{
   if(err){
       console.log(errColor + "ERROR something wrong!" + _0m);
       console.log(err);
         
   } else {
     console.log(_0m + "file is delete!");         
   }
  });    
}

// cd function
async function changeDir() { 
  console.log("Current Directory: " + mainColor + currentDirectory + "/" + _0m);
  const input = await question(_0m + "Enter a directory name: " + mainColor);
  if (input === "..") {
    currentDirectory = path.resolve(currentDirectory, "..");
  } else {
   currentDirectory = path.resolve(currentDirectory, input);      
  }
  console.log(_0m + "Current Directory: " + mainColor + currentDirectory + _0m);
}

//read file function
async function fileRead(){
  await dirRead();
  const name = await question(_0m + "Enter a file name: " + mainColor); 
  console.log(_0m + "-------------------------" + hexcolor("#ea73ff"));
  await new Promise((resolve) => {
    const readStream = fs.createReadStream(currentDirectory + "/" + name,"utf8");
  
    readStream.on("data",(chunk)=>{
      console.log(chunk);
      resolve();
    });
  });
  console.log(_0m + "-------------------------");
}

//"main" CLGUI function
CLGUI(
  [" show path "," create file "," delete file "," change path "," read file "],
  decor.inverse[0],
  "",
  "a",
  "d",
  " ",
  "r",
  [showPath, createFile, deleteFile, changeDir, fileRead]);
    
  • try to create functions to create and delete folders yourself