sift_core/search/output/
mod.rs1pub mod error;
2pub mod format;
3pub mod mode;
4pub mod passthru;
5pub mod style;
6
7use mode::{CandidateCoverage, OutputEmission, SearchMode, ZeroCountMode};
8use passthru::PassthruMode;
9use style::{SearchLineStyle, SearchRecordStyle};
10
11#[derive(Debug, Clone, Copy, PartialEq, Eq, Default)]
12pub enum SearchOutputFormat {
13 #[default]
14 Text,
15 Json,
16}
17
18#[derive(Debug, Clone, Copy, PartialEq, Eq)]
19pub struct SearchOutput {
20 pub format: SearchOutputFormat,
21 pub mode: SearchMode,
22 pub emission: OutputEmission,
23 pub lines: SearchLineStyle,
24 pub records: SearchRecordStyle,
25 pub passthru: PassthruMode,
26 pub include_zero: ZeroCountMode,
27}
28
29impl Default for SearchOutput {
30 fn default() -> Self {
31 Self {
32 format: SearchOutputFormat::Text,
33 mode: SearchMode::Standard,
34 emission: OutputEmission::Normal,
35 lines: SearchLineStyle::default(),
36 records: SearchRecordStyle::default(),
37 passthru: PassthruMode::Disabled,
38 include_zero: ZeroCountMode::Omit,
39 }
40 }
41}
42
43impl SearchOutput {
44 #[must_use]
46 pub(crate) const fn candidate_coverage(self) -> CandidateCoverage {
47 match self.mode {
48 SearchMode::Count | SearchMode::FilesWithoutMatch => CandidateCoverage::Complete,
49 SearchMode::CountMatches if matches!(self.include_zero, ZeroCountMode::Include) => {
50 CandidateCoverage::Complete
51 }
52 SearchMode::Standard
53 | SearchMode::OnlyMatching
54 | SearchMode::CountMatches
55 | SearchMode::FilesWithMatches => CandidateCoverage::Narrowed,
56 }
57 }
58}
59
60#[cfg(test)]
61mod tests {
62 use super::*;
63
64 #[test]
65 fn search_output_defaults() {
66 let output = SearchOutput::default();
67 assert_eq!(output.format, SearchOutputFormat::Text);
68 assert_eq!(output.mode, SearchMode::Standard);
69 assert_eq!(output.emission, OutputEmission::Normal);
70 assert!(matches!(output.passthru, PassthruMode::Disabled));
71 assert!(matches!(output.include_zero, ZeroCountMode::Omit));
72 }
73}