Colorful terminal control, amazing inputs and Random features!
npm install colorside@latest
import ColorSide from 'colorside';
const cs: any = new ColorSide("en"); // language if instructions: 'ru' OR 'en'
cs.use(/* class */); // Using package classes
Note
Если вы из России, по возможности купите мне поесть :)
Карта: 5599002097457313
npm run compile
import ColorSide from 'colorside';
const cs: any = new ColorSide("ru");
cs.use(cs.console) // Using class cs.console
cs.console.log("My first log!"); // like console.log
import ColorSide from 'colorside';
const cs: any = new ColorSide("ru");
cs.use(cs.console);
cs.console.log("It's a basic log"); // Basic log like console.log
cs.console.warn("Warn??"); // Warn message with yellow text foreground
cs.console.error("Error!"); // Error message with red text foreground
cs.console.fatal("FATAL ERROR!!!") // Fatal error message with red text background and black foreground
- cs.fg.color() - foreground color
- cs.fg.bright.color() - foreground bright color
- cs.bg.color() - background color
- cs.bg.bright.color() - background bright color
- cs.format.style() - bold / underlined text
import ColorSide from 'colorside';
const cs: any = new ColorSide("ru");
cs.use(cs.console);
cs.console.log(cs.fg.bright.green(cs.format.bold("Green bright bold text")));
// likewise cs.format.underlined
- colorside@^1.2.3
import { ANSI256 } from 'colorside/ansi256';
ANSI256.get.fg("#hex"); // returns only ansi256-color code. need to ANSI.reset at the end
ANSI256.get.bg("#hex"); // like get.fg, but background
ANSI256.replace.fg("#hex", "Some Text"); // returns a fg color wrapper only for text from the 2nd argument
ANSI256.replace.bg("#hex", "Some Text"); // like replace.fg, but background
import ColorSide from 'colorside';
const cs: any = new ColorSide("ru");
cs.use(cs.console);
cs.console.clear(); // clear screen
The application does not close spontaneously
import ColorSide from 'colorside';
const cs: any = new ColorSide("ru");
cs.use(cs.console);
cs.console.freeze();
cs.console.warn("Only Ctrl-C will kill app");
// Later, you can unfreeze the process automatically
// cs.console.unfreeze();
Like setTimeout, but sync
import ColorSide from 'colorside';
const cs: any = new ColorSide("ru");
cs.use(cs.console);
cs.console.log("Downloading...");
cs.console.sleepSync(1000); // 1s
cs.console.log("Success!");
Input prompts using inquirer API
import ColorSide from 'colorside';
const cs: any = new ColorSide("ru");
cs.use(cs.console);
cs.use(cs.input); // Using class cs.input
async function main(): Promise<void> {
const name = await cs.input.readline("Enter your name: "); // Basic input and nothing else
cs.console.log(`Your name: ${cs.fg.bright.magenta(name)}`);
}
main();
import ColorSide, { ANSI } from 'colorside';
// { ANSI } import required!
const cs: any = new ColorSide("ru");
cs.use(cs.console);
cs.use(cs.input);
async function main(): Promise<void> {
const name = await cs.input.readtext({
message: /*(string)*/ "Enter your name:", // <- [No space after ':']
/* optional params */
// messageColor: /*(string)*/ ANSI.fg.green, - message color
inputColor: /*(string)*/ ANSI.fg.bright.cyan, // input color
// prefix: /*(null | string)*/ '>', - custom prefix. null = prefix disabled
// finishPrefix: /*(boolean)*/ true, - show final prefix when input readed
default: /*(string)*/ "John", // default name
validate: (val) => (val.toLowerCase() !== "adolf") || "Sorry, we don't support such names" // input validation
});
cs.console.log(`Your name: ${cs.fg.bright.magenta(name)}`);
}
main();
import ColorSide, { ANSI } from 'colorside';
// { ANSI } import required!
const cs: any = new ColorSide("ru");
cs.use(cs.console);
cs.use(cs.input);
async function main(): Promise<void> {
const name = await cs.input.readnumber({
message: /*(string)*/ "Enter your name:", // <- [No space after ':']
/* optional params */
// messageColor: /*(string)*/ ANSI.fg.green, - message color
inputColor: /*(string)*/ ANSI.fg.bright.cyan, // input color
// prefix: /*(null | string)*/ '>', - custom prefix. null = prefix disabled
// finishPrefix: /*(boolean)*/ true, - show final prefix when input readed
default: /*(string)*/ "42", // default name
validate: (val) => (Number(val > 100)) ? "Very big number!" : true // input validation
});
cs.console.log(`Your number: ${cs.fg.bright.magenta(name)}`);
}
main();
import ColorSide, { ANSI } from 'colorside';
const cs: any = new ColorSide("ru");
cs.use(cs.console);
cs.use(cs.input);
async function main(): Promise<void> {
const name = await cs.input.readlist({
message: /*(string)*/ "Select OS:",
choices: [
{ name: 'Windows', value: 'Windows' },
{ name: 'Linux (it\'s a base)', value: 'Linux'},
{ name: 'Mac', value: 'Mac', disabled: true}
],
/* optional params */
// messageColor: /*(string)*/ ANSI.fg.green, - message color
// prefix: /*(null | string)*/ '>', - custom prefix. null = prefix disabled
// finishPrefix: /*(boolean)*/ true, - show final prefix when input readed
// default: /*(string)*/ "value", - default name
// validate: (val) => (condition) || else - input validation
// instructions: (boolean) false, - hide input instructions
/* CUSTOM HIGHLIGHTING
selectColors: [
{
keys: ["Admin"],
color: ANSI.fg.bright.red
}
],
answerColor: "auto" / ANSI.color (string) // What will be the final color of the answer: auto - uses indexes from selectColor
*/
});
cs.console.log(`OS selected: ${cs.fg.bright.green(name)}`);
}
main();
import ColorSide, { ANSI } from 'colorside';
const cs: any = new ColorSide("ru");
cs.use(cs.console);
cs.use(cs.input);
async function main(): Promise<void> {
const name = await cs.input.readcheckbox({
message: /*(string)*/ "Select OS:",
choices: [
{ name: 'Windows', value: 'Windows', description: 'Base user OS' },
{ name: 'Linux', value: 'Linux', description: 'Base server OS' },
{ name: 'Mac', value: 'Mac', description: 'Not OS' }
],
/* optional params */
// messageColor: /*(string)*/ ANSI.fg.green, - message color
// prefix: /*(null | string)*/ '>', - custom prefix. null = prefix disabled
// finishPrefix: /*(boolean)*/ true, - show final prefix when input readed
// default: /*(string)*/ "value", - default name
// validate: (val) => (condition) || else - input validation
// instructions: (boolean) false - hide input instructions
});
cs.console.log(`OS selected: ${cs.fg.bright.green(name)}`);
/* CUSTOM HIGHLIGHTING supports already like in readlist */
}
main();
import ColorSide, { ANSI } from 'colorside';
const cs: any = new ColorSide("ru");
cs.use(cs.console);
cs.use(cs.input);
async function main(): Promise<void> {
const name = await cs.input.readpassword({
message: /*(string)*/ "Enter your pass:",
/* optional params */
// messageColor: /*(string)*/ ANSI.fg.green, - message color
inputColor: /*(string)*/ ANSI.fg.bright.cyan, // input color
// prefix: /*(null | string)*/ '>', - custom prefix. null = prefix disabled
// finishPrefix: /*(boolean)*/ true, - show final prefix when input readed
//default: /*(string)*/ - default name
validate: (val) => (val === "ForeverHost") || "Incorrect password" // input validation
});
cs.console.log(`Your pass: ${cs.fg.bright.magenta(name)}`);
}
main();
import ColorSide, { ANSI } from 'colorside';
const cs: any = new ColorSide("ru");
cs.use(cs.console);
cs.use(cs.input);
async function main(): Promise<void> {
const name = await cs.input.readconfirm({
message: /*(string)*/ "Install package?",
/* optional params */
// messageColor: /*(string)*/ ANSI.fg.green, - message color
inputColor: /*(string)*/ ANSI.fg.bright.cyan, // input color
// prefix: /*(null | string)*/ '>', - custom prefix. null = prefix disabled
// finishPrefix: /*(boolean)*/ true, - show final prefix when input readed
// default: /*(string)*/ - default name
// validate: (val) => (condition) || else - input validation
});
cs.console.log(`Install package: ${cs.fg.bright.magenta(name)}`);
}
main();
import ColorSide, { ANSI } from 'colorside';
const cs: any = new ColorSide("ru");
cs.use(cs.console);
cs.use(cs.input);
async function main(): Promise<void> {
const name = await cs.input.readtoggle({
message: /*(string)*/ "Install package?",
active: "Yes",
inactive: "No",
/* optional params */
// messageColor: /*(string)*/ ANSI.fg.green, - message color
// STRING ONLY prefix: /*(string)*/ '>', - custom prefix. null = prefix disabled
// default: /*(string)*/ - default name
// validate: (val) => (condition) || else - input validation
/* CUSTOM HIGHLIGHTING
selectColors: {
active: ANSI.color,
inactive: ANSI.color
}
answerColor: "auto" / ANSI.color (string) // What will be the final color of the answer: auto - uses indexes from selectColor
*/
/** @returns true / false */
});
cs.console.log(`Install package: ${cs.fg.bright.magenta(name)}`);
}
main();
import ColorSide, { Random, ANSI } from 'colorside';
Random.Int(1, 7); // Random int in range
Random.Float(1, 7); // Random float in range
Random.String(['A-Z', 'a-z', '0-9', /* custom symbols */ '&_₽*$+=%'], 8 /* length */); // Random string value