Skip to content

Commit

Permalink
The Struggle v2.0.1 | A New Utility and Refactoring/Formatting
Browse files Browse the repository at this point in the history
Merge pull request #9 from JosephLai241/dev
  • Loading branch information
JosephLai241 authored Aug 5, 2021
2 parents ecee15d + 31dc221 commit 212ff46
Show file tree
Hide file tree
Showing 15 changed files with 355 additions and 273 deletions.
14 changes: 0 additions & 14 deletions .travis.yml

This file was deleted.

4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "ts"
version = "2.0.0"
version = "2.0.1"
authors = ["Joseph Lai <jlai24142@gmail.com>"]
edition = "2018"
description = "A command-line tool for tracking your job applications"
Expand All @@ -9,7 +9,7 @@ license = "MIT"
readme = "README.md"
repository = "https://github.com/JosephLai241/The-Struggle"
categories = ["command-line-utilities"]
keywords = ["cli", "csv", "job application", "tracking"]
keywords = ["cli", "command-line tool", "csv", "job application", "tracking"]

[[bin]]
name = "ts"
Expand Down
211 changes: 132 additions & 79 deletions README.md

Large diffs are not rendered by default.

85 changes: 41 additions & 44 deletions src/add.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
use crate::mcsv;
use crate::model::Job;
use crate::prompt::display_prompt;

use ansi_term::*;
use chrono::prelude::*;
Expand All @@ -12,12 +13,12 @@ use std::process;
/// Get the job title at the company.
fn get_title(company: &String) -> String {
loop {
println!("{}", Style::new()
.bold()
.paint(format!(
"What is the title of the position you are applying for at {}?",
company
)));
display_prompt(
format!("{}", Style::new()
.bold()
.paint(format!("What is the title of the position you are applying for at {}? ", company))
)
);

let mut title = String::new();

Expand All @@ -26,14 +27,14 @@ fn get_title(company: &String) -> String {
let input = title.trim().to_string();

if !input.is_empty() {
return title.trim().to_string();
} else {
println!("{}\n",
Colour::Red.bold().paint("Please enter a job title.")
);
return title.trim().to_string();
} else {
println!("\n{}\n", Colour::Red.bold().paint("Please enter a job title."));
}
},
Err(e) => { println!("Error! {:?}", e); }
Err(e) => {
println!("Error! {:?}", e);
}
}
}
}
Expand All @@ -49,18 +50,18 @@ pub fn get_status() -> String {
];

let status_prompt = r#"
SELECT JOB STATUS
-------------------------
0: PENDING
1: IN PROGRESS
2: OFFER RECEIVED
3: HIRED
4: REJECTED
-------------------------"#;
SELECT JOB STATUS
-----------------
[0] PENDING
[1] IN PROGRESS
[2] OFFER RECEIVED
[3] HIRED
[4] REJECTED
"#;

loop {
println!("{}", Style::new().bold().paint(status_prompt));
display_prompt(format!("{}\n", Style::new().bold().paint(status_prompt)));

let mut status = String::new();

match io::stdin().read_line(&mut status) {
Expand All @@ -70,38 +71,35 @@ pub fn get_status() -> String {
if (0..5).contains(&status_int) {
return status_options[status_int].to_string();
} else {
println!("\n{}",
Colour::Red.bold().paint("Please select a valid status option.")
);
println!("\n{}", Colour::Red.bold().paint("Please select a valid status option."));
}
},
Err(_) => {
println!("\n{}",
Colour::Red.bold().paint("Please select a valid status option.")
);
println!("\n{}", Colour::Red.bold().paint("Please select a valid status option."));
}
}
},
Err(e) => { println!("Error! {:?}", e); }
Err(e) => {
println!("Error! {:?}", e);
}
}
}
}

/// Get notes (or enter through to leave notes blank) about the job listing.
fn get_notes() -> String {
println!("\n{}",
Style::new().bold().paint("(Optional) Enter any notes for this position:")
);
display_prompt(format!("\n{}", Style::new().bold().paint("[Optional] Enter any notes for this position: ")));

let mut notes = String::new();

match io::stdin().read_line(&mut notes) {
Ok(_) => { return notes.trim().to_string(); },
Err(e) => {
println!("Error! {:?}", e);
return "".to_string();
}
}

io::stdin().read_line(&mut notes)
.map_or_else(
|e| {
println!("Error! {:?}", e);
"".to_string()
},
|_| notes.trim().to_string()
)
}

