saya-cli 0.2.0

Database-aware AI agent for the terminal: full-screen TUI, schema discovery, and bounded read-only SQL over PostgreSQL, MySQL, DuckDB, and Snowflake.
Documentation
use crate::render::{RenderFormat, TerminalEvent, render_event};
use saya_types::ConnectionError;

pub(super) fn emit(event: TerminalEvent, format: RenderFormat) {
    let rendered = render_event(&event, format);
    print!("{}", rendered.stdout);
    eprint!("{}", rendered.stderr);
}

pub(super) fn result(
    message: String,
    format: RenderFormat,
) -> Result<i32, Box<dyn std::error::Error>> {
    emit(TerminalEvent::Result { message }, format);
    Ok(0)
}

pub(super) fn failure(
    code: i32,
    error: ConnectionError,
    format: RenderFormat,
) -> Result<i32, Box<dyn std::error::Error>> {
    emit(
        TerminalEvent::Error {
            message: error.to_string(),
        },
        format,
    );
    Ok(code)
}

pub(super) fn failure_message(
    code: i32,
    message: String,
    format: RenderFormat,
) -> Result<i32, Box<dyn std::error::Error>> {
    emit(TerminalEvent::Error { message }, format);
    Ok(code)
}