Add the library to your Cargo.toml
:
[]
= "0.6.4"
Add the library to your Cargo.toml
with features:
[]
= { = "0.6.4", = ["gradients", "table-presets"] }
Feature | Description |
---|---|
internal-commands |
Built-in helper commands like help , ping , etc. |
custom-commands |
Ergonomic helpers for user-defined commands. |
tracing-logs |
Emit tracing events via output::hook alongside console output. |
dispatch-cache |
Single-entry dispatch cache to speed repeated invocations. |
gradients |
Named gradient helpers (24‑bit RGB) with zero extra deps. |
layouts |
Lightweight layout engine for terminal rows/columns. |
table-presets |
Convenience presets for TableStyle (ASCII, Rounded, Heavy). |
progress-presets |
Convenience constructors for ProgressStyle (compact, heavy). |
theme-config |
Enable theme config serialization (serde/serde_json). |
images |
Optional image support (png/jpeg) via the image crate. |
Basic Usage
use ModCli;
Set a custom prefix
use ModCli;
Using named colors
let teal = get; // always returns a Color (or fallback)
let demo = build
.part.space
.part.color.bold.get;
line;
Using Gradients
Two-color gradient:
use ;
let gradient_text = two_color;
line;
Three-color gradient:
use ;
let gradient_text = three_color;
line;
Multi-color gradient:
use ;
let gradient_text = multi_color;
line;
Using RGB with gradients:
use ;
let gradient_text = two_color;
line;
Output Styles
use ;
// 📦 Progress Bar Demo
let testing = build
.part
.color
.bold
.get;
line;
// Outputs "Testing" in bold/blue.
Multiple Styles:
use ;
// 📦 Progress Bar Demo
let testing = build
.part.color.bold.space
.part.space
.part.color.bold.space
.part.underline.space
.part.italic.space
.part.underline.space
.part
.get;
line;
Style + Gradients:
use ;
let gradient_text = two_color;
let testing = build
.part.bold.space
.part
.get;
line;
Progress Bar & Animated Loaders
Auto Progress:
use ;
show_progress_bar;
Displays
Manual control:
use ;
// Progress Bar Demo
let label = build
.part
.color
.bold
.get;
let mut bar = new;
bar.set_label;
bar.start_auto; // auto-fill in 2 seconds
Manual .tick() control (like during a loop):
use Duration;
use ;
use run_shell;
let mut bar = new;
bar.set_label;
for _ in 0..10
println!;
Animated Spinner (Loading/Waiting):
use ;
show_spinner;
Animated Percentage Loader:
use sleep;
use Duration;
use ;
for i in .step_by
println!;
Tables
Table Example: Flex Width, Heavy Borders
use crate;
let headers = ;
let rows = vec!;
render_table;
Outputs
Table Example: Fixed Width, Rounded Borders
use crate;
let headers = ;
let rows = vec!;
render_table;
Outputs
Table Example: Fixed Width, Ascii Borders
use crate;
let headers = ;
let rows = vec!;
render_table;
Outputs
| | | |
| | | |
| | | |
| | | |
File Structure
my_project/
├── src/
│ ├── commands/
│ │ └── greet.rs ← define `GreetCommand` here
Create a commands folder in src/, then put the command in its own file:
Custom Command File
use Command;
;
greet.rs
Register your command in main.rs
, tool.rs
, etc.
use ModCli;
use GreetCommand;
Test Command
ModCLI supports an interactive console mode (like a REPL):
use CliConfig;
use run_shell;
Adding a custom console command for shell
:
use ModCli;
use ;
Config File Example (config.json)
Default location:
project_root/config.json
Manually set the config path (if not project root)
use config;
[!WARNING] Pre-release: This project is in active development. The core is stable but features are evolving. Production use is possible, but interfaces may still evolve until 1.0.