pub enum OutputMode {
Plain,
Rich,
Json,
}Expand description
Output mode for console rendering.
Determines how console output should be formatted. The mode is automatically
detected based on environment variables and terminal state, but can be
overridden via SQLMODEL_PLAIN, SQLMODEL_RICH, or SQLMODEL_JSON.
Variants§
Plain
Plain text output, no ANSI codes. Machine-parseable.
Used for: AI agents, CI systems, piped output, dumb terminals.
Rich
Rich formatted output with colors, tables, panels.
Used for: Interactive human terminal sessions.
Json
Structured JSON output for programmatic consumption.
Used for: Tool integrations, scripting, IDEs.
Implementations§
Source§impl OutputMode
impl OutputMode
Sourcepub fn detect() -> Self
pub fn detect() -> Self
Detect the appropriate output mode from the environment.
This function checks various environment variables and terminal state to determine the best output mode. The detection is deterministic and follows a well-defined priority order.
§Priority Order
SQLMODEL_PLAIN=1- Force plain outputSQLMODEL_JSON=1- Force JSON outputSQLMODEL_RICH=1- Force rich output (overrides agent detection!)NO_COLORpresent - Plain (standard convention)CI=true- Plain (CI environment)TERM=dumb- Plain (dumb terminal)- Agent environment detected - Plain
- stdout is not a TTY - Plain
- Default - Rich
§Examples
use sqlmodel_console::OutputMode;
let mode = OutputMode::detect();
match mode {
OutputMode::Plain => println!("Using plain text"),
OutputMode::Rich => println!("Using rich formatting"),
OutputMode::Json => println!("Using JSON output"),
}Sourcepub fn is_agent_environment() -> bool
pub fn is_agent_environment() -> bool
Check if we’re running in an AI coding agent environment.
This function checks for environment variables set by known AI coding assistants. When detected, we default to plain output to ensure machine-parseability.
§Known Agent Environment Variables
CLAUDE_CODE- Claude Code CLICODEX_CLI- OpenAI Codex CLICURSOR_SESSION- Cursor IDEAIDER_MODEL/AIDER_REPO- Aider coding assistantAGENT_MODE- Generic agent markerGITHUB_COPILOT- GitHub CopilotCONTINUE_SESSION- Continue.dev extensionCODY_*- Sourcegraph CodyWINDSURF_*- Windsurf/CodeiumGEMINI_CLI- Google Gemini CLI
§Returns
true if any agent environment variable is detected.
§Examples
use sqlmodel_console::OutputMode;
if OutputMode::is_agent_environment() {
println!("Running under an AI agent");
}Sourcepub const fn supports_ansi(&self) -> bool
pub const fn supports_ansi(&self) -> bool
Check if this mode should use ANSI escape codes.
Returns true only for Rich mode, which is the only mode that
uses colors and formatting.
§Examples
use sqlmodel_console::OutputMode;
assert!(!OutputMode::Plain.supports_ansi());
assert!(OutputMode::Rich.supports_ansi());
assert!(!OutputMode::Json.supports_ansi());Sourcepub const fn is_structured(&self) -> bool
pub const fn is_structured(&self) -> bool
Check if this mode uses structured format.
Returns true only for Json mode, which outputs structured data
for programmatic consumption.
§Examples
use sqlmodel_console::OutputMode;
assert!(!OutputMode::Plain.is_structured());
assert!(!OutputMode::Rich.is_structured());
assert!(OutputMode::Json.is_structured());Sourcepub const fn is_plain(&self) -> bool
pub const fn is_plain(&self) -> bool
Check if this mode is plain text.
§Examples
use sqlmodel_console::OutputMode;
assert!(OutputMode::Plain.is_plain());
assert!(!OutputMode::Rich.is_plain());
assert!(!OutputMode::Json.is_plain());Trait Implementations§
Source§impl Clone for OutputMode
impl Clone for OutputMode
Source§fn clone(&self) -> OutputMode
fn clone(&self) -> OutputMode
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more