-
Notifications
You must be signed in to change notification settings - Fork 58
Expand file tree
/
Copy pathprinter.rs
More file actions
33 lines (28 loc) · 906 Bytes
/
printer.rs
File metadata and controls
33 lines (28 loc) · 906 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
use eldritch::{Printer, Span};
use tokio::sync::mpsc::UnboundedSender;
#[derive(Debug)]
pub struct StreamPrinter {
tx: UnboundedSender<String>,
error_tx: UnboundedSender<String>,
}
impl StreamPrinter {
pub fn new(tx: UnboundedSender<String>, error_tx: UnboundedSender<String>) -> Self {
Self { tx, error_tx }
}
}
// TODO: @Kcarretto remove this
impl StreamPrinter {
pub fn report_error(&self, s: &str) {
let _ = self.error_tx.send(format!("{}\n", s));
}
}
impl Printer for StreamPrinter {
fn print_out(&self, _span: &Span, s: &str) {
// We format with newline to match BufferPrinter behavior which separates lines
let _ = self.tx.send(format!("{}\n", s));
}
fn print_err(&self, _span: &Span, s: &str) {
// We format with newline to match BufferPrinter behavior
let _ = self.error_tx.send(format!("{}\n", s));
}
}