pub struct SqlModelConsole { /* private fields */ }Expand description
Main coordinator for all SQLModel console output.
SqlModelConsole provides a unified API for rendering output that
automatically adapts to the detected output mode (Plain, Rich, or Json).
§Example
use sqlmodel_console::{SqlModelConsole, OutputMode};
let console = SqlModelConsole::new();
console.print("Hello, world!");
console.status("Processing...");
console.success("Done!");Implementations§
Source§impl SqlModelConsole
impl SqlModelConsole
Sourcepub fn new() -> Self
pub fn new() -> Self
Create a new console with auto-detected mode and default theme.
This is the recommended way to create a console. It will:
- Check environment variables for explicit mode
- Detect AI agent environments
- Check terminal capabilities
- Choose appropriate mode
Sourcepub fn with_mode(mode: OutputMode) -> Self
pub fn with_mode(mode: OutputMode) -> Self
Create a console with a specific output mode.
Use this when you need to force a specific mode regardless of environment.
Sourcepub fn with_theme(theme: Theme) -> Self
pub fn with_theme(theme: Theme) -> Self
Create a console with a specific theme.
Sourcepub fn plain_width(self, width: usize) -> Self
pub fn plain_width(self, width: usize) -> Self
Builder method to set the plain mode width.
Sourcepub const fn mode(&self) -> OutputMode
pub const fn mode(&self) -> OutputMode
Get the current output mode.
Sourcepub const fn get_plain_width(&self) -> usize
pub const fn get_plain_width(&self) -> usize
Get the plain mode width.
Sourcepub fn set_mode(&mut self, mode: OutputMode)
pub fn set_mode(&mut self, mode: OutputMode)
Set the output mode.
Sourcepub fn print(&self, message: &str)
pub fn print(&self, message: &str)
Print a message to stdout.
In rich mode, supports markup syntax: [bold red]text[/]
In plain mode, prints without formatting (markup stripped).
In JSON mode, regular prints go to stderr to keep stdout clean.
Sourcepub fn print_raw(&self, message: &str)
pub fn print_raw(&self, message: &str)
Print to stdout without any markup processing.
Use this when you need raw output without markup stripping.
Sourcepub fn status(&self, message: &str)
pub fn status(&self, message: &str)
Print a message followed by a newline to stderr.
Status messages are always sent to stderr because:
- Agents typically only parse stdout
- Status messages are transient/informational
- Separating streams helps with output redirection
Sourcepub fn rule(&self, title: Option<&str>)
pub fn rule(&self, title: Option<&str>)
Print a horizontal rule/divider.
Optionally includes a title centered in the rule.
Sourcepub fn print_json<T: Serialize>(&self, value: &T) -> Result<(), Error>
pub fn print_json<T: Serialize>(&self, value: &T) -> Result<(), Error>
Output JSON to stdout (compact format for parseability).
Returns an error if serialization fails.
Sourcepub fn print_json_pretty<T: Serialize>(&self, value: &T) -> Result<(), Error>
pub fn print_json_pretty<T: Serialize>(&self, value: &T) -> Result<(), Error>
Output pretty-printed JSON to stdout.
In rich mode, could include syntax highlighting (not yet implemented).
Sourcepub fn newline_stderr(&self)
pub fn newline_stderr(&self)
Print an empty line to stderr.
Trait Implementations§
Source§impl Clone for SqlModelConsole
impl Clone for SqlModelConsole
Source§fn clone(&self) -> SqlModelConsole
fn clone(&self) -> SqlModelConsole
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more