Skip to main content

steamroom_cli/
sink.rs

1//! Output sink abstraction shared by direct-mode CLI and the daemon
2//! worker. Every `run_*` command in `commands/` writes results through a
3//! `&dyn JobSink` so the same code paths produce stdout text in direct
4//! mode and broadcast events in daemon mode.
5
6use crate::daemon::proto::ProgressUpdate;
7
8pub trait JobSink: Send + Sync {
9    fn stdout_line(&self, line: &str);
10    fn progress(&self, update: ProgressUpdate);
11}
12
13/// Direct-mode sink: writes to the inherited stdout and to `tracing`.
14/// Progress updates are absorbed (direct mode wires the progress bar
15/// separately through `download::spawn_progress_renderer`).
16pub struct StdoutSink;
17
18impl Default for StdoutSink {
19    fn default() -> Self {
20        Self::new()
21    }
22}
23
24impl StdoutSink {
25    pub fn new() -> Self {
26        Self
27    }
28}
29
30impl JobSink for StdoutSink {
31    fn stdout_line(&self, line: &str) {
32        println!("{line}");
33    }
34    fn progress(&self, _update: ProgressUpdate) {
35        // Direct mode renders progress via the existing event channel;
36        // sink-level progress events are a daemon-only concern.
37    }
38}