Skip to main content

fur_cli/commands/status/
mod.rs

1pub mod core;
2pub mod render;
3
4use std::fs;
5use std::path::Path;
6use std::collections::HashMap;
7
8use colored::Colorize;
9use serde_json::{Value, json};
10
11use self::core::*;
12use self::render::*;
13
14use clap::Parser;
15
16
17#[derive(Parser, Debug)]
18pub struct StatusArgs {
19    /// Optional conversation override (used by `fur run` for ephemeral runs)
20    #[clap(skip)]
21    pub conversation_override: Option<String>,
22}
23
24pub fn run_status(args: StatusArgs) {
25    let fur_dir = Path::new(".fur");
26    let index_path = fur_dir.join("index.json");
27
28    if !index_path.exists() {
29        eprintln!("{}", "🚨 .fur/ not found. Run `fur new` first.".red().bold());
30        return;
31    }
32
33    let avatars: Value = serde_json::from_str(
34        &fs::read_to_string(fur_dir.join("avatars.json")).unwrap_or_else(|_| "{}".to_string())
35    ).unwrap_or(json!({}));
36
37    let (index, mut conversation, mut current_msg_id) =
38        load_index_and_conversation(&fur_dir);
39
40    if let Some(ref tid) = args.conversation_override {
41        let convo_path = fur_dir.join("tmp").join(format!("{}.json", tid));
42        if let Ok(content) = fs::read_to_string(&convo_path) {
43            if let Ok(tmp_conversation) = serde_json::from_str::<Value>(&content) {
44                conversation = tmp_conversation;
45            }
46        }
47    }
48
49    let id_to_message = load_conversation_messages(&fur_dir, &conversation);
50
51    if current_msg_id.is_empty() {
52        current_msg_id = first_message_fallback(&conversation);
53    }
54
55    render_status_ui(
56        &index,
57        &conversation,
58        &id_to_message,
59        &current_msg_id,
60        &avatars
61    );
62}
63
64
65fn render_status_ui(
66    index: &Value,
67    conversation: &Value,
68    id_to_message: &HashMap<String, Value>,
69    current_msg_id: &str,
70    avatars: &Value
71) {
72    // Active conversation
73    print_active_conversation(index, conversation);
74
75    // Current message
76    print_current_message(current_msg_id);
77
78    println!("{}", "─────────────────────────────".bright_black());
79
80    // Lineage (ancestors)
81    print_lineage(
82        id_to_message,
83        current_msg_id,
84        avatars
85    );
86
87    println!("{}", "─────────────────────────────".bright_black());
88    println!("{}", "Next messages from here:".bright_magenta().bold());
89
90    // Children + siblings
91    print_next_messages(
92        id_to_message,
93        conversation,
94        current_msg_id,
95        avatars
96    );
97}