/// Return the Job struct created from the date, job title, job application
Expand All @@ -121,16 +119,15 @@ pub fn add_job(company: String) -> Job {
/// Confirm addition of the new job listing to the spreadsheet.
pub fn confirm_add(new_job: Job) {
loop {
println!("\n{}", Style::new().bold().paint("Confirm? [Y/N]"));
display_prompt(format!("\n{}", Style::new().bold().paint("Confirm? [Y/N] ")));

let mut confirm_in = String::new();

match io::stdin().read_line(&mut confirm_in) {
Ok(_) => {
match confirm_in.trim().to_uppercase().as_str() {
"Y" => {
mcsv::write_new_job(&new_job)
.expect("Failed writing to spreadsheet");
mcsv::write_new_job(&new_job).expect("Failed to write to spreadsheet");
break;
},
"N" => {
Expand Down
13 changes: 11 additions & 2 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,26 @@ pub struct Args {
#[structopt(
short = "u",
long = "update",
help = "Update an existing job in the spreadsheet"
help = "Update an existing job"
)]
pub update: Option<String>,

/// Flag for deleting an existing job listing.
#[structopt(
short = "d",
long = "delete",
help = "Delete an existing job in the spreadsheet"
help = "Delete an existing job"
)]
pub delete: Option<String>,

/// Flag for searching for an existing job listing.
#[structopt(
short = "s",
long = "search",
help = "Search for an existing job"
)]
pub search: Option<String>,

/// Flag for listing all existing job listings.
#[structopt(
short = "l",
Expand Down Expand Up @@ -77,6 +85,7 @@ mod test_cli {
add: None,
update: None,
delete: None,
search: None,
list: false,
insights: false
}, args);
Expand Down
3 changes: 2 additions & 1 deletion src/delete.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
use crate::mcsv::overwrite;
use crate::model::Job;
use crate::prompt::display_prompt;

use ansi_term::*;

Expand Down Expand Up @@ -34,7 +35,7 @@ pub fn delete_job(job_index: u16, master: &mut BTreeMap<u16, Job>) {
loop {
let mut confirm_delete = String::new();

println!("\n{}", Style::new().bold().paint("Confirm deletion? [Y/N]"));
display_prompt(format!("\n{}", Style::new().bold().paint("Confirm deletion? [Y/N] ")));

match io::stdin().read_line(&mut confirm_delete) {
Ok(_) => {
Expand Down
45 changes: 28 additions & 17 deletions src/insights.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! Returning a PrettyTable of job application statistics.
use crate::format::format_table;
use crate::model::Job;
use crate::table::format_table;

use prettytable::*;

Expand Down Expand Up @@ -48,11 +48,21 @@ pub fn get_stats(master: BTreeMap<u16, Job>) -> JobStats {

for i in 0u16..master.len() as u16 {
match master.get_key_value(&i).unwrap().1.status.as_str() {
"PENDING" => { current_stats.pending += 1.0; },
"IN PROGRESS" => { current_stats.in_progress += 1.0; },
"OFFER RECEIVED" => { current_stats.offers += 1.0; },
"HIRED" => { current_stats.hired += 1.0; },
"REJECTED" => { current_stats.rejected += 1.0; },
"PENDING" => {
current_stats.pending += 1.0;
},
"IN PROGRESS" => {
current_stats.in_progress += 1.0;
},
"OFFER RECEIVED" => {
current_stats.offers += 1.0;
},
"HIRED" => {
current_stats.hired += 1.0;
},
"REJECTED" => {
current_stats.rejected += 1.0;
},
_ => ()
}
}
Expand All @@ -76,16 +86,14 @@ fn get_job_count(current_stats: &JobStats, insights: &mut Table, is_percent: boo
for stat in stats {
match is_percent {
true => {
table_values.push(Cell::new(
&format!("{:.2}% of all jobs", stat.0 * 100.0))
.style_spec(stat.1)
table_values.push(Cell::new(&format!("{:.2}% of all jobs", stat.0 * 100.0))
.style_spec(stat.1)
);
},
false => {
let plurality = if &stat.0 == &1.0 { "job" } else { "jobs" };
table_values.push(Cell::new(
&format!("{} {}", stat.0, plurality))
.style_spec(stat.1)
table_values.push(Cell::new(&format!("{} {}", stat.0, plurality))
.style_spec(stat.1)
);
}
}
Expand All @@ -99,10 +107,12 @@ fn get_job_count(current_stats: &JobStats, insights: &mut Table, is_percent: boo
pub fn display_insights(current_stats: JobStats) {
let mut insights = Table::new();

insights.set_titles(Row::new(vec![
Cell::new(&format!("{} TRACKED JOB APPLICATIONS", current_stats.total))
.style_spec("bicH5")
]));
insights.set_titles(Row::new(
vec![
Cell::new(&format!("{} TRACKED JOB APPLICATIONS", current_stats.total))
.style_spec("bicH5")
]
));

insights.add_row(
row![
Expand All @@ -112,7 +122,8 @@ pub fn display_insights(current_stats: JobStats) {
"OFFERS RECEIVED",
"HIRES",
"REJECTIONS"
]);
]
);

get_job_count(&current_stats, &mut insights, false);

Expand Down
30 changes: 17 additions & 13 deletions src/list.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! Listing stored job applications in a PrettyTable.
use crate::format::*;
use crate::model::Job;
use crate::table::*;

use prettytable::*;

Expand All @@ -10,15 +10,16 @@ use std::collections::BTreeMap;
/// Add each stored job listing as a row in the PrettyTable.
fn add_rows(job_table: &mut Table, master: BTreeMap<u16, Job>) {
for i in 0u16..master.len() as u16 {
let job = master.get_key_value(&i).unwrap().1;
let job_details = vec![
master.get_key_value(&i).unwrap().1.date.to_string(),
master.get_key_value(&i).unwrap().1.company.to_string(),
master.get_key_value(&i).unwrap().1.title.to_string(),
master.get_key_value(&i).unwrap().1.status.to_string(),
master.get_key_value(&i).unwrap().1.notes.to_string()
job.date.to_string(),
job.company.to_string(),
job.title.to_string(),
job.status.to_string(),
job.notes.to_string()
];

let style = set_color(&job_details[3]);
let style = set_color(&job.status);
let pt_row = convert_details(&job_details, &style);

job_table.add_row(Row::new(pt_row));
Expand All @@ -37,15 +38,18 @@ pub fn list_jobs(master: BTreeMap<u16, Job>) {
"JOB TITLE",
"STATUS",
"NOTES"
]);
]
);

add_rows(&mut job_table, master);

job_table.set_titles(Row::new(vec![
Cell::new(&format!("{} TRACKED JOB APPLICATIONS", job_table.len() - 1))
.style_spec("bicH5")
]));

job_table.set_titles(Row::new(
vec![
Cell::new(&format!("{} TRACKED JOB APPLICATIONS", job_table.len() - 1))
.style_spec("bicH5")
]
));

job_table.set_format(format_table());
job_table.printstd();
}
Loading

0 comments on commit 212ff46

Please sign in to comment.