Skip to main content

todo_tree/printer/
options.rs

1//! Output format and print option types.
2
3use std::path::PathBuf;
4
5/// The output format a [`super::Printer`] renders a
6/// [`crate::core::ScanResult`] as.
7#[derive(Debug, Clone, Copy, PartialEq, Eq)]
8pub enum OutputFormat {
9    /// Hierarchical, file-grouped tree view.
10    Tree,
11    /// One line per item, no grouping.
12    Flat,
13    /// Machine-readable JSON.
14    Json,
15}
16
17/// Options controlling how a scan result is rendered.
18#[derive(Debug, Clone)]
19pub struct PrintOptions {
20    /// The output format to render.
21    pub format: OutputFormat,
22    /// Whether to colorize output.
23    pub colored: bool,
24    /// Whether to show line numbers.
25    pub show_line_numbers: bool,
26    /// Whether to show full (vs. relative) file paths.
27    pub full_paths: bool,
28    /// Whether to emit clickable OSC 8 terminal hyperlinks.
29    pub clickable_links: bool,
30    /// The root path scanned, used to compute relative paths and links.
31    pub base_path: Option<PathBuf>,
32    /// Whether to print the summary block after the main output.
33    pub show_summary: bool,
34    /// Whether to group items by tag instead of by file.
35    pub group_by_tag: bool,
36}
37
38impl Default for PrintOptions {
39    fn default() -> Self {
40        Self {
41            format: OutputFormat::Tree,
42            colored: true,
43            show_line_numbers: true,
44            full_paths: false,
45            clickable_links: true,
46            base_path: None,
47            show_summary: true,
48            group_by_tag: false,
49        }
50    }
51}
52
53#[cfg(test)]
54mod tests {
55    use super::*;
56
57    #[test]
58    fn default_options_use_tree_format_and_color() {
59        let options = PrintOptions::default();
60        assert_eq!(options.format, OutputFormat::Tree);
61        assert!(options.colored);
62        assert!(options.show_line_numbers);
63        assert!(!options.full_paths);
64        assert!(options.clickable_links);
65        assert!(options.base_path.is_none());
66        assert!(options.show_summary);
67        assert!(!options.group_by_tag);
68    }
69
70    #[test]
71    fn output_format_equality() {
72        assert_eq!(OutputFormat::Tree, OutputFormat::Tree);
73        assert_ne!(OutputFormat::Tree, OutputFormat::Json);
74    }
75}