1
0
mirror of https://github.com/BurntSushi/ripgrep.git synced 2025-07-16 22:42:20 +02:00

print hello for histogram

This commit is contained in:
Cabbache
2024-10-23 19:04:38 +02:00
parent fcb758a62d
commit e2659ff051
4 changed files with 16 additions and 6 deletions

View File

@ -1354,7 +1354,8 @@ impl Flag for Histogram {
fn update(&self, v: FlagValue, args: &mut LowArgs) -> anyhow::Result<()> { fn update(&self, v: FlagValue, args: &mut LowArgs) -> anyhow::Result<()> {
let binsize = convert::usize(&v.unwrap_value())?; let binsize = convert::usize(&v.unwrap_value())?;
args.histogram = if binsize == 0 { None } else { Some(binsize) }; args.histogram = binsize;
args.mode.update(Mode::Search(SearchMode::Histogram));
Ok(()) Ok(())
} }
} }

View File

@ -203,6 +203,7 @@ impl HiArgs {
SearchMode::FilesWithMatches SearchMode::FilesWithMatches
| SearchMode::FilesWithoutMatch | SearchMode::FilesWithoutMatch
| SearchMode::Count | SearchMode::Count
| SearchMode::Histogram
| SearchMode::CountMatches => return false, | SearchMode::CountMatches => return false,
SearchMode::JSON => return true, SearchMode::JSON => return true,
SearchMode::Standard => { SearchMode::Standard => {
@ -569,9 +570,10 @@ impl HiArgs {
SearchMode::FilesWithoutMatch => SummaryKind::PathWithoutMatch, SearchMode::FilesWithoutMatch => SummaryKind::PathWithoutMatch,
SearchMode::Count => SummaryKind::Count, SearchMode::Count => SummaryKind::Count,
SearchMode::CountMatches => SummaryKind::CountMatches, SearchMode::CountMatches => SummaryKind::CountMatches,
SearchMode::Histogram => SummaryKind::Histogram,
SearchMode::JSON => { SearchMode::JSON => {
return Printer::JSON(self.printer_json(wtr)) return Printer::JSON(self.printer_json(wtr))
} },
SearchMode::Standard => { SearchMode::Standard => {
return Printer::Standard(self.printer_standard(wtr)) return Printer::Standard(self.printer_standard(wtr))
} }

View File

@ -59,7 +59,7 @@ pub(crate) struct LowArgs {
pub(crate) globs: Vec<String>, pub(crate) globs: Vec<String>,
pub(crate) heading: Option<bool>, pub(crate) heading: Option<bool>,
pub(crate) hidden: bool, pub(crate) hidden: bool,
pub(crate) histogram: Option<usize>, pub(crate) histogram: usize,
pub(crate) hostname_bin: Option<PathBuf>, pub(crate) hostname_bin: Option<PathBuf>,
pub(crate) hyperlink_format: HyperlinkFormat, pub(crate) hyperlink_format: HyperlinkFormat,
pub(crate) iglobs: Vec<String>, pub(crate) iglobs: Vec<String>,
@ -210,6 +210,8 @@ pub(crate) enum SearchMode {
/// Show files containing at least one match and the total number of /// Show files containing at least one match and the total number of
/// matches. /// matches.
CountMatches, CountMatches,
/// Show a histogram of the matches
Histogram,
/// Print matches in a JSON lines format. /// Print matches in a JSON lines format.
JSON, JSON,
} }

View File

@ -71,6 +71,8 @@ pub enum SummaryKind {
/// If the `path` setting is enabled, then the count is prefixed by the /// If the `path` setting is enabled, then the count is prefixed by the
/// corresponding file path. /// corresponding file path.
CountMatches, CountMatches,
/// Show a histogram of the matches
Histogram,
/// Show only the file path if and only if a match was found. /// Show only the file path if and only if a match was found.
/// ///
/// This ignores the `path` setting and always shows the file path. If no /// This ignores the `path` setting and always shows the file path. If no
@ -101,7 +103,7 @@ impl SummaryKind {
match *self { match *self {
PathWithMatch | PathWithoutMatch => true, PathWithMatch | PathWithoutMatch => true,
Count | CountMatches | Quiet => false, Count | CountMatches | Histogram | Quiet => false,
} }
} }
@ -111,7 +113,7 @@ impl SummaryKind {
use self::SummaryKind::*; use self::SummaryKind::*;
match *self { match *self {
CountMatches => true, Histogram |CountMatches => true,
Count | PathWithMatch | PathWithoutMatch | Quiet => false, Count | PathWithMatch | PathWithoutMatch | Quiet => false,
} }
} }
@ -123,7 +125,7 @@ impl SummaryKind {
match *self { match *self {
PathWithMatch | Quiet => true, PathWithMatch | Quiet => true,
Count | CountMatches | PathWithoutMatch => false, Count | CountMatches | Histogram | PathWithoutMatch => false,
} }
} }
} }
@ -788,6 +790,9 @@ impl<'p, 's, M: Matcher, W: WriteColor> Sink for SummarySink<'p, 's, M, W> {
self.write_line_term(searcher)?; self.write_line_term(searcher)?;
} }
} }
SummaryKind::Histogram => {
self.write(b"hello")?;
},
SummaryKind::PathWithMatch => { SummaryKind::PathWithMatch => {
if self.match_count > 0 { if self.match_count > 0 {
self.write_path_line(searcher)?; self.write_path_line(searcher)?;