style: run cargo fmt
This commit is contained in:
parent
6185a3123a
commit
809151b28c
3 changed files with 28 additions and 17 deletions
|
|
@ -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<u32>,
|
||||
limit: Option<u32>,
|
||||
) -> Self {
|
||||
Search { query, offset, limit }
|
||||
pub fn new(query: String, offset: Option<u32>, limit: Option<u32>) -> Self {
|
||||
Search {
|
||||
query,
|
||||
offset,
|
||||
limit,
|
||||
}
|
||||
}
|
||||
|
||||
pub async fn run(&self) -> Result<(), Box<dyn Error>> {
|
||||
|
|
@ -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(
|
||||
|
|
|
|||
|
|
@ -2,10 +2,10 @@ use serde::{Deserialize, Serialize};
|
|||
|
||||
#[derive(Serialize)]
|
||||
pub struct SearchQueryParams {
|
||||
pub query: String,
|
||||
pub facets: String,
|
||||
pub offset: Option<u32>,
|
||||
pub limit: Option<u32>,
|
||||
pub query: String,
|
||||
pub facets: String,
|
||||
pub offset: Option<u32>,
|
||||
pub limit: Option<u32>,
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
|
|
|
|||
|
|
@ -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<F, Fut, T>(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue