@trap_stevo/terminal-plus
Version:
Transform your CLI into a visually striking, feature-rich command layer. Blend animated gradients, stylish badges, dynamic progress bars, sleek tables, and precise formatting utilities β all turning terminal output into a powerful visual experience.
504 lines (365 loc) β’ 21.5 kB
Markdown
# π₯οΈ @trap_stevo/terminal-plus
**Transform your CLI into a visually striking, feature-rich command layer.**
Blend animated gradients, stylish badges, dynamic progress bars, sleek tables, and precision formatting utilities β engineered for legendary terminal output.
## π Features
- π Animated gradient text and smooth-moving animations
- π·οΈ Stylish, icon-enhanced terminal badges
- π Interactive multi-task progress bars with paging
- π Sleek auto-formatted console tables with border styles and gradients
- π¨ Color formatting utilities
- π Attach dynamic followers to animations or base content
- π§ Byte and time formatting utilities
## βοΈ System Requirements
| Requirement | Version |
|----------------|--------------------|
| **Node.js** | β₯ 19.x |
| **npm** | β₯ 9.x (recommended)|
| **OS** | Windows, macOS, Linux |
## π Specifications
| Method | Description | Async |
|---------------------------|------------------------------------------------------------------------|:-----:|
| `constructor(options)` | Initializes a new `TerminalPlus` instance with optional config | β |
| `log(message, type)` | Logs a styled message with timestamp | β |
| `printGradient(text)` | Prints gradient-colored static text to the terminal | β |
| `printMovingGradient(text, colors, interval)` | Displays animated gradient text | β |
| `printColor(text, opts)` | Returns styled text with custom color formatting | β |
| `printBadge(label, opts)` | Prints a stylized badge directly to the terminal | β |
| `getBadge(label, opts)` | Returns the badge as a string (no printing) | β |
| `drawDivider(type, position, colors, content, width)` | Renders a gradient divider line or sci-fi frame | β |
| `createTable(data, opts)` | Renders a formatted, stylized console table | β |
| `createProgressBar(tasks = [], options = {})` | Displays a multi-task progress bar system | β |
| `attachFollower(base, content, options = {})` | Dynamically renders content below or inline with an animation | β
|
| `setDefaultGradient(gradient)` | Updates the globally used fallback gradient colors | β |
| `formatBytes(size)` | Converts bytes to a readable string with appropriate units | β |
| `formatSeconds(seconds)` | Converts seconds to a `hh:mm:ss` formatted string | β |
## π§° Methods Overview
### `constructor(options = {})` β *Sync*
Initializes the `TerminalPlus` instance.
**Options**:
- `gradientSpeed` *(number)*: Speed of moving gradient (default `100`)
- `defaultGradient` *(string[])*: Default gradient colors (default `["#00ffff", "#1a73e8"]`)
### `log(message, type = "info", typeOptions = {})` β *Sync*
Log a timestamped message with optional styles.
**Parameters**:
- `message`: String to print
- `type`: `"info" | "warn" | "error" | "success" | "debug"`
- `typeOptions`: Override default chalk styles
### `printGradient(text, colors = this.options.defaultGradient, interval = this.options.gradientSpeed)` β *Sync*
Prints a static gradient text to console.
### `printMovingGradient(text, colors, interval)` β *Sync*
Returns a moving gradient animation object.
**Returns**: `animation` with `.start()` and `.stop()` methods
### `printColor(text, options = {})` β *Sync*
Returns colored string using inline styles.
**Options**:
- `textColor`: hex or color keyword
- `backgroundColor`: hex or color keyword
- `bold`, `italic`, `underline` etc.
### `printBadge(label, options = {})` β *Sync*
Prints a styled badge to the console.
### `getBadge(label, options = {})` β *Sync*
Returns the badge string (instead of printing).
**Options**:
- `icon`: prepended icon
- `textColor`, `backgroundColor`
- `gradient`: [start, end]
- `padding`, `rounded`
### π§± `drawDivider(type, position, colors, content, width)` β *Sync*
Draws a gradient divider line or a sci-fi style framed section.
#### Parameters:
- `type` *(string)*: `"default"`, `"arrow"`, or `"sci-frame"` (default: `"default"`)
- `position` *(string|null)*: `"top"`, `"bottom"`, or `null` (only applies to `"sci-frame"`)
- `colors` *(string[])*: Gradient color pair (default: `["#273140", "#143857"]`)
- `content` *(string|null)*: Optional string or pattern to use instead of default line
- `width` *(number)*: Total width of the divider (default: `116`)
```js
// Default sleek divider
terminal.drawDivider();
// Arrow-style divider
terminal.drawDivider("arrow", null, ["#1a3c78", "#1e607e"]);
// Framed section with header
terminal.drawDivider("sci-frame", "top");
terminal.drawDivider("sci-frame", null, ["#1a212b", "#2b7fc5"], " SUPERCL SESSION ", 100);
terminal.drawDivider("sci-frame", "bottom");
// Custom pattern divider
terminal.drawDivider("custom", null, ["#1a3c78", "#338ba8"], "~*~".repeat(30), 120);
```
### `createTable(data, options = {})` β *Sync*
Renders an auto-aligned styled table.
**Parameters**:
- `data`: Array of row objects
- `options`:
- `columnNames`: Object map for column labels
- `columnOrder`: Array to define column order
- `padding`: Cell padding
- `borderStyle`: `"solid" | "double" | "round" | "bold"`
- `gradient`: `{ header, border, title, cell }`
### `createProgressBar(tasks = [], options = {})` β *Sync*
Creates a multi-task progress bar manager.
**Returns**: Manager with `.updateTaskProgress(name, delta)`
### `attachFollower(base, content, options = {})` β *Async*
Attaches content (like badge) near an animation or after a delay.
**Parameters**:
- `base`: the animated base (must have `.moving()`)
- `content`: string or function returning string
- `options`:
- `inline`: `true | false`
- `inlinePosition`: `"left" | "right"`
- `spacing`: # of lines or spaces
- `delay`: in milliseconds
### `setDefaultGradient(colors: string[])` β *Sync*
Sets the default gradient colors globally.
### `formatBytes(size, dynamicUnits = true)` β *Sync*
Formats bytes into readable strings (e.g. `12.3 MB`).
### `formatSeconds(seconds)` β *Sync*
Formats seconds into `hh:mm:ss` format.
## Terminal Components
### π Console Table Options
The `ConsoleTable` supports rich customization for column styling, layout, borders, and gradients. Below provides all the configurable options you can pass when creating a table via `createTable(data, options)`:
| Option | Type | Description |
|---------------------|--------------------|----------------------------------------------------------------------------------------------|
| `padding` | `number` | Space padding inside each cell (default: `1`) |
| `headerAlign` | `"left" \| "right" \| "center"` | Text alignment for header cells (default: `"center"`) |
| `cellAlign` | `"left" \| "right" \| "center"` | Text alignment for regular cells (default: `"left"`) |
| `borderStyle` | `"solid" \| "double" \| "round" \| "bold"` | Style of table border characters (default: `"solid"`) |
| `headerColor` | `function` | Function to apply color/styling to header cell content |
| `borderColor` | `function` | Function to apply color/styling to border characters |
| `cellColor` | `function(content, column, row)` | Function to apply color/styling per cell content (default: returns raw content) |
| `columnOrder` | `string[]` | Define explicit column order instead of automatic detection |
| `columnNames` | `object` | Map of `originalKey : displayLabel` to rename column headers |
| `title` | `string` | Optional table title (rendered above the table) |
| `tableNumber` | `number` | Optional number to tag the table for reference |
| `gradient.title` | `[string, string]` | Gradient color pair applied to the title (overrides static color) |
| `gradient.header` | `[string, string]` | Gradient color pair applied to header text |
| `gradient.border` | `[string, string]` | Gradient color pair applied to border characters |
| `gradient.cell` | `[string, string]` | Gradient color pair applied to cell content |
### π· Terminal Badge Options
The `TerminalBadge` component enables you to display beautifully styled label badges directly in the terminal with support for colors, gradients, icons, and format types.
You can use it via:
```js
terminal.printBadge("Build Success", options);
const badge = terminal.getBadge("MyCLI", options);
```
| Option | Type | Description |
|---------------------|----------------------|----------------------------------------------------------------------------------------------|
| `icon` | `string` | Emoji or icon to prepend inside the badge (e.g., `"π"`) |
| `padding` | `number` | Number of spaces on both sides of the content (default: `1`) |
| `backgroundColor` | `string (hex)` | Background color of the badge (default: `"#6c63ff"`) |
| `textColor` | `string (hex)` | Foreground (text) color inside the badge (default: `"#ffffff"`) |
| `gradient` | `[string, string]` | Optional gradient colors to override backgroundColor |
| `type` | `"sleek" \| "sci-fi" \| "rounded" \| "classic"` | Defines the badge frame style (default: `"sleek"`) |
| `inline` | `boolean` | Whether to render the badge inline or on its own line (default: `true`) |
### π Console Progress Bar Options
The `ConsoleProgressBarManager` allows you to manage multiple terminal-based progress bars with advanced customization. You can create a manager using:
```js
const barManager = terminal.createProgressBar(tasks, options);
```
#### Tasks Format
An object with at least:
```js
{ name : "Upload", size : 1000 }
```
#### π Options
| Option | Type | Description |
|----------------------|-----------------------|-----------------------------------------------------------------------------------------------|
| `barWidth` | `number` | Total width of the progress bar (default: `40`) |
| `barChar` | `string` | Character used to fill the progress bar (default: `"β"`) |
| `emptyChar` | `string` | Character used for the unfilled portion (default: `"β"`) |
| `showPercentage` | `boolean` | Show percentage next to the bar (default: `true`) |
| `showCount` | `boolean` | Show current / total progress numbers (default: `true`) |
| `showBarBorder` | `boolean` | Surround the bar with borders (default: `false`) |
| `barBorderChar` | `[string, string]` | Custom left and right characters for the border (default: `["[", "]"]`) |
| `labelAlign` | `"left" \| "center" \| "right"` | Alignment of the task label (default: `"left"`) |
| `barGradient` | `[string, string]` | Gradient colors used inside the filled bar section |
| `textColor` | `string` | Hex color applied to label and percentage (default: `"#ffffff"`) |
| `completedIcon` | `string` | Optional icon to show when a task reaches 100% (e.g., `"β
"`) |
| `autoRender` | `boolean` | If `true`, automatically calls `displayPage()` and `listenForInput()` (default: `true`) |
#### π§ Task Methods
After creating the bar manager, you can control tasks with:
```js
barManager.updateTaskProgress(taskName, amount);
barManager.completeTask(taskName);
barManager.completeAll();
```
#### Example
```js
const tasks = [
{ name : "Upload", size : 1000 },
{ name : "Process", size : 500 }
];
const barManager = terminal.createProgressBar(tasks, {
barWidth : 30,
barChar : "#",
emptyChar : "-",
barGradient : ["#00C9FF", "#92FE9D"],
completedIcon : "β
"
});
// Simulate updates
barManager.updateTaskProgress("Upload", 100);
```
> π‘ Console Progress Bar uses cumulative progression β keep calling `updateTaskProgress` to move it forward.
### π Terminal Spinner Options
The `TerminalSpinner` creates beautiful animated loaders with support for color gradients, shifting, icons, and custom frames.
You can start a spinner using:
```js
const spinner = terminal.createSpinner("Loading...", options);
spinner.start();
// Optional: stop after done
setTimeout(() => spinner.stop("β
Done!"), 3000);
```
#### π Options
| Option | Type | Description |
|--------------------------|--------------------------|-----------------------------------------------------------------------------------------------|
| `preset` | `string` | Built-in spinner style (e.g., `"dots"`, `"rocket"`, etc.) |
| `frames` | `string[]` | Custom array of frame strings (overrides `preset` if provided) |
| `interval` | `number` | Milliseconds between each frame (default: `80`) |
| `textColor` | `string \| string[]` | Text color or gradient colors array |
| `backgroundColor` | `string \| string[]` | Background color or gradient colors array |
| `icon` | `string` | Emoji or icon prepended to the spinner label (e.g., `"π"`) |
| `prefix` | `string` | String to show before the spinner block |
| `suffix` | `string` | String to show after the spinner block |
| `padding` | `number` | Number of spaces around the spinner text (default: `1`) |
| `inline` | `boolean` | Whether to print on the same line (`true`) or as a new line per frame (`false`) |
| `gradientShift` | `boolean` | Enable live shifting of text/background gradients per frame |
| `textGradientSpeed` | `number` | Number of frames before shifting text gradient (default: `1`) |
| `bgGradientSpeed` | `number` | Number of frames before shifting background gradient (default: `1`) |
| `textGradientReverse` | `boolean` | Reverse the direction of text gradient shift |
| `bgGradientReverse` | `boolean` | Reverse the direction of background gradient shift |
#### ποΈ Built-in Spinner Presets
| Preset | Description |
|--------------|---------------------------------|
| `dots` | Classic braille spinner |
| `line` | Rotating slashes |
| `arrows` | Directional arrow cycle |
| `circle` | Circular quadrant spinner |
| `bounce` | Bouncing dot loader |
| `bar` | Progress bar simulation |
| `grow` | Vertical growth bar |
| `clock` | Analog clock face rotation |
| `simple` | Expanding ellipsis |
| `supercape` | Superhero flying dash |
| `fireball` | Flame swipe with momentum |
| `magic` | Glowing spell swirl |
| `rocket` | Rocket launch animation |
| `retro` | Alien + UFO loop |
## π¦ Install
```bash
npm install @trap_stevo/terminal-plus
```
## π Example Usage
Hereβs a full example of how to use `TerminalPlus` to build a legendarily appealing terminal output:
```js
const TerminalPlus = require("@trap_stevo/terminal-plus");
const terminal = new TerminalPlus({
gradientSpeed : 75,
defaultGradient : ["#FF00FF", "#00FFFF"]
});
// πΉ Gradient Text
terminal.printGradient("β¨ Welcome to LegendaryTerminal β¨");
// πΉ Moving Gradient (animated)
const badge = terminal.getBadge("MyCLI", {
icon : "π",
backgroundColor : "#007BFF",
textColor : "#ffffff",
padding : 2,
rounded : true
});
const anim = terminal.printMovingGradient("β¨ Animating with style...", ["#FF6B6B", "#FFD93D"]);
anim.setFollower(badge);
setTimeout(() => {
anim.stop();
console.log("\nβ
Animation done.\n");
}, 3000);
// πΉ Terminal Badge
terminal.printBadge("MyCLI", {
icon : "π",
backgroundColor : "#007BFF",
textColor : "#ffffff",
padding : 2,
rounded : true
});
// πΉ Custom Styled Badge with Gradient
terminal.printBadge("Build Success", {
icon : "β
",
gradient : ["#28a745", "#85e085"],
textColor : "#000000",
padding : 1,
rounded : true
});
// πΉ Console Table
const tableOutput = terminal.createTable([
{ name : "Alice", role : "Admin", age : 30 },
{ name : "Bob", role : "User", age : 25 }
], {
columnNames : { name : "Name", role : "Role", age : "Age" },
gradient : {
header : ["#00C9FF", "#92FE9D"],
cell : ["#FFDEE9", "#B5FFFC"]
},
borderStyle : "round"
});
console.log("\n" + tableOutput);
// πΉ Styled Text Using applyColor
const styled = terminal.printColor("π‘ SECURE", {
backgroundColor : "#222831",
textColor : "#00FFF5"
});
process.stdout.write(styled);
// πΉ Inline Badge Follower
terminal.attachFollower(styled, badge, { inline : true });
// πΉ Byte & Time Format Utilities
console.log("\nFile size:", terminal.formatBytes(12582912));
console.log("Estimated time:", terminal.formatSeconds(9876));
setTimeout(() => {
const spinner = terminal.createSpinner("Launching to the stars...", {
preset : "rocket",
textColor : ["#00FFF5", "#1A73E8", "#9D00FF"],
backgroundColor : ["#0F1117", "#11131A", "#0F1117"],
gradientShift : true,
textGradientSpeed : 0.1,
bgGradientSpeed : 2,
textGradientReverse : false,
bgGradientReverse : true,
interval : 100
});
setTimeout(() => {
spinner.stop("π We have liftoff!");
}, 4000);
}, 3000);
```
> π§ Customize every visual element, combine components, and inject dynamic elegance into every CLI interaction.
## π License
See License in [LICENSE.md](./LICENSE.md)
## π§ Terminal Magic. Command Layer Power.
Turn everyday terminal output into a high-impact visual experience.
Use it to elevate your CLI tools, installation wizards, developer scripts, or deployment logs with elegance and clarity.
> Let your terminal shine with color, clarity, and control.