rush_sync_server/setup/
setup_toml.rs1use crate::core::prelude::*;
6use std::path::PathBuf;
7use tokio::fs;
8
9const DEFAULT_CONFIG: &str = r#"[general]
11max_messages = 100
12# Typewriter-Effekt: 50ms = 20 Zeichen/Sekunde (empfohlen: 30-100ms)
13typewriter_delay = 5
14input_max_length = 100
15max_history = 30
16# Poll-Rate: 16ms = 60 FPS (empfohlen: 16-33ms, NICHT unter 16!)
17poll_rate = 16
18log_level = "info"
19current_theme = "dark"
20
21[language]
22current = "en"
23
24# =================================================================
25# THEME-DEFINITIONEN (mit integrierten Prompts)
26# =================================================================
27
28[theme.dark]
29input_text = "Black"
30input_bg = "White"
31cursor = "Black"
32output_text = "White"
33output_bg = "Black"
34prompt_text = "/// "
35prompt_color = "Black"
36
37[theme.light]
38input_text = "White"
39input_bg = "Black"
40cursor = "White"
41output_text = "Black"
42output_bg = "White"
43prompt_text = "/// "
44prompt_color = "White"
45
46[theme.green]
47input_text = "LightGreen"
48input_bg = "Black"
49cursor = "LightGreen"
50output_text = "Green"
51output_bg = "Black"
52prompt_text = "$ "
53prompt_color = "LightGreen"
54
55[theme.blue]
56input_text = "White"
57input_bg = "Blue"
58cursor = "White"
59output_text = "LightBlue"
60output_bg = "White"
61prompt_text = "> "
62prompt_color = "White"
63
64# =================================================================
65# HINWEIS: PROMPT IST JETZT TEIL DER THEMES!
66# =================================================================
67#
68# Jedes Theme definiert:
69# - prompt_text (Der Prompt-String z.B. "/// " oder "λ> ")
70# - prompt_color (Die Prompt-Farbe z.B. "LightBlue")
71#
72# Dies löst das macOS Terminal Schwarz-Problem und macht
73# Prompts thematisch konsistent.
74#
75# ENTFERNT: [prompt] Section (war vorher separiert)
76#
77# =================================================================
78# PERFORMANCE-HINWEISE:
79# =================================================================
80# poll_rate:
81# - 16ms = 60 FPS (EMPFOHLEN für flüssiges UI)
82# - 33ms = 30 FPS (akzeptabel für langsamere Systeme)
83# - 1-15ms = NICHT empfohlen (hohe CPU-Last!)
84# - 0ms = CRASH! (Tokio interval panic)
85#
86# typewriter_delay:
87# - 50ms = 20 Zeichen/Sekunde (gut lesbar)
88# - 30ms = 33 Zeichen/Sekunde (schnell)
89# - 100ms = 10 Zeichen/Sekunde (langsam)
90# - 0ms = Typewriter-Effekt deaktiviert
91#
92# current_theme:
93# - "dark" = Dunkles Theme (Standard)
94# - "light" = Helles Theme
95# - "matrix" = Matrix-Style (grün)
96# - "blue" = Blaues Theme
97# - "hacker" = Hacker-Style (grün/rot)
98# - "minimal" = Minimalistisches Theme
99#
100# NEUE FEATURE: THEME-INTEGRIERTE PROMPTS
101# - Jedes Theme hat eigenen prompt_text und prompt_color
102# - Löst macOS Terminal Schwarz-Problem
103# - Thematisch konsistente Prompts
104# ================================================================="#;
105
106pub async fn ensure_config_exists() -> Result<PathBuf> {
107 let exe_path = std::env::current_exe().map_err(AppError::Io)?;
108 let base_dir = exe_path
109 .parent()
110 .ok_or_else(|| AppError::Validation(get_translation("system.config.dir_error", &[])))?;
111
112 let config_dir = base_dir.join(".rss");
113 if !config_dir.exists() {
114 fs::create_dir_all(&config_dir)
115 .await
116 .map_err(AppError::Io)?;
117 log::debug!(
118 "{}",
119 get_translation(
120 "system.config.dir_created",
121 &[&config_dir.display().to_string()]
122 )
123 );
124 }
125
126 let config_path = config_dir.join("rush.toml");
127 if !config_path.exists() {
128 fs::write(&config_path, DEFAULT_CONFIG)
129 .await
130 .map_err(AppError::Io)?;
131
132 log::info!(
134 "{}",
135 get_translation(
136 "system.config.file_created",
137 &[&config_path.display().to_string()]
138 )
139 );
140
141 log::info!("💡 Tipp: Für optimale Performance, behalte poll_rate >= 16ms");
143 log::info!(
144 "✨ NEU: Prompt ist jetzt Teil der Themes! Jedes Theme hat eigenen Prompt-Style."
145 );
146 }
147
148 Ok(config_path)
149}
150
151pub fn get_config_paths() -> Vec<PathBuf> {
152 let mut paths = Vec::new();
153 if let Ok(exe_path) = std::env::current_exe() {
154 if let Some(base_dir) = exe_path.parent() {
155 paths.push(base_dir.join(".rss/rush.toml"));
156 paths.push(base_dir.join("rush.toml"));
157 paths.push(base_dir.join("config/rush.toml"));
158 }
159 }
160 #[cfg(debug_assertions)]
161 {
162 paths.push(PathBuf::from("rush.toml"));
163 paths.push(PathBuf::from("src/rush.toml"));
164 }
165 paths
166}