1pub trait UiSink {
3 fn write_stdout(&mut self, text: &str);
4 fn write_stderr(&mut self, text: &str);
5}
6
7#[derive(Default)]
8pub struct StdIoUiSink;
9
10impl UiSink for StdIoUiSink {
11 fn write_stdout(&mut self, text: &str) {
12 if !text.is_empty() {
13 print!("{text}");
14 }
15 }
16
17 fn write_stderr(&mut self, text: &str) {
18 if !text.is_empty() {
19 eprint!("{text}");
20 }
21 }
22}
23
24#[derive(Default, Debug)]
25pub struct BufferedUiSink {
26 pub stdout: String,
27 pub stderr: String,
28}
29
30impl UiSink for BufferedUiSink {
31 fn write_stdout(&mut self, text: &str) {
32 self.stdout.push_str(text);
33 }
34
35 fn write_stderr(&mut self, text: &str) {
36 self.stderr.push_str(text);
37 }
38}