1
0
Mirror von https://github.com/Chaoscaot/schemsearch synchronisiert 2024-11-08 05:10:09 +01:00

Add output for machines

Dieser Commit ist enthalten in:
Chaoscaot 2023-04-04 22:38:02 +02:00
Ursprung 64158cf45b
Commit 80eeaad5d5
3 geänderte Dateien mit 62 neuen und 4 gelöschten Zeilen

Datei anzeigen

@ -18,6 +18,7 @@
mod types;
mod json_output;
mod sinks;
mod stderr;
use std::fmt::Debug;
use std::io::Write;
@ -40,6 +41,7 @@ use crate::types::SqlSchematicSupplier;
use indicatif::*;
use schemsearch_files::Schematic;
use crate::sinks::{OutputFormat, OutputSink};
use crate::stderr::MaschineStdErr;
fn main() {
#[allow(unused_mut)]
@ -139,6 +141,15 @@ fn main() {
.default_value("0")
.value_parser(|s: &str| s.parse::<usize>().map_err(|e| e.to_string())),
)
.arg(
Arg::new("machine")
.help("Output for machines")
.short('m')
.long("machine")
.action(ArgAction::Set)
.default_value("0")
.value_parser(|s: &str| s.parse::<u16>().map_err(|e| e.to_string()))
)
.about("Searches for a pattern in a schematic")
.bin_name("schemsearch");
@ -246,9 +257,12 @@ fn main() {
ThreadPoolBuilder::new().num_threads(*matches.get_one::<usize>("threads").expect("Could not get threads")).build_global().unwrap();
let bar = ProgressBar::new(schematics.len() as u64);
let bar = ProgressBar::new(schematics.len() as u64); // "maschine"
bar.set_style(ProgressStyle::with_template("[{elapsed}, ETA: {eta}] {wide_bar} {pos}/{len} {per_sec}").unwrap());
//bar.set_draw_target(ProgressDrawTarget::stderr_with_hz(5));
let term_size = *matches.get_one::<u16>("machine").expect("Could not get machine");
if term_size != 0 {
bar.set_draw_target(ProgressDrawTarget::term_like(Box::new(MaschineStdErr { size: term_size })))
}
let matches: Vec<SearchResult> = schematics.par_iter().progress_with(bar).map(|schem| {
match schem {

Datei anzeigen

@ -49,8 +49,8 @@ impl FromStr for OutputSink {
impl OutputSink {
pub fn output(&self) -> Box<dyn Write> {
match self {
OutputSink::Stdout => Box::new(std::io::stdout().lock()),
OutputSink::Stderr => Box::new(std::io::stderr().lock()),
OutputSink::Stdout => Box::new(std::io::stdout()),
OutputSink::Stderr => Box::new(std::io::stderr()),
OutputSink::File(path) => Box::new(BufWriter::new(File::create(path).unwrap()))
}
}

Datei anzeigen

@ -0,0 +1,44 @@
use std::fmt::Debug;
use std::io::Write;
use indicatif::TermLike;
#[derive(Debug)]
pub struct MaschineStdErr { pub(crate) size: u16}
impl TermLike for MaschineStdErr {
fn width(&self) -> u16 {
self.size
}
fn move_cursor_up(&self, _: usize) -> std::io::Result<()> {
Ok(())
}
fn move_cursor_down(&self, _: usize) -> std::io::Result<()> {
Ok(())
}
fn move_cursor_right(&self, _: usize) -> std::io::Result<()> {
Ok(())
}
fn move_cursor_left(&self, _: usize) -> std::io::Result<()> {
Ok(())
}
fn write_line(&self, s: &str) -> std::io::Result<()> {
writeln!(std::io::stderr(), "{}", s)
}
fn write_str(&self, s: &str) -> std::io::Result<()> {
write!(std::io::stderr(), "{}", s)
}
fn clear_line(&self) -> std::io::Result<()> {
Ok(())
}
fn flush(&self) -> std::io::Result<()> {
std::io::stderr().flush()
}
}