From 5c9bcfc2ec46d4c6442011b73f3c68f4f019f103 Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Tue, 4 Apr 2023 16:31:48 +0200 Subject: [PATCH 01/12] Add SQL to Makefile --- Makefile | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Makefile b/Makefile index 9f26d3a..1527be6 100644 --- a/Makefile +++ b/Makefile @@ -2,6 +2,10 @@ default: @echo "Building (Release)..."; cargo rustc --release --color=always -p schemsearch-cli -- -C target-feature=+avx2 +sql: + @echo "Building (Release)..."; + cargo rustc --release --color=always -p schemsearch-cli --features sql -- -C target-feature=+avx2 + debug: @echo "Building (Debug)..."; cargo build -p schemsearch-cli From 5607dcc72c98f12b0ea0692cb076e19d4b91d49e Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Tue, 4 Apr 2023 17:29:04 +0200 Subject: [PATCH 02/12] Print Progressbar to stdout --- schemsearch-cli/src/main.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/schemsearch-cli/src/main.rs b/schemsearch-cli/src/main.rs index f17f263..e63f62b 100644 --- a/schemsearch-cli/src/main.rs +++ b/schemsearch-cli/src/main.rs @@ -248,7 +248,7 @@ fn main() { let bar = ProgressBar::new(schematics.len() as u64); 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)); + bar.set_draw_target(ProgressDrawTarget::stdout_with_hz(5)); let matches: Vec = schematics.par_iter().progress_with(bar).map(|schem| { match schem { From e4b26755ea5169d1e0e1a9c5e65364d2b57f3819 Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Tue, 4 Apr 2023 17:34:12 +0200 Subject: [PATCH 03/12] Revert "Print Progressbar to stdout" This reverts commit 5607dcc72c98f12b0ea0692cb076e19d4b91d49e. --- schemsearch-cli/src/main.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/schemsearch-cli/src/main.rs b/schemsearch-cli/src/main.rs index e63f62b..f17f263 100644 --- a/schemsearch-cli/src/main.rs +++ b/schemsearch-cli/src/main.rs @@ -248,7 +248,7 @@ fn main() { let bar = ProgressBar::new(schematics.len() as u64); bar.set_style(ProgressStyle::with_template("[{elapsed}, ETA: {eta}] {wide_bar} {pos}/{len} {per_sec}").unwrap()); - bar.set_draw_target(ProgressDrawTarget::stdout_with_hz(5)); + bar.set_draw_target(ProgressDrawTarget::stderr_with_hz(5)); let matches: Vec = schematics.par_iter().progress_with(bar).map(|schem| { match schem { From 64158cf45b5b5ac4fc8d95c569566a4316844e60 Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Tue, 4 Apr 2023 21:44:43 +0200 Subject: [PATCH 04/12] Remove Timer from Progressbar --- schemsearch-cli/src/main.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/schemsearch-cli/src/main.rs b/schemsearch-cli/src/main.rs index f17f263..d2955a5 100644 --- a/schemsearch-cli/src/main.rs +++ b/schemsearch-cli/src/main.rs @@ -248,7 +248,7 @@ fn main() { let bar = ProgressBar::new(schematics.len() as u64); 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)); + //bar.set_draw_target(ProgressDrawTarget::stderr_with_hz(5)); let matches: Vec = schematics.par_iter().progress_with(bar).map(|schem| { match schem { From 80eeaad5d5df17d6a502ad56c3c992358ad0093a Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Tue, 4 Apr 2023 22:38:02 +0200 Subject: [PATCH 05/12] Add output for machines --- schemsearch-cli/src/main.rs | 18 ++++++++++++-- schemsearch-cli/src/sinks.rs | 4 ++-- schemsearch-cli/src/stderr.rs | 44 +++++++++++++++++++++++++++++++++++ 3 files changed, 62 insertions(+), 4 deletions(-) create mode 100644 schemsearch-cli/src/stderr.rs diff --git a/schemsearch-cli/src/main.rs b/schemsearch-cli/src/main.rs index d2955a5..6dbe948 100644 --- a/schemsearch-cli/src/main.rs +++ b/schemsearch-cli/src/main.rs @@ -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::().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::().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::("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::("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 = schematics.par_iter().progress_with(bar).map(|schem| { match schem { diff --git a/schemsearch-cli/src/sinks.rs b/schemsearch-cli/src/sinks.rs index e19a2f8..6c81f59 100644 --- a/schemsearch-cli/src/sinks.rs +++ b/schemsearch-cli/src/sinks.rs @@ -49,8 +49,8 @@ impl FromStr for OutputSink { impl OutputSink { pub fn output(&self) -> Box { 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())) } } diff --git a/schemsearch-cli/src/stderr.rs b/schemsearch-cli/src/stderr.rs new file mode 100644 index 0000000..8292e0e --- /dev/null +++ b/schemsearch-cli/src/stderr.rs @@ -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() + } +} \ No newline at end of file From e7c1fd1ef722334f8503f02bdbf0a2c69466fb4e Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Wed, 5 Apr 2023 00:33:21 +0200 Subject: [PATCH 06/12] Fixing Something? --- schemsearch-lib/src/lib.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/schemsearch-lib/src/lib.rs b/schemsearch-lib/src/lib.rs index c140532..98a512e 100644 --- a/schemsearch-lib/src/lib.rs +++ b/schemsearch-lib/src/lib.rs @@ -61,7 +61,7 @@ pub fn search( let air_id = if search_behavior.ignore_air || search_behavior.air_as_any { pattern_schem.palette.get("minecraft:air").unwrap_or(&-1) } else { &-1}; - let pattern_blocks = (pattern_schem.width * pattern_schem.height * pattern_schem.length) as f32; + let pattern_blocks = pattern_data.len() as f32; let pattern_width = pattern_schem.width as usize; let pattern_height = pattern_schem.height as usize; From 2a112ac49ca94b4f59c0059d797144d5dc2c7893 Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Wed, 5 Apr 2023 02:43:28 +0200 Subject: [PATCH 07/12] Add Output Limit --- schemsearch-cli/src/main.rs | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/schemsearch-cli/src/main.rs b/schemsearch-cli/src/main.rs index 6dbe948..dc86ff5 100644 --- a/schemsearch-cli/src/main.rs +++ b/schemsearch-cli/src/main.rs @@ -150,6 +150,15 @@ fn main() { .default_value("0") .value_parser(|s: &str| s.parse::().map_err(|e| e.to_string())) ) + .arg( + Arg::new("limit") + .help("The maximum number of matches to return [0 = Unlimited]") + .short('l') + .long("limit") + .action(ArgAction::Set) + .default_value("50") + .value_parser(|s: &str| s.parse::().map_err(|e| e.to_string())), + ) .about("Searches for a pattern in a schematic") .bin_name("schemsearch"); @@ -264,6 +273,8 @@ fn main() { bar.set_draw_target(ProgressDrawTarget::term_like(Box::new(MaschineStdErr { size: term_size }))) } + let max_matching = *matches.get_one::("limit").expect("Could not get max-matching"); + let matches: Vec = schematics.par_iter().progress_with(bar).map(|schem| { match schem { SchematicSupplierType::PATH(schem) => { @@ -300,13 +311,19 @@ fn main() { } }).collect(); - for matching in matches { + let mut matches_count = 0; + + 'outer: for matching in matches { let schem_name = matching.name; let matching = matching.matches; for x in matching { for out in &mut output { write!(out.1, "{}", out.0.found_match(&schem_name, x)).unwrap(); } + matches_count += 1; + if max_matching != 0 && matches_count >= max_matching { + break 'outer; + } } } From fb8f93561759661070de07205683b486346ee1d8 Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Wed, 5 Apr 2023 13:05:15 +0200 Subject: [PATCH 08/12] Fix Cache and Bump Version --- .github/workflows/master-build.yml | 22 ++++++++++++---------- .github/workflows/release-build.yml | 11 ++++++----- schemsearch-cli/Cargo.toml | 2 +- schemsearch-files/Cargo.toml | 2 +- schemsearch-lib/Cargo.toml | 2 +- 5 files changed, 21 insertions(+), 18 deletions(-) diff --git a/.github/workflows/master-build.yml b/.github/workflows/master-build.yml index 32ef5d5..d1f11d4 100644 --- a/.github/workflows/master-build.yml +++ b/.github/workflows/master-build.yml @@ -19,13 +19,14 @@ jobs: - name: Cache Cargo modules id: cache-cargo uses: actions/cache@v3 - env: - cache-name: cache-cargo-target-debug + continue-on-error: false with: - path: target - key: ${{ runner.os }}-${{ env.cache-name }}-${{ hashFiles('**/Cargo.lock') }} + path: | + ~/.cargo/registry + ~/.cargo/git + key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }} restore-keys: | - ${{ runner.os }}-${{ env.cache-name }}- + ${{ runner.os }}-cargo- - name: Build run: make debug - name: Run tests @@ -38,13 +39,14 @@ jobs: - name: Cache Cargo modules id: cache-cargo uses: actions/cache@v3 - env: - cache-name: cache-cargo-target-release + continue-on-error: false with: - path: target - key: ${{ runner.os }}-${{ env.cache-name }}-${{ hashFiles('**/Cargo.lock') }} + path: | + ~/.cargo/registry + ~/.cargo/git + key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }} restore-keys: | - ${{ runner.os }}-${{ env.cache-name }}- + ${{ runner.os }}-cargo- - name: Build run: make - name: Upload a Build Artifact diff --git a/.github/workflows/release-build.yml b/.github/workflows/release-build.yml index 301b087..7a9fcb0 100644 --- a/.github/workflows/release-build.yml +++ b/.github/workflows/release-build.yml @@ -22,13 +22,14 @@ jobs: - name: Cache Cargo modules id: cache-cargo uses: actions/cache@v3 - env: - cache-name: cache-cargo-target-release + continue-on-error: false with: - path: target - key: ${{ runner.os }}-${{ env.cache-name }}-${{ hashFiles('**/Cargo.lock') }} + path: | + ~/.cargo/registry + ~/.cargo/git + key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }} restore-keys: | - ${{ runner.os }}-${{ env.cache-name }}- + ${{ runner.os }}-cargo- - name: Build run: make - name: Create Tarball diff --git a/schemsearch-cli/Cargo.toml b/schemsearch-cli/Cargo.toml index b9e98f0..85a7786 100644 --- a/schemsearch-cli/Cargo.toml +++ b/schemsearch-cli/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "schemsearch-cli" -version = "0.1.1" +version = "0.1.2" edition = "2021" license = "AGPL-3.0-or-later" diff --git a/schemsearch-files/Cargo.toml b/schemsearch-files/Cargo.toml index 395f9fe..368fc4f 100644 --- a/schemsearch-files/Cargo.toml +++ b/schemsearch-files/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "schemsearch-files" -version = "0.1.1" +version = "0.1.2" edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html diff --git a/schemsearch-lib/Cargo.toml b/schemsearch-lib/Cargo.toml index 1c340ef..559e62c 100644 --- a/schemsearch-lib/Cargo.toml +++ b/schemsearch-lib/Cargo.toml @@ -1,6 +1,6 @@ [package] name = "schemsearch-lib" -version = "0.1.1" +version = "0.1.2" edition = "2021" license = "AGPL-3.0-or-later" From 00e3d6fd0ff82a68191024ad8dddade807e4e755 Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Wed, 5 Apr 2023 13:07:14 +0200 Subject: [PATCH 09/12] Fix Cache --- .github/workflows/master-build.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/master-build.yml b/.github/workflows/master-build.yml index d1f11d4..cfb5ad2 100644 --- a/.github/workflows/master-build.yml +++ b/.github/workflows/master-build.yml @@ -33,6 +33,8 @@ jobs: run: cargo test --verbose -p schemsearch-lib build-release: + needs: + - build runs-on: ubuntu-latest steps: - uses: actions/checkout@v3 From 14866df17db73a35db0007a1c16e7ce664d55c6a Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Thu, 13 Apr 2023 00:20:53 +0200 Subject: [PATCH 10/12] Create dependabot.yml --- .github/dependabot.yml | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 .github/dependabot.yml diff --git a/.github/dependabot.yml b/.github/dependabot.yml new file mode 100644 index 0000000..b8e9e3d --- /dev/null +++ b/.github/dependabot.yml @@ -0,0 +1,6 @@ +version: 2 +updates: + - package-ecosystem: "Cargo" + directory: "/" + schedule: + interval: "weekly" From 733aaa9e725df2e3f387494c9ce127b012439fe1 Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Thu, 13 Apr 2023 00:21:24 +0200 Subject: [PATCH 11/12] Update dependabot.yml --- .github/dependabot.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/dependabot.yml b/.github/dependabot.yml index b8e9e3d..53f8242 100644 --- a/.github/dependabot.yml +++ b/.github/dependabot.yml @@ -1,6 +1,6 @@ version: 2 updates: - - package-ecosystem: "Cargo" + - package-ecosystem: "cargo" directory: "/" schedule: interval: "weekly" From 3f20cbc17f61190ebda30e04629b25c9ab1d317f Mon Sep 17 00:00:00 2001 From: Chaoscaot Date: Thu, 13 Apr 2023 00:25:42 +0200 Subject: [PATCH 12/12] Create CODE_OF_CONDUCT.md --- CODE_OF_CONDUCT.md | 128 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 128 insertions(+) create mode 100644 CODE_OF_CONDUCT.md diff --git a/CODE_OF_CONDUCT.md b/CODE_OF_CONDUCT.md new file mode 100644 index 0000000..4f0ecd0 --- /dev/null +++ b/CODE_OF_CONDUCT.md @@ -0,0 +1,128 @@ +# Contributor Covenant Code of Conduct + +## Our Pledge + +We as members, contributors, and leaders pledge to make participation in our +community a harassment-free experience for everyone, regardless of age, body +size, visible or invisible disability, ethnicity, sex characteristics, gender +identity and expression, level of experience, education, socio-economic status, +nationality, personal appearance, race, religion, or sexual identity +and orientation. + +We pledge to act and interact in ways that contribute to an open, welcoming, +diverse, inclusive, and healthy community. + +## Our Standards + +Examples of behavior that contributes to a positive environment for our +community include: + +* Demonstrating empathy and kindness toward other people +* Being respectful of differing opinions, viewpoints, and experiences +* Giving and gracefully accepting constructive feedback +* Accepting responsibility and apologizing to those affected by our mistakes, + and learning from the experience +* Focusing on what is best not just for us as individuals, but for the + overall community + +Examples of unacceptable behavior include: + +* The use of sexualized language or imagery, and sexual attention or + advances of any kind +* Trolling, insulting or derogatory comments, and personal or political attacks +* Public or private harassment +* Publishing others' private information, such as a physical or email + address, without their explicit permission +* Other conduct which could reasonably be considered inappropriate in a + professional setting + +## Enforcement Responsibilities + +Community leaders are responsible for clarifying and enforcing our standards of +acceptable behavior and will take appropriate and fair corrective action in +response to any behavior that they deem inappropriate, threatening, offensive, +or harmful. + +Community leaders have the right and responsibility to remove, edit, or reject +comments, commits, code, wiki edits, issues, and other contributions that are +not aligned to this Code of Conduct, and will communicate reasons for moderation +decisions when appropriate. + +## Scope + +This Code of Conduct applies within all community spaces, and also applies when +an individual is officially representing the community in public spaces. +Examples of representing our community include using an official e-mail address, +posting via an official social media account, or acting as an appointed +representative at an online or offline event. + +## Enforcement + +Instances of abusive, harassing, or otherwise unacceptable behavior may be +reported to the community leaders responsible for enforcement at +chaoscaot@zohomail.eu. +All complaints will be reviewed and investigated promptly and fairly. + +All community leaders are obligated to respect the privacy and security of the +reporter of any incident. + +## Enforcement Guidelines + +Community leaders will follow these Community Impact Guidelines in determining +the consequences for any action they deem in violation of this Code of Conduct: + +### 1. Correction + +**Community Impact**: Use of inappropriate language or other behavior deemed +unprofessional or unwelcome in the community. + +**Consequence**: A private, written warning from community leaders, providing +clarity around the nature of the violation and an explanation of why the +behavior was inappropriate. A public apology may be requested. + +### 2. Warning + +**Community Impact**: A violation through a single incident or series +of actions. + +**Consequence**: A warning with consequences for continued behavior. No +interaction with the people involved, including unsolicited interaction with +those enforcing the Code of Conduct, for a specified period of time. This +includes avoiding interactions in community spaces as well as external channels +like social media. Violating these terms may lead to a temporary or +permanent ban. + +### 3. Temporary Ban + +**Community Impact**: A serious violation of community standards, including +sustained inappropriate behavior. + +**Consequence**: A temporary ban from any sort of interaction or public +communication with the community for a specified period of time. No public or +private interaction with the people involved, including unsolicited interaction +with those enforcing the Code of Conduct, is allowed during this period. +Violating these terms may lead to a permanent ban. + +### 4. Permanent Ban + +**Community Impact**: Demonstrating a pattern of violation of community +standards, including sustained inappropriate behavior, harassment of an +individual, or aggression toward or disparagement of classes of individuals. + +**Consequence**: A permanent ban from any sort of public interaction within +the community. + +## Attribution + +This Code of Conduct is adapted from the [Contributor Covenant][homepage], +version 2.0, available at +https://www.contributor-covenant.org/version/2/0/code_of_conduct.html. + +Community Impact Guidelines were inspired by [Mozilla's code of conduct +enforcement ladder](https://github.com/mozilla/diversity). + +[homepage]: https://www.contributor-covenant.org + +For answers to common questions about this code of conduct, see the FAQ at +https://www.contributor-covenant.org/faq. Translations are available at +https://www.contributor-covenant.org/translations.