Skip to main content

host_adapter_integration/
host_adapter_integration.rs

1use std::path::PathBuf;
2
3use vtcode_tui::host::{
4    HostAdapter, HostSessionDefaults, NotificationProvider, ThemeProvider, WorkspaceInfoProvider,
5};
6use vtcode_tui::{InlineTheme, SessionSurface, spawn_session_with_host};
7
8struct DemoHost;
9
10impl WorkspaceInfoProvider for DemoHost {
11    fn workspace_name(&self) -> String {
12        "demo-workspace".to_string()
13    }
14
15    fn workspace_root(&self) -> Option<PathBuf> {
16        std::env::current_dir().ok()
17    }
18}
19
20impl NotificationProvider for DemoHost {
21    fn set_terminal_focused(&self, _focused: bool) {}
22}
23
24impl ThemeProvider for DemoHost {
25    fn available_themes(&self) -> Vec<String> {
26        vec!["default".to_string(), "catppuccin".to_string()]
27    }
28
29    fn active_theme_name(&self) -> Option<String> {
30        Some("default".to_string())
31    }
32}
33
34impl HostAdapter for DemoHost {
35    fn session_defaults(&self) -> HostSessionDefaults {
36        HostSessionDefaults {
37            surface_preference: SessionSurface::Auto,
38            inline_rows: 20,
39            keyboard_protocol: Default::default(),
40        }
41    }
42}
43
44fn main() {
45    let host = DemoHost;
46    let _ = host.workspace_name();
47    let _ = host.workspace_root();
48    let _ = host.available_themes();
49    host.set_terminal_focused(true);
50
51    // Keep this example non-interactive in CI.
52    if std::env::var("VTCODE_TUI_RUN_EXAMPLES").is_ok() {
53        let _ = spawn_session_with_host(InlineTheme::default(), &host);
54    }
55}