A Rust CLI for publishing thought records. Designed to work with thought.stream.
at main 2.6 kB view raw
1use anyhow::Result; 2use std::io::{self, Write}; 3use tokio::sync::mpsc; 4 5use crate::client::AtProtoClient; 6use crate::jetstream; 7use crate::tui; 8 9pub async fn run_interactive_mode(client: &AtProtoClient, use_tui: bool) -> Result<()> { 10 if use_tui { 11 run_tui_mode(client).await 12 } else { 13 run_simple_repl(client).await 14 } 15} 16 17async fn run_tui_mode(client: &AtProtoClient) -> Result<()> { 18 // Create channel for messages from jetstream to TUI 19 let (message_tx, message_rx) = mpsc::unbounded_channel(); 20 21 // Get user's DID to filter out our own messages 22 let own_did = client.get_user_did(); 23 24 // Start jetstream listener in background 25 let jetstream_tx = message_tx.clone(); 26 tokio::spawn(async move { 27 if let Err(e) = jetstream::start_jetstream_listener(jetstream_tx, own_did).await { 28 eprintln!("Jetstream listener error: {}", e); 29 } 30 }); 31 32 // Run the TUI 33 tui::run_tui(client, message_rx).await 34} 35 36async fn run_simple_repl(client: &AtProtoClient) -> Result<()> { 37 println!("Entering interactive mode. Type /help for commands."); 38 println!("Enter your thoughts line by line, or use commands starting with '/'"); 39 println!(); 40 41 loop { 42 print!("> "); 43 io::stdout().flush()?; 44 45 let mut input = String::new(); 46 io::stdin().read_line(&mut input)?; 47 48 let input = input.trim(); 49 50 // Skip empty lines 51 if input.is_empty() { 52 continue; 53 } 54 55 // Handle commands 56 if input.starts_with('/') { 57 match input { 58 "/exit" | "/quit" => { 59 println!("Goodbye!"); 60 break; 61 } 62 "/help" => { 63 show_help(); 64 continue; 65 } 66 _ => { 67 println!("Unknown command: {}. Type /help for available commands.", input); 68 continue; 69 } 70 } 71 } 72 73 // Publish the blip 74 match client.publish_blip(input).await { 75 Ok(uri) => { 76 println!("✅ Published: {}", uri); 77 } 78 Err(e) => { 79 println!("❌ Failed to publish: {}", e); 80 } 81 } 82 } 83 84 Ok(()) 85} 86 87fn show_help() { 88 println!("Interactive mode commands:"); 89 println!(" /help - Show this help message"); 90 println!(" /exit, /quit - Exit interactive mode"); 91 println!(); 92 println!("Just type your message and press Enter to publish a blip."); 93}