mirror of
https://github.com/FliegendeWurst/ripgrep-all.git
synced 2024-11-24 04:14:57 +00:00
pdf: add page number prefix
This commit is contained in:
parent
ba58151dac
commit
cd1a26ffff
BIN
exampledir/test.tar.gz
Normal file
BIN
exampledir/test.tar.gz
Normal file
Binary file not shown.
Binary file not shown.
38
exampledir/wasteland.fb2
Normal file
38
exampledir/wasteland.fb2
Normal file
File diff suppressed because one or more lines are too long
@ -1,6 +1,7 @@
|
||||
use super::*;
|
||||
use lazy_static::lazy_static;
|
||||
use spawning::SpawningFileAdapter;
|
||||
use std::io::BufReader;
|
||||
use std::process::Command;
|
||||
|
||||
static EXTENSIONS: &[&str] = &["pdf"];
|
||||
@ -29,6 +30,20 @@ impl GetMetadata for PopplerAdapter {
|
||||
}
|
||||
}
|
||||
impl SpawningFileAdapter for PopplerAdapter {
|
||||
fn postproc(line_prefix: &str, inp: &mut Read, oup: &mut Write) -> Fallible<()> {
|
||||
// prepend Page X to each line
|
||||
let mut page = 1;
|
||||
for line in BufReader::new(inp).lines() {
|
||||
let mut line = line?;
|
||||
if line.contains("\x0c") {
|
||||
// page break
|
||||
line = line.replace("\x0c", "");
|
||||
page += 1;
|
||||
}
|
||||
oup.write_all(format!("{}Page {}: {}\n", line_prefix, page, line).as_bytes())?;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
fn get_exe(&self) -> &str {
|
||||
"pdftotext"
|
||||
}
|
||||
|
@ -53,7 +53,7 @@ impl FileAdapter for ZipAdapter {
|
||||
file.size(),
|
||||
file.compressed_size()
|
||||
);
|
||||
let line_prefix = &format!("{}{}:/", line_prefix, file.name().clone());
|
||||
let line_prefix = &format!("{}{}: ", line_prefix, file.name().clone());
|
||||
rga_preproc(
|
||||
AdaptInfo {
|
||||
filepath_hint: &file.sanitized_name(),
|
||||
|
@ -1,11 +1,8 @@
|
||||
use failure::{format_err, Error};
|
||||
use path_clean::PathClean;
|
||||
use rga::adapters::*;
|
||||
use rga::preproc::*;
|
||||
use rga::CachingWriter;
|
||||
use std::env;
|
||||
use std::fs::File;
|
||||
use std::path::PathBuf;
|
||||
use std::rc::Rc;
|
||||
|
||||
fn main() -> Result<(), Error> {
|
||||
let path = {
|
||||
@ -26,5 +23,11 @@ fn main() -> Result<(), Error> {
|
||||
line_prefix: "",
|
||||
};
|
||||
|
||||
rga_preproc(ai, Some(open_cache_db()?))
|
||||
let cache_db = match env::var("RGA_NO_CACHE") {
|
||||
Ok(ref s) if s.len() > 0 => Some(open_cache_db()?),
|
||||
Ok(_) => None,
|
||||
Err(_) => None,
|
||||
};
|
||||
|
||||
rga_preproc(ai, cache_db)
|
||||
}
|
||||
|
@ -14,14 +14,10 @@ fn main() -> std::io::Result<()> {
|
||||
"--list-adapters 'Lists all known adapters'",
|
||||
))
|
||||
.arg(Arg::from_usage("--adapters=[commaseparated] 'Change which adapters to use and in which priority order (descending)'").require_equals(true))
|
||||
.arg(Arg::from_usage("--no-cache 'Disable caching of results'"))
|
||||
.arg(Arg::from_usage("--rg-help 'Show help for ripgrep itself'"))
|
||||
.arg(Arg::from_usage("--rg-version 'Show version of ripgrep itself'"));
|
||||
app.p.create_help_and_version();
|
||||
println!("g={:#?},f={:#?}", app.p.groups, app.p.flags);
|
||||
for opt in app.p.opts() {
|
||||
println!("opt {:#?}", opt.s.long);
|
||||
}
|
||||
//
|
||||
let mut firstarg = true;
|
||||
let (our_args, mut passthrough_args): (Vec<OsString>, Vec<OsString>) = std::env::args_os()
|
||||
.partition(|os_arg| {
|
||||
@ -71,7 +67,16 @@ fn main() -> std::io::Result<()> {
|
||||
println!("Adapters:");
|
||||
for adapter in adapters {
|
||||
let meta = adapter.metadata();
|
||||
println!("{} v{}", meta.name, meta.version);
|
||||
let matchers = meta
|
||||
.matchers
|
||||
.iter()
|
||||
.map(|m| match m {
|
||||
Matcher::FileExtension(ext) => format!(".{}", ext),
|
||||
})
|
||||
.collect::<Vec<_>>()
|
||||
.join(", ");
|
||||
print!("{} v{}: {}", meta.name, meta.version, matchers);
|
||||
println!("");
|
||||
}
|
||||
return Ok(());
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user