sqlmodel_console/lib.rs
1//! SQLModel Console - Beautiful terminal output for SQLModel Rust.
2//!
3//! `sqlmodel-console` is the **optional UX layer** for SQLModel Rust. It renders
4//! errors, query results, schema trees, and progress in a way that adapts to
5//! humans (rich formatting) or agents/CI (plain or JSON).
6//!
7//! # Role In The Architecture
8//!
9//! - **Optional integration**: enabled via the `console` feature in `sqlmodel` or
10//! in driver crates.
11//! - **Agent-safe output**: auto-detects AI coding tools and switches to plain text.
12//! - **Diagnostics**: provides structured renderables for tables, errors, and status.
13//!
14//! This crate provides styled console output that automatically adapts to
15//! the terminal environment. When running under an AI coding agent, output
16//! is plain text. When running interactively, output is richly formatted.
17//!
18//! # Features
19//!
20//! - `rich` - Enable rich formatted output with colors, tables, panels
21//! - `syntax` - Enable SQL syntax highlighting (requires `rich`)
22//! - `full` - Enable all features
23//!
24//! # Output Mode Detection
25//!
26//! The crate automatically detects the appropriate output mode:
27//!
28//! - **Plain**: AI agents (Claude Code, Codex, etc.), CI systems, piped output
29//! - **Rich**: Interactive human terminal sessions
30//! - **Json**: Structured output for tool integrations
31//!
32//! You can override detection via environment variables:
33//!
34//! - `SQLMODEL_PLAIN=1` - Force plain text output
35//! - `SQLMODEL_RICH=1` - Force rich output (even for agents)
36//! - `SQLMODEL_JSON=1` - Force JSON structured output
37//!
38//! # Example
39//!
40//! ```rust
41//! use sqlmodel_console::OutputMode;
42//!
43//! let mode = OutputMode::detect();
44//! if mode.supports_ansi() {
45//! println!("Rich formatting available!");
46//! } else {
47//! println!("Plain text mode");
48//! }
49//! ```
50
51// Forbid unsafe code in production, but allow in tests for env manipulation
52#![cfg_attr(not(test), forbid(unsafe_code))]
53#![cfg_attr(test, allow(unsafe_code))]
54
55pub mod console;
56pub mod logging;
57pub mod mode;
58pub mod renderables;
59pub mod theme;
60pub mod traits;
61pub mod widgets;
62
63// Re-export primary types
64pub use console::SqlModelConsole;
65pub use mode::OutputMode;
66pub use theme::Theme;
67pub use traits::ConsoleAware;
68
69/// Prelude for convenient imports.
70pub mod prelude {
71 pub use crate::console::SqlModelConsole;
72 pub use crate::mode::OutputMode;
73 pub use crate::theme::Theme;
74 pub use crate::traits::ConsoleAware;
75}