1pub mod ansi;
4pub mod fragment;
5pub mod plain;
6
7pub use fragment::FragmentFormatter;
8pub use plain::PlainFormatter;
9
10use crate::Emit;
11use std::io;
12
13pub trait Formatter {
15 fn write(&mut self, sink: &mut dyn io::Write, emit: &Emit) -> io::Result<()>;
16}
17
18#[derive(Debug, Clone)]
20pub struct FormatOpts {
21 pub show_line_numbers: bool,
22 pub show_filename: bool,
23 pub filename: Option<String>,
24 pub color: bool,
25 pub target_marker: bool,
28}
29
30impl FormatOpts {
31 pub fn prefix(&self, line_no: u64) -> String {
32 let mut p = String::new();
33 if self.show_filename
34 && let Some(f) = &self.filename
35 {
36 p.push_str(f);
37 p.push(':');
38 }
39 if self.show_line_numbers {
40 p.push_str(&line_no.to_string());
41 p.push(':');
42 }
43 p
44 }
45}