eck 0.0.3

A fast, simple file & folder encryption manager, written in Rust
pub mod action;
pub mod browse;
pub mod help;
pub mod input;
pub mod parameters;
pub mod treatment;

use self::action::EnkryptitTuiAction;
use self::input::TuiInput;
use crate::VERSION;
use colored::*;

/// Show Params macro helper
#[allow(unused)] // It is not unused, but... Rust Analyser thinks that
macro_rules! show_params {
    ($kt:expr, $c:expr) => {
        println!("\n{}", "Current Parameters".cyan().bold());
        println!("   Key Type:    {}", format!("{:?}", $kt).yellow());
        println!("   Compression: {}", format!("{:?}", $c).yellow());
    };
}

/// Public function that launches the TUI
pub fn launch_ui(input: &impl TuiInput) {
    println!("\n{}", "Enkryptit".cyan().bold());
    println!("   Fast & Simple File Encryption Manager v0.0.{}", VERSION);

    loop {
        let choices = vec!["Browse", "Parameters", "Help", "Exit"];

        match input.select("What do you want to do?", &choices) {
            Ok(choice) if choice == "Exit" => {
                println!("\n{}", "Goodbye!".green());
                break;
            }

            Ok(value) => {
                if let Some(action) = EnkryptitTuiAction::from_string(&value)
                    && let Err(e) = action.execute(input)
                {
                    e.into_output().display();
                }
            }

            Err(_) => {
                // EnkryptitOutput::info("Selection cancelled").display(); replaced by :
                tracing::info!("Selection cancelled");
            }
        }
    }
}