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