MCPcopy Index your code
hub / github.com/ChrisFeldmeier/OpenCodeRust / new

Method new

crates/opencode-tui/src/app/app.rs:85–238  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

83
84impl 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

Callers

nothing calls this directly

Calls 15

newFunction · 0.85
initFunction · 0.85
resolve_tui_base_urlFunction · 0.85
provider_from_modelFunction · 0.85
agent_color_from_nameFunction · 0.85
with_placeholderMethod · 0.80
set_api_clientMethod · 0.80
is_emptyMethod · 0.80
set_agentMethod · 0.80
set_model_selectionMethod · 0.80
set_model_variantMethod · 0.80

Tested by

no test coverage detected