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 colored::Colorize;
|
||||||
use terminal_size;
|
use terminal_size;
|
||||||
|
use terminal_size::{Width, terminal_size as get_terminal_size};
|
||||||
use textwrap::{Options, fill};
|
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 {
|
pub struct Search {
|
||||||
query: String,
|
query: String,
|
||||||
|
|
@ -16,12 +19,12 @@ pub struct Search {
|
||||||
impl Search {
|
impl Search {
|
||||||
const BASE_URL: &str = "https://api.modrinth.com/v2";
|
const BASE_URL: &str = "https://api.modrinth.com/v2";
|
||||||
|
|
||||||
pub fn new(
|
pub fn new(query: String, offset: Option<u32>, limit: Option<u32>) -> Self {
|
||||||
query: String,
|
Search {
|
||||||
offset: Option<u32>,
|
query,
|
||||||
limit: Option<u32>,
|
offset,
|
||||||
) -> Self {
|
limit,
|
||||||
Search { query, offset, limit }
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub async fn run(&self) -> Result<(), Box<dyn Error>> {
|
pub async fn run(&self) -> Result<(), Box<dyn Error>> {
|
||||||
|
|
@ -57,7 +60,7 @@ impl Search {
|
||||||
.await?
|
.await?
|
||||||
.json()
|
.json()
|
||||||
.await?;
|
.await?;
|
||||||
|
|
||||||
self.print_results(&res);
|
self.print_results(&res);
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|
@ -66,12 +69,18 @@ impl Search {
|
||||||
fn print_results(&self, res: &SearchResult) {
|
fn print_results(&self, res: &SearchResult) {
|
||||||
println!(
|
println!(
|
||||||
"{}\n",
|
"{}\n",
|
||||||
format!("Found {} result{}", res.total_hits, if res.total_hits == 1 { "" } else { "s" })
|
format!(
|
||||||
.green()
|
"Found {} result{}",
|
||||||
.bold()
|
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() {
|
for (i, hit) in res.hits.iter().enumerate() {
|
||||||
let wrapped = fill(
|
let wrapped = fill(
|
||||||
|
|
|
||||||
|
|
@ -2,10 +2,10 @@ use serde::{Deserialize, Serialize};
|
||||||
|
|
||||||
#[derive(Serialize)]
|
#[derive(Serialize)]
|
||||||
pub struct SearchQueryParams {
|
pub struct SearchQueryParams {
|
||||||
pub query: String,
|
pub query: String,
|
||||||
pub facets: String,
|
pub facets: String,
|
||||||
pub offset: Option<u32>,
|
pub offset: Option<u32>,
|
||||||
pub limit: Option<u32>,
|
pub limit: Option<u32>,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Deserialize)]
|
#[derive(Deserialize)]
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,6 @@
|
||||||
use indicatif::{ProgressBar, ProgressStyle};
|
use indicatif::{ProgressBar, ProgressStyle};
|
||||||
|
use sha1::{Digest, Sha1};
|
||||||
|
use sha2::Sha512;
|
||||||
use std::{error::Error, future::Future};
|
use std::{error::Error, future::Future};
|
||||||
|
|
||||||
pub async fn with_spinner<F, Fut, T>(
|
pub async fn with_spinner<F, Fut, T>(
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue