### Complete CLI Application Example in Rust
Source: https://context7.com/0x20f/paris/llms.txt
Shows a practical example of a CLI application using the Paris library. This includes styling, logging, indentation, loading spinners, and displaying a deployment summary.
```rust
use paris::Logger;
use std::{thread, time::Duration};
fn main() {
let mut log = Logger::new();
// Define consistent styling
log.add_style("title", vec!["bright-cyan", "bold", "underline"])
.add_style("highlight", vec!["bright-yellow", "bold"]);
// Application startup
log.log("
MyApp Deployment Tool v2.1.0>");
log.newline(1);
// Configuration check
log.info("Checking configuration...");
log.indent(1).success("Config file loaded")
.indent(1).success("Credentials validated")
.indent(1).warn("Using default port 8080>");
log.newline(1);
// Long operation with spinner
log.loading("Connecting to remote server...");
thread::sleep(Duration::from_secs(2));
log.success("Connected to prod-server-01>");
// Deployment process
log.loading("Deploying application...");
thread::sleep(Duration::from_secs(3));
// Results
log.done().newline(1);
log.info("Deployment Summary:")
.indent(1).log("Files uploaded: 247>")
.indent(1).log("Services restarted: 3>")
.indent(1).log("Duration: 5.2s>");
log.newline(1);
log.success("Deployment completed successfully!>");
// Final status on same line
log.newline(1)
.same().log("Status: ")
.log(" ONLINE >");
}
```
--------------------------------
### Rust Inline Color Tags and Text Styling
Source: https://context7.com/0x20f/paris/llms.txt
Demonstrates the use of Paris's tag-based syntax for applying inline formatting to log messages. This includes foreground and background colors, bright variants, and text styles like bold, underline, italic, dimmed, blink, reverse, hidden, and strikethrough. The example shows both named styles and shortcuts like `` for bold.
```rust
use paris::Logger;
fn main() {
let mut log = Logger::new();
// Foreground colors
log.info("Status: online> | Users: 1,234>");
// Background colors
log.warn(" ALERT > Something needs attention");
// Bright variants
log.log("Server: production> Environment: stable>");
// Text styles
log.info("This is important> and underlined>");
log.log("Note:> Use dimmed> for less important info");
log.log("Old value> → New value");
// Style shortcuts: b(bold), u(underline), i(italic), d(dimmed),
// l(blink), r(reverse), h(hidden), s(strikethrough)
log.log("Critical>: System restart required");
// Reset tags
log.log("Error in module>: normal text continues");
log.log("Colored/>only foreground> all reset");
log.log("Text//>background reset only");
}
```
--------------------------------
### Configure Feature Flags in Cargo.toml
Source: https://context7.com/0x20f/paris/llms.txt
Examples for enabling optional functionality through Cargo features. This includes configurations for timestamps, macros, and disabling the logger.
```toml
# Cargo.toml configurations
# Default - Logger with color support only
[dependencies]
paris = "1.5"
# Add timestamps to all output
[dependencies]
paris = { version = "1.5", features = ["timestamps"] }
# Enable macro support
[dependencies]
paris = { version = "1.5", features = ["macros"] }
# Both timestamps and macros
[dependencies]
paris = { version = "1.5", features = ["timestamps", "macros"] }
# Formatter only, no Logger struct (minimal size)
[dependencies]
paris = { version = "1.5", features = ["no_logger"] }
```
--------------------------------
### Use LogIcon Enum Directly in Rust
Source: https://context7.com/0x20f/paris/llms.txt
Shows how to use the LogIcon enum directly in custom print statements for indicating status. It includes examples for individual icons, formatted strings, and converting to string.
```rust
use paris::LogIcon;
fn main() {
// Individual icons
println!("{} Task completed", LogIcon::Tick);
println!("{} Task failed", LogIcon::Cross);
println!("{} Additional info", LogIcon::Info);
println!("{} Warning: check logs", LogIcon::Warning);
println!("{} Thank you", LogIcon::Heart);
// In formatted strings
let status = "OK";
println!("{} System status: {}", LogIcon::Tick, status);
// Convert to string
let icon_str = LogIcon::Info.to_str();
assert_eq!(icon_str, "ℹ");
}
```
--------------------------------
### Use Basic Logging Macros in Rust
Source: https://context7.com/0x20f/paris/llms.txt
Demonstrates the usage of basic logging macros provided by the Paris library for quick logging without instantiating a Logger. This includes different log levels and formatting options.
```rust
use paris::{log, info, success, warn, error};
fn main() {
// Basic output
log!("Application started");
// With formatting
info!("Connected to {}", "localhost:5432");
success!("Processed {} items", 42);
warn!("Memory usage at {}%", 85);
error!("Failed to load config: {}", "file not found");
// Color tags work in macros too
info!("Status: healthy> | Uptime: {}>", "3d 5h");
log!("Important:> System will restart in {} minutes>", 5);
}
```
--------------------------------
### Basic Logger Initialization and Info Logging in Rust
Source: https://github.com/0x20f/paris/blob/master/README.md
Demonstrates how to initialize the `Logger` struct from the `paris` crate and log a simple informational message. This is the most basic usage of the library.
```rust
use paris::Logger;
let mut log = Logger::new();
log.info("It's that simple!");
```
--------------------------------
### Logging with Icons using Macros in Rust
Source: https://github.com/0x20f/paris/blob/master/README.md
Illustrates the use of macros provided by the `paris` crate for logging messages with icons. This requires enabling the `macros` feature and offers a more concise syntax than direct method calls.
```rust
// or as macros
info!("Will add ℹ at the start");
error!("Will add ✖ at the start");
```
--------------------------------
### Use Standalone String Formatting in Rust
Source: https://context7.com/0x20f/paris/llms.txt
Illustrates how to use the formatter API without the Logger struct for custom output systems. It covers colorization, stripping tags, and applying custom styles.
```rust
use paris::formatter::{Formatter, colorize_string, format_string};
fn main() {
// Quick colorization
let formatted = colorize_string("Success:> Operation complete>");
println!("{}", formatted);
// Strip tags without adding colors
let plain = format_string("Error:> Something failed", false);
assert_eq!(plain, "Error: Something failed");
// Formatter with custom styles
let mut fmt = Formatter::new();
fmt.new_style("brand", vec!["bright-magenta", "bold"])
.new_style("muted", vec!["dimmed", "italic"]);
let message = "MyApp> v1.0.0>";
let output = fmt.colorize(message);
println!("{}", output);
}
```
--------------------------------
### Rust Basic Logger Usage with Icons and Colors
Source: https://context7.com/0x20f/paris/llms.txt
Demonstrates the basic usage of the Paris Logger API to output messages with predefined icons and colors for different log levels (info, success, warn, error). The Logger is created, and then methods like `log()`, `info()`, `success()`, `warn()`, and `error()` are called to display formatted output. The `error()` method specifically outputs to stderr.
```rust
use paris::Logger;
fn main() {
let mut log = Logger::new();
// Basic log output - just prints the text
log.log("Starting application...");
// Info with cyan ℹ icon
log.info("Connected to database");
// Success with green ✔ icon
log.success("User authentication completed");
// Warning with yellow ⚠ icon
log.warn("API rate limit approaching");
// Error with red ✖ icon (outputs to stderr)
log.error("Failed to connect to remote service");
}
```
--------------------------------
### Rust Custom Style Definitions and Usage
Source: https://context7.com/0x20f/paris/llms.txt
Explains how to define and use custom style shortcuts with the Paris Logger API. Developers can create reusable style combinations (e.g., 'warning', 'header', 'success') by providing a name and a vector of style tags. These custom styles can then be applied inline within log messages, similar to built-in tags, promoting consistent application theming.
```rust
use paris::Logger;
fn main() {
let mut log = Logger::new();
// Create custom style shortcuts
log.add_style("warning", vec!["yellow", "bold", "on-red"])
.add_style("header", vec!["bright-cyan", "bold", "underline"])
.add_style("success", vec!["bright-green", "bold"]);
// Use custom styles in messages
log.log("System Report>");
log.log("All tests passed>");
log.log(" Deprecated API in use > ");
// Mix custom styles with other formatting
log.info("Database Status:> Connected>");
}
```
--------------------------------
### Rust Chained Output with Indentation and Newlines
Source: https://context7.com/0x20f/paris/llms.txt
Illustrates how to build complex output sequences using the chainable methods of the Paris Logger API. This includes adding indentation levels with `indent()`, inserting newlines with `newline()`, and producing same-line output with `same()`. This pattern is useful for structuring detailed progress reports or multi-part messages.
```rust
use paris::Logger;
fn main() {
let mut log = Logger::new();
log.info("Processing items:")
.indent(1).log("Item 1: Complete")
.indent(1).log("Item 2: Complete")
.indent(1).warn("Item 3: Needs attention")
.newline(2)
.success("Batch processing finished");
// Same-line output
log.same().log("Progress: ")
.log("50%")
.log(" done"); // All on one line
}
```
--------------------------------
### Rust Loading Animation and Manual Stop
Source: https://context7.com/0x20f/paris/llms.txt
Shows how to implement a loading animation using Paris Logger's `loading()` method, providing visual feedback during long operations. The animation automatically stops when any other logging method is called, or it can be manually stopped using `done()`. This snippet includes using `thread::sleep` to simulate a time-consuming task.
```rust
use paris::Logger;
use std::{thread, time::Duration};
fn main() {
let mut log = Logger::new();
log.loading("Downloading packages...");
thread::sleep(Duration::from_secs(3));
// Any log method auto-stops loading
log.success("Download complete!");
log.loading("Building project...");
thread::sleep(Duration::from_secs(2));
// Manually stop without message
log.done().info("Build finished in 2s");
}
```
--------------------------------
### Colorizing Text with Tags in Rust
Source: https://github.com/0x20f/paris/blob/master/README.md
Explains and demonstrates how to use simple HTML-like tags within log strings to colorize specific parts of the text. It supports standard terminal colors and background colors by prefixing with 'on-'.
```rust
log.info("I can write normal text or use tags to color it>");
log.warn("Every function can contain tags>");
log.info("If you don't write them correctly>, you just get an ugly looking tag");
```
--------------------------------
### Using Bright Terminal Colors with Tags in Rust
Source: https://github.com/0x20f/paris/blob/master/README.md
Shows how to utilize the brighter variations of terminal colors by adding the `bright` keyword to the color tags. This allows for more vibrant text output.
```rust
log.info(" This text is blue on a bright red background> it's a pain");
```
--------------------------------
### Adding Paris as a Dependency in Cargo.toml
Source: https://github.com/0x20f/paris/blob/master/README.md
Provides the necessary `Cargo.toml` configuration to include the `paris` crate as a project dependency. This is the standard way to manage external libraries in Rust projects.
```toml
[dependencies]
paris = "1.5"
```
--------------------------------
### Defining and Using Custom Styles in Rust
Source: https://github.com/0x20f/paris/blob/master/README.md
Illustrates how to create reusable custom styles by combining multiple color and formatting options into a single named style using `add_style`. These custom styles can then be used as tags in log messages.
```rust
log.add_style("lol", vec!["green", "bold", "on-bright-blue"]);
// '' is now a key that you can use in your strings
log.info("This is has all your new styles>");
```
--------------------------------
### Using `colorize_string` for Simple String Colorization in Rust
Source: https://github.com/0x20f/paris/blob/master/README.md
Demonstrates the `colorize_string` function from the `paris::formatter` module, which provides a quick way to colorize a string without explicit `Formatter` instantiation. Be aware of potential drawbacks mentioned in the library's documentation.
```rust
use paris::formatter::colorize_string;
let colored_string = colorize_string("This is red> and this is bold>");
println!("{}", colored_string);
```
--------------------------------
### Use Timestamps Feature in Rust Logging
Source: https://context7.com/0x20f/paris/llms.txt
Demonstrates how to enable the timestamps feature and use it with the Logger to automatically include timestamps in all output.
```rust
// With timestamps feature enabled
use paris::Logger;
fn main() {
let mut log = Logger::new();
// Output: 14:23:45 PM: ℹ Server started
log.info("Server started");
// Output: 14:23:46 PM: ✔ Ready to accept connections
log.success("Ready to accept connections");
}
```
--------------------------------
### Logging with Icons using Logger Methods in Rust
Source: https://github.com/0x20f/paris/blob/master/README.md
Shows how to use the `Logger` struct to add icons to log messages, such as information (ℹ) or error (✖) icons. This enhances the visual distinction of different log levels.
```rust
// You can have icons at the start of your message!
log.info("Will add ℹ at the start");
log.error("Will add ✖ at the start");
```
--------------------------------
### Using Formatter for Direct String Colorization in Rust
Source: https://github.com/0x20f/paris/blob/master/README.md
Illustrates how to bypass the `Logger` API and use the `Formatter` directly from the `paris::format` module for more granular control over text formatting. This is suitable for cases where the built-in logger is too simplistic.
```rust
use paris::format::Formatter;
let mut formatter = Formatter::new();
let colored_text = formatter.format("This text is colored>");
println!("{}", colored_text);
```
--------------------------------
### Enabling Macros Feature for Paris Crate in Cargo.toml
Source: https://github.com/0x20f/paris/blob/master/README.md
Demonstrates how to enable the `macros` feature for the `paris` crate in `Cargo.toml`. This makes common logging functions available as macros (e.g., `info!`, `error!`).
```toml
[dependencies]
paris = { version = "1.5", features = ["macros"] }
```
--------------------------------
### Chaining Log Messages with Indentation and Newlines in Rust
Source: https://github.com/0x20f/paris/blob/master/README.md
Demonstrates the ability to chain multiple `Logger` methods together to create complex log outputs. This includes methods for indentation (`indent`) and adding multiple newlines (`newline`), helping to manage log string concatenation.
```rust
log.info("this is some info")
.indent(4).warn("this is now indented by 4")
.newline(5)
.success("and this is 5 lines under all other messages");
```
--------------------------------
### Enabling Timestamps Feature for Paris Crate in Cargo.toml
Source: https://github.com/0x20f/paris/blob/master/README.md
Shows how to enable the `timestamps` feature for the `paris` crate in `Cargo.toml`. This will add timestamps to all log messages automatically.
```toml
[dependencies]
paris = { version = "1.5", features = ["timestamps"] }
```
--------------------------------
### Enabling No Logger Feature for Paris Crate in Cargo.toml
Source: https://github.com/0x20f/paris/blob/master/README.md
Explains how to enable the `no_logger` feature for the `paris` crate in `Cargo.toml`. This is useful if you only intend to use the logging macros and want to exclude the `Logger` struct from your build to reduce binary size.
```toml
[dependencies]
paris = { version = "1.5", features = ["no_logger"] }
```
=== COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.