Skip to main content

OutputMode

Enum OutputMode 

Source
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

Source

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
  1. SQLMODEL_PLAIN=1 - Force plain output
  2. SQLMODEL_JSON=1 - Force JSON output
  3. SQLMODEL_RICH=1 - Force rich output (overrides agent detection!)
  4. NO_COLOR present - Plain (standard convention)
  5. CI=true - Plain (CI environment)
  6. TERM=dumb - Plain (dumb terminal)
  7. Agent environment detected - Plain
  8. stdout is not a TTY - Plain
  9. 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"),
}
Source

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 CLI
  • CODEX_CLI - OpenAI Codex CLI
  • CURSOR_SESSION - Cursor IDE
  • AIDER_MODEL / AIDER_REPO - Aider coding assistant
  • AGENT_MODE - Generic agent marker
  • GITHUB_COPILOT - GitHub Copilot
  • CONTINUE_SESSION - Continue.dev extension
  • CODY_* - Sourcegraph Cody
  • WINDSURF_* - Windsurf/Codeium
  • GEMINI_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");
}
Source

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());
Source

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());
Source

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());
Source

pub const fn is_rich(&self) -> bool

Check if this mode uses rich formatting.

§Examples
use sqlmodel_console::OutputMode;

assert!(!OutputMode::Plain.is_rich());
assert!(OutputMode::Rich.is_rich());
assert!(!OutputMode::Json.is_rich());
Source

pub const fn as_str(&self) -> &'static str

Get the mode name as a string slice.

§Examples
use sqlmodel_console::OutputMode;

assert_eq!(OutputMode::Plain.as_str(), "plain");
assert_eq!(OutputMode::Rich.as_str(), "rich");
assert_eq!(OutputMode::Json.as_str(), "json");

Trait Implementations§

Source§

impl Clone for OutputMode

Source§

fn clone(&self) -> OutputMode

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for OutputMode

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for OutputMode

Source§

fn default() -> OutputMode

Returns the “default value” for a type. Read more
Source§

impl Display for OutputMode

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Hash for OutputMode

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl PartialEq for OutputMode

Source§

fn eq(&self, other: &OutputMode) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Copy for OutputMode

Source§

impl Eq for OutputMode

Source§

impl StructuralPartialEq for OutputMode

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.