toddi 0.2.2

A TODO focuser built on top of todo.txt
Documentation
use core::f64;

use indicatif::{ProgressBar, ProgressStyle};
use toddi::{Project, Task};

/// Displays Project status on the terminal.
pub fn display_project_status(project: Project) {
    let pos = project.done as u64;
    let len = project.todo as u64 + pos;

    let completion = pos as f64 / len as f64;
    let msg = if completion == 1.0 {
        "DONE"
    } else if completion > 0.9 {
        "Almost there!!"
    } else if completion > 0.5 {
        "Good Progress!"
    } else if completion > 0.2 {
        "Progressing"
    } else if completion > 0. {
        "Getting started"
    } else {
        ""
    };

    println!();
    if !project.name.is_empty() {
        display_project_name(&project.name);
    }
    if len > 0 {
        // There is at least 1 task
        let bar = ProgressBar::new(len);
        let progress_style = match ProgressStyle::with_template(
            "[{pos}/{len}] {bar:40.cyan/blue} {percent}% done - {msg}",
        ) {
            Ok(style) => style,
            Err(err) => panic!("cannot handle TemplateError from indicatif.\n{}", err),
        };
        bar.set_style(progress_style.progress_chars("##-"));
        bar.set_position(pos);
        bar.set_message(msg);
        bar.abandon();
        println!("todo: <<< {} >>>", project.current_task.description)
    } else {
        // There is a project, but no task.
        println!("This project contains no task as of now.")
    }
}

fn display_project_name(name: &str) {
    println!("==> Project {}", name.to_uppercase());
}

pub fn display_no_project_found(name: &str) {
    println!();
    println!("Project `{}` contains no task as of now.", name);
}

pub fn display_task(task: Task) {
    display_project_name(&task.project);
    println!("todo: <<< {} >>>", task.description);
}

pub fn display_empty_todo_list() {
    println!();
    println!("todo list is empty!")
}