context_creator/formatters/
mod.rs1use crate::cli::OutputFormat;
4use crate::core::cache::FileCache;
5use crate::core::context_builder::ContextOptions;
6use crate::core::walker::FileInfo;
7use anyhow::Result;
8use std::sync::Arc;
9
10pub mod markdown;
11pub mod paths;
12pub mod plain;
13pub mod xml;
14
15pub struct DigestData<'a> {
17 pub files: &'a [FileInfo],
18 pub options: &'a ContextOptions,
19 pub cache: &'a Arc<FileCache>,
20 pub base_directory: &'a str,
21}
22
23pub trait DigestFormatter {
25 fn render_header(&mut self, data: &DigestData) -> Result<()>;
27
28 fn render_statistics(&mut self, data: &DigestData) -> Result<()>;
30
31 fn render_file_tree(&mut self, data: &DigestData) -> Result<()>;
33
34 fn render_toc(&mut self, data: &DigestData) -> Result<()>;
36
37 fn render_file_details(&mut self, file: &FileInfo, data: &DigestData) -> Result<()>;
39
40 fn finalize(self: Box<Self>) -> String;
42
43 fn format_name(&self) -> &'static str;
45}
46
47pub fn create_formatter(format: OutputFormat) -> Box<dyn DigestFormatter> {
49 match format {
50 OutputFormat::Markdown => Box::new(markdown::MarkdownFormatter::new()),
51 OutputFormat::Xml => Box::new(xml::XmlFormatter::new()),
52 OutputFormat::Plain => Box::new(plain::PlainFormatter::new()),
53 OutputFormat::Paths => Box::new(paths::PathsFormatter::new()),
54 }
55}