envelope_cli/setup/steps/
categories.rs1use std::io::{self, Write};
6
7use crate::error::EnvelopeResult;
8
9#[derive(Debug, Clone, Copy, PartialEq, Eq)]
11pub enum CategoryChoice {
12 UseDefaults,
14 Customize,
16 Empty,
18}
19
20pub struct CategoriesSetupResult {
22 pub choice: CategoryChoice,
24}
25
26pub struct CategoriesSetupStep;
28
29impl CategoriesSetupStep {
30 pub fn run() -> EnvelopeResult<CategoriesSetupResult> {
32 println!();
33 println!("Step 2: Category Groups");
34 println!("=======================");
35 println!();
36 println!("EnvelopeCLI organizes your budget into category groups.");
37 println!();
38 println!("Default groups include:");
39 println!(" - Bills: Rent/Mortgage, Electric, Water, Internet, Phone, Insurance");
40 println!(" - Needs: Groceries, Transportation, Medical, Household");
41 println!(" - Wants: Dining Out, Entertainment, Shopping, Subscriptions");
42 println!(" - Savings: Emergency Fund, Vacation, Large Purchases");
43 println!();
44 println!("What would you like to do?");
45 println!(" 1. Use default categories (recommended)");
46 println!(" 2. Start with empty categories (add your own later)");
47 println!();
48
49 let choice_str = prompt_string("Select option [1]: ")?;
50 let choice = match choice_str.trim() {
51 "" | "1" => CategoryChoice::UseDefaults,
52 "2" => CategoryChoice::Empty,
53 _ => CategoryChoice::UseDefaults,
54 };
55
56 match choice {
57 CategoryChoice::UseDefaults => {
58 println!();
59 println!("Default categories will be created.");
60 }
61 CategoryChoice::Empty => {
62 println!();
63 println!("Starting with empty categories.");
64 println!("Use 'envelope category create' to add categories later.");
65 }
66 CategoryChoice::Customize => {
67 println!();
69 println!("Category customization will be available in a future update.");
70 println!("Using default categories for now.");
71 }
72 }
73
74 Ok(CategoriesSetupResult { choice })
75 }
76}
77
78fn prompt_string(prompt: &str) -> EnvelopeResult<String> {
80 print!("{}", prompt);
81 io::stdout().flush()?;
82
83 let mut input = String::new();
84 io::stdin().read_line(&mut input)?;
85
86 Ok(input.trim().to_string())
87}