()
| 83 | |
| 84 | impl App { |
| 85 | pub fn new() -> anyhow::Result<Self> { |
| 86 | let (event_tx, event_rx) = mpsc::channel(); |
| 87 | let event_tx_input = event_tx.clone(); |
| 88 | let context = Arc::new(AppContext::new()); |
| 89 | let terminal = terminal::init()?; |
| 90 | let mut prompt = Prompt::new(context.clone()) |
| 91 | .with_placeholder("Ask anything... \"Fix a TODO in the codebase\""); |
| 92 | let mut pending_initial_submit = false; |
| 93 | let mut initial_session_id: Option<String> = None; |
| 94 | |
| 95 | if let Ok(dir) = std::env::current_dir() { |
| 96 | *context.directory.write() = dir.display().to_string(); |
| 97 | } |
| 98 | |
| 99 | let base_url = resolve_tui_base_url(); |
| 100 | let api_client = Arc::new(ApiClient::new(base_url.clone())); |
| 101 | context.set_api_client(api_client); |
| 102 | spawn_server_event_listener(event_tx.clone(), base_url); |
| 103 | |
| 104 | if let Ok(agent) = std::env::var("OPENCODE_TUI_AGENT") { |
| 105 | let agent = agent.trim(); |
| 106 | if !agent.is_empty() { |
| 107 | context.set_agent(agent.to_string()); |
| 108 | } |
| 109 | } |
| 110 | if let Ok(model) = std::env::var("OPENCODE_TUI_MODEL") { |
| 111 | let model = model.trim(); |
| 112 | if !model.is_empty() { |
| 113 | context.set_model_selection(model.to_string(), provider_from_model(model)); |
| 114 | context.set_model_variant(None); |
| 115 | } |
| 116 | } |
| 117 | if let Ok(session_id) = std::env::var("OPENCODE_TUI_SESSION") { |
| 118 | let session_id = session_id.trim(); |
| 119 | if !session_id.is_empty() { |
| 120 | initial_session_id = Some(session_id.to_string()); |
| 121 | context.navigate(Route::Session { |
| 122 | session_id: session_id.to_string(), |
| 123 | }); |
| 124 | } |
| 125 | } |
| 126 | if let Ok(initial_prompt) = std::env::var("OPENCODE_TUI_PROMPT") { |
| 127 | let initial_prompt = initial_prompt.trim(); |
| 128 | if !initial_prompt.is_empty() { |
| 129 | prompt.set_input(initial_prompt.to_string()); |
| 130 | pending_initial_submit = true; |
| 131 | } |
| 132 | } |
| 133 | { |
| 134 | let theme = context.theme.read().clone(); |
| 135 | let agent = context.current_agent.read().clone(); |
| 136 | prompt.set_spinner_color(agent_color_from_name(&theme, &agent)); |
| 137 | } |
| 138 | |
| 139 | let tick_rate = Duration::from_millis(TICK_RATE_MS); |
| 140 | thread::spawn(move || { |
| 141 | let mut last_tick = Instant::now(); |
| 142 |
nothing calls this directly
no test coverage detected