rsigma_runtime/io/
stdout.rs1use std::io::Write;
2
3use rsigma_eval::ProcessResult;
4
5use crate::error::RuntimeError;
6
7pub struct StdoutSink {
9 pretty: bool,
10}
11
12impl StdoutSink {
13 pub fn new(pretty: bool) -> Self {
14 StdoutSink { pretty }
15 }
16
17 pub fn send(&self, result: &ProcessResult) -> Result<(), RuntimeError> {
19 if result.detections.is_empty() && result.correlations.is_empty() {
20 return Ok(());
21 }
22
23 let stdout = std::io::stdout();
24 let mut out = stdout.lock();
25
26 for m in &result.detections {
27 let json = if self.pretty {
28 serde_json::to_string_pretty(m)?
29 } else {
30 serde_json::to_string(m)?
31 };
32 writeln!(out, "{json}")?;
33 }
34
35 for m in &result.correlations {
36 let json = if self.pretty {
37 serde_json::to_string_pretty(m)?
38 } else {
39 serde_json::to_string(m)?
40 };
41 writeln!(out, "{json}")?;
42 }
43
44 Ok(())
45 }
46}