Skip to content

Commit

Permalink
New Progress Bar Feature
Browse files Browse the repository at this point in the history
  • Loading branch information
CHRISCARLON committed Sep 18, 2024
1 parent b0e7ffd commit 022ed6c
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 21 deletions.
1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ reqwest = { version = "0.12", features = ["blocking", "json"] }
colored = "2.1.0"
serde = "1.0.207"
serde_json = "1.0.124"
indicatif = "0.17.8"

[lib]
name = "nebby"
Expand Down
1 change: 0 additions & 1 deletion src/api/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// src/reqwest_functions.rs
use colored::Colorize;
use reqwest::blocking::get;
use serde_json::Value;
Expand Down
1 change: 0 additions & 1 deletion src/bytes/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// src/file_bytes.rs
use reqwest::blocking::get;
use std::io::Read;

Expand Down
1 change: 0 additions & 1 deletion src/excel/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
// src/excel_file_functions.rs
use calamine::{DataType, Reader, Xlsx};
use colored::Colorize;
use comfy_table::{Attribute, Cell, Color, Table};
Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// src/lib.rs
pub mod api;
pub mod bytes;
pub mod excel;
pub mod utils;
39 changes: 22 additions & 17 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
// src/main.rs
mod api;
mod bytes;
mod excel;
mod utils;
use api::simple_api_get_reqwest;
use bytes::view_bytes;
use clap::{Parser, Subcommand};
use colored::Colorize;
use excel::{
analyze_excel_formatting, display_remote_basic_info,
display_remote_basic_info_specify_header_idx, excel_quick_view, fetch_remote_file,
};
use utils::create_progress_bar;

#[derive(Parser, Debug)]
#[command(author = "Christopher Carlon", version = "0.1.1", about = "Nebby - quickly review basic information about remote xlsx files and API GET requests", long_about = None)]
Expand Down Expand Up @@ -69,43 +69,48 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {

fn process_json(url: &str) -> Result<(), Box<dyn std::error::Error>> {
validate_url(url)?;
println!("{}", "Processing JSON...".blue());
simple_api_get_reqwest(url)
let pb = create_progress_bar("Processing JSON...");
let result = simple_api_get_reqwest(url);
pb.finish_with_message("JSON Processed");
result
}

fn process_excel(url: &str, operation: &str) -> Result<(), Box<dyn std::error::Error>> {
validate_url(url)?;
println!("{}", format!("Processing Excel {}...", operation).blue());
let pb = create_progress_bar(&format!("Processing Excel {}...", operation));
let bytes = fetch_remote_file(url)?;
match operation {

let result = match operation {
"basic info" => display_remote_basic_info(bytes),
"formatting" => analyze_excel_formatting(bytes),
"quick view" => excel_quick_view(bytes),
_ => Err("Unknown operation".into()),
}
};

pb.finish_with_message("Excel Processed");
result
}

fn process_excel_with_header(
url: &str,
header_index: usize,
) -> Result<(), Box<dyn std::error::Error>> {
validate_url(url)?;
println!(
"{}",
format!(
"Processing Excel with header set at INDEX {}...",
header_index
)
.blue()
);
let pb = create_progress_bar(&format!(
"Processing Excel with header set at INDEX {}...",
header_index
));
let bytes = fetch_remote_file(url)?;
display_remote_basic_info_specify_header_idx(bytes, header_index)
let result = display_remote_basic_info_specify_header_idx(bytes, header_index);
pb.finish_with_message("Excel processing with header complete");
result
}

fn process_view_bytes(url: &str) -> Result<(), Box<dyn std::error::Error>> {
validate_url(url)?;
println!("{}", "Viewing first 100 bytes...".blue());
let pb = create_progress_bar("Viewing first 100 bytes...");
let bytes = view_bytes(url)?;
pb.finish_with_message("Bytes Processed");
println!("First 100 bytes:");
for (i, byte) in bytes.iter().enumerate() {
print!("{:02X} ", byte);
Expand Down
15 changes: 15 additions & 0 deletions src/utils/mod.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
use indicatif::{ProgressBar, ProgressStyle};
use std::time::Duration;

pub fn create_progress_bar(message: &str) -> ProgressBar {
let pb = ProgressBar::new_spinner();
pb.set_style(
ProgressStyle::default_bar()
.tick_chars("⣾⣽⣻⢿⡿⣟⣯⣷")
.template("{spinner:.bright_yellow} {msg:.bright_yellow}")
.unwrap(),
);
pb.set_message(message.to_string());
pb.enable_steady_tick(Duration::from_millis(100));
pb
}

0 comments on commit 022ed6c

Please sign in to comment.