1use oxicode_vtui::tui::host::{
4 HostAdapter, HostSessionDefaults, NotificationProvider, ThemeProvider, WorkspaceInfoProvider,
5};
6use parking_lot::RwLock;
7use std::sync::Arc;
8
9pub struct OxicodeHostAdapter {
11 pub workspace_name: String,
12 pub workspace_root: Option<std::path::PathBuf>,
13 pub settings: Arc<RwLock<crate::store::settings::Settings>>,
14}
15
16impl OxicodeHostAdapter {
17 pub fn new(
18 workspace_root: Option<std::path::PathBuf>,
19 settings: Arc<RwLock<crate::store::settings::Settings>>,
20 ) -> Self {
21 let workspace_name = workspace_root
22 .as_ref()
23 .and_then(|p| p.file_name())
24 .map(|n| n.to_string_lossy().into_owned())
25 .unwrap_or_else(|| "oxicode".to_string());
26 Self {
27 workspace_name,
28 workspace_root,
29 settings,
30 }
31 }
32}
33
34impl WorkspaceInfoProvider for OxicodeHostAdapter {
35 fn workspace_name(&self) -> String {
36 self.workspace_name.clone()
37 }
38
39 fn workspace_root(&self) -> Option<std::path::PathBuf> {
40 self.workspace_root.clone()
41 }
42}
43
44impl NotificationProvider for OxicodeHostAdapter {
45 fn set_terminal_focused(&self, _focused: bool) {
46 }
48}
49
50impl ThemeProvider for OxicodeHostAdapter {
51 fn available_themes(&self) -> Vec<String> {
52 oxicode_vtui::theme::available_themes()
53 .into_iter()
54 .map(|s| s.to_string())
55 .collect()
56 }
57
58 fn active_theme_name(&self) -> Option<String> {
59 let name = self.settings.read().get_theme_name();
60 if name.is_empty() { None } else { Some(name) }
61 }
62}
63
64impl HostAdapter for OxicodeHostAdapter {
65 fn app_name(&self) -> String {
66 "oxicode".into()
67 }
68
69 fn session_defaults(&self) -> HostSessionDefaults {
70 HostSessionDefaults::default()
71 }
72}
73
74pub fn activate_theme(settings: &crate::store::settings::Settings) {
76 let theme_id = settings.get_theme_name();
77 let theme_id = if theme_id.is_empty() {
78 oxicode_vtui::theme::DEFAULT_THEME_ID
79 } else {
80 theme_id.as_str()
81 };
82 let _ = oxicode_vtui::theme::set_active_theme(theme_id);
83}