1mod session;
3mod state_block;
4mod ingest;
5mod fs_safe;
6mod content_cache;
7
8pub use session::*;
9pub use state_block::*;
10pub use ingest::*;
11pub use fs_safe::*;
12pub use content_cache::*;
13
14#[derive(Debug, Clone, Copy, PartialEq, clap::ValueEnum)]
15pub enum OutputFormat {
16 Default,
17 Compact,
18 Json,
19}
20
21#[derive(Debug, Clone)]
22pub struct FormatConfig {
23 pub format: OutputFormat,
24 pub color: bool,
25}
26
27impl FormatConfig {
28 pub fn new(format: OutputFormat) -> Self {
29 Self { format, color: matches!(format, OutputFormat::Default) }
30 }
31
32 pub fn format_output(&self, label: &str, lines: &[String]) -> String {
33 match self.format {
34 OutputFormat::Json => {
35 serde_json::to_string(&lines).unwrap_or_default()
36 }
37 OutputFormat::Compact => lines.join("\n"),
38 OutputFormat::Default => {
39 if lines.is_empty() {
40 format!("{}: (none)", label)
41 } else {
42 format!("{}:\n {}", label, lines.join("\n "))
43 }
44 }
45 }
46 }
47}