vtcode_core/ui/
tui.rs

1use anyhow::Result;
2use tokio::sync::mpsc;
3
4use crate::config::types::UiSurfacePreference;
5
6mod session;
7mod style;
8mod tui;
9mod types;
10
11pub use style::{convert_style, theme_from_styles};
12pub use types::{
13    InlineCommand, InlineEvent, InlineHandle, InlineHeaderContext, InlineMessageKind,
14    InlineSegment, InlineSession, InlineTextStyle, InlineTheme,
15};
16
17use tui::run_tui;
18
19pub fn spawn_session(
20    theme: InlineTheme,
21    placeholder: Option<String>,
22    surface_preference: UiSurfacePreference,
23    inline_rows: u16,
24) -> Result<InlineSession> {
25    let (command_tx, command_rx) = mpsc::unbounded_channel();
26    let (event_tx, event_rx) = mpsc::unbounded_channel();
27
28    tokio::spawn(async move {
29        if let Err(error) = run_tui(
30            command_rx,
31            event_tx,
32            theme,
33            placeholder,
34            surface_preference,
35            inline_rows,
36        )
37        .await
38        {
39            tracing::error!(%error, "inline session terminated unexpectedly");
40        }
41    });
42
43    Ok(InlineSession {
44        handle: InlineHandle { sender: command_tx },
45        events: event_rx,
46    })
47}