diff --git a/src/commands/search.rs b/src/commands/search.rs index 854ba13..2b5b335 100644 --- a/src/commands/search.rs +++ b/src/commands/search.rs @@ -2,10 +2,13 @@ use std::error::Error; use colored::Colorize; use terminal_size; +use terminal_size::{Width, terminal_size as get_terminal_size}; use textwrap::{Options, fill}; -use terminal_size::{terminal_size as get_terminal_size, Width}; -use crate::models::{config::Config, search::{SearchQueryParams, SearchResult}}; +use crate::models::{ + config::Config, + search::{SearchQueryParams, SearchResult}, +}; pub struct Search { query: String, @@ -16,12 +19,12 @@ pub struct Search { impl Search { const BASE_URL: &str = "https://api.modrinth.com/v2"; - pub fn new( - query: String, - offset: Option, - limit: Option, - ) -> Self { - Search { query, offset, limit } + pub fn new(query: String, offset: Option, limit: Option) -> Self { + Search { + query, + offset, + limit, + } } pub async fn run(&self) -> Result<(), Box> { @@ -57,7 +60,7 @@ impl Search { .await? .json() .await?; - + self.print_results(&res); Ok(()) @@ -66,12 +69,18 @@ impl Search { fn print_results(&self, res: &SearchResult) { println!( "{}\n", - format!("Found {} result{}", res.total_hits, if res.total_hits == 1 { "" } else { "s" }) - .green() - .bold() + format!( + "Found {} result{}", + res.total_hits, + if res.total_hits == 1 { "" } else { "s" } + ) + .green() + .bold() ); - let width = get_terminal_size().map(|(Width(w), _)| w as usize).unwrap_or(80); + let width = get_terminal_size() + .map(|(Width(w), _)| w as usize) + .unwrap_or(80); for (i, hit) in res.hits.iter().enumerate() { let wrapped = fill( diff --git a/src/models/search.rs b/src/models/search.rs index 8fa597c..11929d5 100644 --- a/src/models/search.rs +++ b/src/models/search.rs @@ -2,10 +2,10 @@ use serde::{Deserialize, Serialize}; #[derive(Serialize)] pub struct SearchQueryParams { - pub query: String, - pub facets: String, - pub offset: Option, - pub limit: Option, + pub query: String, + pub facets: String, + pub offset: Option, + pub limit: Option, } #[derive(Deserialize)] diff --git a/src/utils.rs b/src/utils.rs index 9f8e106..61b5a92 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -1,4 +1,6 @@ use indicatif::{ProgressBar, ProgressStyle}; +use sha1::{Digest, Sha1}; +use sha2::Sha512; use std::{error::Error, future::Future}; pub async fn with_spinner(