mini-blessed
v1.1.2
Published
Mini Blessed
Readme
Mini Blessed - Terminal control
Uses the Blessed API for a simplified experience with Blessed in TypeScript (maybe js - untested)
Install
npm install mini-blessed@latestFirst run
import { MiniBlessed as Mini, COLORS } from 'mini-blessed';
Mini.Console.log("Hi from mini-blessed!");Simple console output
import { MiniBlessed as Mini, COLORS } from 'mini-blessed';
Mini.Console.log("this is log");
Mini.Console.warn("this is warn (yellow)");
Mini.Console.error("this is error (red)");
Mini.Console.critical("this is critical error (pulse red text <-> red background && black text");Colored output
import { MiniBlessed as Mini, COLORS } from 'mini-blessed';
// Red text
Mini.Console.log(`${COLORS.FG.RED}Red text!${COLORS.RESET}`) // "COLORS.RESET" VERY IMPORTANT!!!
// Bright green color
Mini.Console.log(`${COLORS.FG.BRIGHT.GREEN}Light green text!${COLORS.RESET}`);
// Cyan background + black text
Mini.Console.log(`${COLORS.BG.CYAN}${COLORS.FG.BLACK}Multi-coloring!${COLORS.RESET}`);
// Bold text
Mini.Console.log(`${COLORS.STYLE.BOLD}Bold text!${COLORS.RESET}`);
// Underlined text
Mini.Console.log(`${COLORS.STYLE.UNDERLINED}Underlined text${COLORS.RESET}`);Advanced output
Advanced output also supports color output
import { MiniBlessed as Mini, COLORS } from 'mini-blessed';
// Send custom output
Mini.Custom.addLog("UNIQUE_ID", "TEXT", {});
// Clear one log
Mini.Custom.removeLog("UNIQUE_LOG_ID");
// Clean all screen
Mini.Custom.cleanScreen();⚠️ WARNING Unique log names (Mini.Custom.addLog("UNIQUE_NAME!!!", ...) must be unique for the ENTIRE PROJECT!
Advanced dynamic output
import { MiniBlessed as Mini, COLORS } from 'mini-blessed';
// Calling first green message
const onlog = Mini.Custom.Log("mylog", `${COLORS.FG.GREEN}First log${COLORS.RESET}`, {
updateInterval: 100, // Minimum text refresh rate (ms)
width: 50 // max output width before and after changing (symbols)
});
// Replace the text of the first line with a new one in 2 seconds
setTimeout(() => {
onlog?.update(`${COLORS.FG.RED}New red log!${COLORS.RESET}`);
}, 2000)Key reader
import { MiniBlessed as Mini, COLORS } from 'mini-blessed';
// Kill the app when pressed ESC / Q / Ctrl+C keys
Mini.screen.key(['escape', 'q', 'C-c'], () => process.exit(0));Basic input
⚠️ Only in main file!!! Don't works in export modules
import { MiniBlessed as Mini, COLORS } from 'mini-blessed';
const main: () => Promise<void> = async () => {
const $name: any = await Mini.Input.text("Your name: ");
const $age: any = await Mini.Input.text("Age: ");
Mini.Console.log(`Name: ${$name}\nAge: ${$age}`);
}
main();Result: Your Name: Vasiliy Age: 25 Name: Vasiliy Age: 25
Color input
>= 1.1.1
import { MiniBlessed as Mini, COLORS } from './index';
const name: any = await Mini.Input.text(`Enter your name: `, {
prefixFg: COLORS.FG.RED, // Don't supports BRIGHT colors
prefixBg: COLORS.BG.WHITE, // Don't supports BRIGHT colors
inputFg: COLORS.FG.BLUE,// Don't supports BRIGHT colors
inputBg: COLORS.BG.GREEN // Don't supports BRIGHT colors,
width: 50
});
Mini.Console.log(name);
/*
'Enter your name: ' - red foreground and white background
User input - blue foreground and green background
*/
Advanced color input
>= 1.1.1
import { MiniBlessed as Mini, COLORS } from './index';
const Name: any = await Mini.Input.text([
{ text: "Enter ", fg: COLORS.FG.WHITE },
{ text: "your name", fg: COLORS.FG.RED, bg: COLORS.BG.YELLOW + COLORS.STYLE.BOLD },
{ text: ": ", fg: COLORS.FG.WHITE }
], {
inputFg: COLORS.FG.GREEN,
inputBg: COLORS.BG.BRIGHT.BLACK
});
Mini.Console.success(`Hi, ${Name}!`);
/*
'Enter ' - white foreground
'your name' - bold, red foreground, yellow background
': ' - white foreground
*/Input key validation
>= 1.1.1
import { MiniBlessed as Mini, COLORS } from './index';
const Name: any = await Mini.Input.text([
{ text: "Enter ", fg: COLORS.FG.WHITE },
{ text: "your name", fg: COLORS.FG.RED, bg: COLORS.BG.YELLOW + COLORS.STYLE.BOLD },
{ text: ": ", fg: COLORS.FG.WHITE }
], {
inputFg: COLORS.FG.GREEN,
inputBg: COLORS.BG.BRIGHT.BLACK,
customKeys: {
'escape': (input) => { input.setValue("Skip"); input.submit(); } // pressed 'ESC' => putted 'Skip' and submitted (important input.submit()!)
}
});
if (Name !== 'Skip') {
Mini.Console.success(`Hi, ${Name}!`);
} else {
Mini.Console.error("Name skipped");
}
TODO
- [x] ~~Basic console operations~~
- [x] ~~Advanced console operations~~
- [x] ~~Basic input~~
- [x] ~~Advanced input (color customizer)~~
- [ ] Advanced input (input validation)
- [ ] Advanced input (radio menu)
- [ ] Advanced input (select menu)
- [ ] Basic progressbars
- [ ] Advanced progressbars
Dependencies
- blessed
- node-fetch
- @types/node
