Skip to main content

looprs_core/adapters/
terminal_output.rs

1//! TerminalOutput adapter — `UserOutput` port backed by stdout/stderr.
2//!
3//! This is a minimal, dependency-free adapter. The full looprs terminal
4//! output (with colour, sanitization, and machine-log JSON) is implemented
5//! in `looprs::ui`. Use this adapter in contexts where those extras are
6//! not available (e.g. tests, embedded use).
7
8use crate::ports::UserOutput;
9
10/// Writes output directly to stdout/stderr with no formatting or sanitization.
11pub struct TerminalOutput;
12
13impl UserOutput for TerminalOutput {
14    fn info(&self, msg: &str) {
15        println!("{msg}");
16    }
17
18    fn warn(&self, msg: &str) {
19        eprintln!("warning: {msg}");
20    }
21
22    fn error(&self, msg: &str) {
23        eprintln!("error: {msg}");
24    }
25
26    fn assistant_text(&self, text: &str) {
27        println!("{text}");
28    }
29
30    fn tool_call(&self, tool_name: &str, input_preview: &str) {
31        println!("tool: {tool_name}({input_preview})");
32    }
33
34    fn tool_ok(&self) {
35        println!("  ok");
36    }
37
38    fn tool_err(&self, err_msg: &str) {
39        println!("  error: {err_msg}");
40    }
41}
42
43#[cfg(test)]
44mod tests {
45    use super::*;
46
47    #[test]
48    fn conformance() {
49        crate::ports::test_contracts::assert_user_output_contract(&TerminalOutput);
50    }
51}