smart-password-manager-cli 0.1.0

Command line interface for smart password management built on smartpasslib. Generate deterministic passwords from secret phrases without storing them.
use anyhow::Result;
use qrcode::{EcLevel, QrCode};

pub fn render(text: &str) {
    if let Err(e) = build_and_print(text) {
        eprintln!("error: failed to render QR: {e}");
    }
}

fn build_and_print(text: &str) -> Result<()> {
    let code = QrCode::with_error_correction_level(text.as_bytes(), EcLevel::M)?;
    let width = code.width();
    let modules = code.to_colors();

    let quiet = 2;
    let total = width + quiet * 2;

    let white = "\x1b[47m  \x1b[0m";
    let black = "\x1b[40m  \x1b[0m";

    for _ in 0..quiet {
        for _ in 0..total {
            print!("{white}");
        }
        println!();
    }

    for y in 0..width {
        for _ in 0..quiet {
            print!("{white}");
        }
        for x in 0..width {
            let idx = y * width + x;
            let dark = matches!(modules[idx], qrcode::types::Color::Dark);
            if dark {
                print!("{black}");
            } else {
                print!("{white}");
            }
        }
        for _ in 0..quiet {
            print!("{white}");
        }
        println!();
    }

    for _ in 0..quiet {
        for _ in 0..total {
            print!("{white}");
        }
        println!();
    }

    Ok(())
}