use super::App;
use crate::components::global_search::SearchKind;
use rootle_provider::{ErrorKind, ProviderError, ProviderResult};
pub(super) mod lenses;
pub(super) mod lifecycle;
pub(super) mod search;
pub(super) mod tracker;
pub(crate) use tracker::Outstanding;
const BLOB_CAP: usize = 1024 * 1024;
fn fetch_blob_capped(
provider: &dyn rootle_provider::Provider,
repo: &rootle_provider::RepoId,
sha: &rootle_provider::Sha,
) -> ProviderResult<Vec<u8>> {
let bytes = provider.fetch_blob(repo, sha)?;
if bytes.len() > BLOB_CAP {
return Err(ProviderError::new(
ErrorKind::Provider,
format!(
"blob {sha} is {} KiB — over the 1 MiB preview cap",
bytes.len() / 1024
),
));
}
Ok(bytes)
}
impl App {
pub(super) fn finish_hits(
&self,
hits: Vec<crate::components::global_search::SearchHit>,
kind: SearchKind,
query: &str,
) -> Vec<crate::components::global_search::SearchHit> {
let mut hits: Vec<_> = hits
.into_iter()
.map(|hit| {
let lines = self.highlighter.highlight(&hit.path, &hit.preview_text());
hit.with_highlighted(lines)
})
.collect();
if kind == SearchKind::Grep {
crate::components::global_search::highlight_matches(
&mut hits,
query,
self.theme.semantic.search_match,
self.theme.semantic.crust,
);
}
hits
}
}