Skip to content

Commit e1a59b4

Browse files
committed
fix(interactive): clear terminal between screens
1 parent 704a161 commit e1a59b4

File tree

7 files changed

+111
-40
lines changed

7 files changed

+111
-40
lines changed

src-tauri/src/cli/interactive/config.rs

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,14 @@ use crate::cli::i18n::texts;
66
use crate::cli::ui::{error, highlight, info, success};
77
use crate::config::get_app_config_path;
88
use crate::error::AppError;
9-
use crate::services::ProviderService;
109
use crate::services::ConfigService;
10+
use crate::services::ProviderService;
1111

12-
use super::utils::{get_state, pause};
12+
use super::utils::{clear_screen, get_state, pause};
1313

1414
pub fn manage_config_menu(app_type: &AppType) -> Result<(), AppError> {
1515
loop {
16+
clear_screen();
1617
println!("\n{}", highlight(texts::config_management()));
1718
println!("{}", "─".repeat(60));
1819

@@ -67,6 +68,7 @@ pub fn manage_config_menu(app_type: &AppType) -> Result<(), AppError> {
6768
}
6869

6970
fn edit_common_config_snippet_interactive(app_type: &AppType) -> Result<(), AppError> {
71+
clear_screen();
7072
println!(
7173
"\n{}",
7274
highlight(
@@ -95,7 +97,11 @@ fn edit_common_config_snippet_interactive(app_type: &AppType) -> Result<(), AppE
9597
loop {
9698
println!(
9799
"\n{}",
98-
info(&format!("{} ({})", texts::opening_external_editor(), field_name))
100+
info(&format!(
101+
"{} ({})",
102+
texts::opening_external_editor(),
103+
field_name
104+
))
99105
);
100106

101107
let edited = match open_external_editor(&initial) {
@@ -119,7 +125,10 @@ fn edit_common_config_snippet_interactive(app_type: &AppType) -> Result<(), AppE
119125
let value: serde_json::Value = match serde_json::from_str(&edited) {
120126
Ok(v) => v,
121127
Err(e) => {
122-
println!("\n{}", error(&format!("{}: {}", texts::invalid_json_syntax(), e)));
128+
println!(
129+
"\n{}",
130+
error(&format!("{}: {}", texts::invalid_json_syntax(), e))
131+
);
123132
if !retry_prompt()? {
124133
return Ok(());
125134
}
@@ -177,7 +186,10 @@ fn edit_common_config_snippet_interactive(app_type: &AppType) -> Result<(), AppE
177186
if apply {
178187
let current_id = ProviderService::current(&state, app_type.clone())?;
179188
if current_id.trim().is_empty() {
180-
println!("{}", info(texts::common_config_snippet_no_current_provider()));
189+
println!(
190+
"{}",
191+
info(texts::common_config_snippet_no_current_provider())
192+
);
181193
} else {
182194
ProviderService::switch(&state, app_type.clone(), &current_id)?;
183195
println!("{}", success(texts::common_config_snippet_applied()));
@@ -203,6 +215,7 @@ fn open_external_editor(initial_content: &str) -> Result<String, AppError> {
203215
}
204216

205217
fn show_config_path_interactive() -> Result<(), AppError> {
218+
clear_screen();
206219
let config_path = get_app_config_path();
207220
let config_dir = config_path.parent().unwrap_or(&config_path);
208221

@@ -235,6 +248,7 @@ fn show_config_path_interactive() -> Result<(), AppError> {
235248
}
236249

237250
fn show_full_config_interactive() -> Result<(), AppError> {
251+
clear_screen();
238252
let config = MultiAppConfig::load()?;
239253
let json = serde_json::to_string_pretty(&config)
240254
.map_err(|e| AppError::Message(format!("Failed to serialize config: {}", e)))?;
@@ -251,6 +265,7 @@ fn show_full_config_interactive() -> Result<(), AppError> {
251265
}
252266

253267
fn export_config_interactive(path: &str) -> Result<(), AppError> {
268+
clear_screen();
254269
let target_path = Path::new(path);
255270

256271
if target_path.exists() {
@@ -274,6 +289,7 @@ fn export_config_interactive(path: &str) -> Result<(), AppError> {
274289
}
275290

276291
fn import_config_interactive(path: &str) -> Result<(), AppError> {
292+
clear_screen();
277293
let file_path = Path::new(path);
278294

279295
if !file_path.exists() {
@@ -301,6 +317,7 @@ fn import_config_interactive(path: &str) -> Result<(), AppError> {
301317
}
302318

303319
fn backup_config_interactive() -> Result<(), AppError> {
320+
clear_screen();
304321
println!(
305322
"\n{}",
306323
highlight(texts::config_backup().trim_start_matches("💾 "))
@@ -342,6 +359,7 @@ fn backup_config_interactive() -> Result<(), AppError> {
342359
}
343360

344361
fn restore_config_interactive() -> Result<(), AppError> {
362+
clear_screen();
345363
println!(
346364
"\n{}",
347365
highlight(texts::config_restore().trim_start_matches("♻️ "))
@@ -415,6 +433,7 @@ fn restore_config_interactive() -> Result<(), AppError> {
415433
}
416434

417435
fn validate_config_interactive() -> Result<(), AppError> {
436+
clear_screen();
418437
let config_path = get_app_config_path();
419438

420439
println!(
@@ -466,6 +485,7 @@ fn validate_config_interactive() -> Result<(), AppError> {
466485
}
467486

468487
fn reset_config_interactive() -> Result<(), AppError> {
488+
clear_screen();
469489
let confirm = Confirm::new(texts::confirm_reset())
470490
.with_default(false)
471491
.prompt()

src-tauri/src/cli/interactive/mcp.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,11 @@ use crate::error::AppError;
88
use crate::services::McpService;
99
use crate::store::AppState;
1010

11-
use super::utils::{get_state, pause};
11+
use super::utils::{clear_screen, get_state, pause};
1212

1313
pub fn manage_mcp_menu(_app_type: &AppType) -> Result<(), AppError> {
1414
loop {
15+
clear_screen();
1516
println!("\n{}", highlight(texts::mcp_management()));
1617
println!("{}", "─".repeat(60));
1718

@@ -77,6 +78,7 @@ pub fn manage_mcp_menu(_app_type: &AppType) -> Result<(), AppError> {
7778
}
7879

7980
fn mcp_enable_server_interactive(state: &AppState) -> Result<(), AppError> {
81+
clear_screen();
8082
let servers = McpService::get_all_servers(state)?;
8183
if servers.is_empty() {
8284
println!("\n{}", info(texts::no_mcp_servers()));
@@ -124,6 +126,7 @@ fn mcp_enable_server_interactive(state: &AppState) -> Result<(), AppError> {
124126
}
125127

126128
fn mcp_disable_server_interactive(state: &AppState) -> Result<(), AppError> {
129+
clear_screen();
127130
let servers = McpService::get_all_servers(state)?;
128131
if servers.is_empty() {
129132
println!("\n{}", info(texts::no_mcp_servers()));
@@ -171,6 +174,7 @@ fn mcp_disable_server_interactive(state: &AppState) -> Result<(), AppError> {
171174
}
172175

173176
fn mcp_delete_server_interactive(state: &AppState) -> Result<(), AppError> {
177+
clear_screen();
174178
let servers = McpService::get_all_servers(state)?;
175179
if servers.is_empty() {
176180
println!("\n{}", info(texts::no_servers_to_delete()));
@@ -211,6 +215,7 @@ fn mcp_delete_server_interactive(state: &AppState) -> Result<(), AppError> {
211215
}
212216

213217
fn mcp_import_servers_interactive(state: &AppState) -> Result<(), AppError> {
218+
clear_screen();
214219
let mut total = 0;
215220
total += McpService::import_from_claude(state)?;
216221
total += McpService::import_from_codex(state)?;
@@ -222,6 +227,7 @@ fn mcp_import_servers_interactive(state: &AppState) -> Result<(), AppError> {
222227
}
223228

224229
fn mcp_validate_command_interactive() -> Result<(), AppError> {
230+
clear_screen();
225231
let command = Text::new(texts::enter_command_to_validate())
226232
.prompt()
227233
.map_err(|e| AppError::Message(format!("Input failed: {}", e)))?;

src-tauri/src/cli/interactive/mod.rs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,15 @@ use crate::cli::ui::{error, highlight, info, success};
1313
use crate::error::AppError;
1414
use crate::services::{McpService, PromptService, ProviderService};
1515

16-
use utils::pause;
16+
use utils::{clear_screen, pause};
1717

1818
pub fn run(app: Option<AppType>) -> Result<(), AppError> {
1919
let mut app_type = app.unwrap_or(AppType::Claude);
2020

21-
print_welcome(&app_type);
22-
2321
loop {
22+
clear_screen();
23+
print_welcome(&app_type);
24+
2425
match show_main_menu(&app_type)? {
2526
MainMenuChoice::ManageProviders => {
2627
if let Err(e) = provider::manage_providers_menu(&app_type) {
@@ -55,7 +56,6 @@ pub fn run(app: Option<AppType>) -> Result<(), AppError> {
5556
MainMenuChoice::SwitchApp => {
5657
if let Ok(new_app) = select_app() {
5758
app_type = new_app;
58-
print_welcome(&app_type);
5959
}
6060
}
6161
MainMenuChoice::Settings => {
@@ -65,7 +65,8 @@ pub fn run(app: Option<AppType>) -> Result<(), AppError> {
6565
}
6666
}
6767
MainMenuChoice::Exit => {
68-
println!("\n{}", success(texts::goodbye()));
68+
clear_screen();
69+
println!("{}\n", success(texts::goodbye()));
6970
break;
7071
}
7172
}

src-tauri/src/cli/interactive/prompts.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,10 +7,11 @@ use crate::error::AppError;
77
use crate::services::PromptService;
88
use crate::store::AppState;
99

10-
use super::utils::{get_state, pause};
10+
use super::utils::{clear_screen, get_state, pause};
1111

1212
pub fn manage_prompts_menu(app_type: &AppType) -> Result<(), AppError> {
1313
loop {
14+
clear_screen();
1415
println!("\n{}", highlight(texts::prompts_management()));
1516
println!("{}", "─".repeat(60));
1617

@@ -83,6 +84,7 @@ fn view_current_prompt_interactive(
8384
_app_type: &AppType,
8485
prompts: &std::collections::HashMap<String, crate::prompt::Prompt>,
8586
) -> Result<(), AppError> {
87+
clear_screen();
8688
let active = prompts.iter().find(|(_, p)| p.enabled);
8789

8890
if let Some((id, prompt)) = active {
@@ -111,6 +113,7 @@ fn view_current_prompt_interactive(
111113
fn show_prompt_content_interactive(
112114
prompts: &std::collections::HashMap<String, crate::prompt::Prompt>,
113115
) -> Result<(), AppError> {
116+
clear_screen();
114117
if prompts.is_empty() {
115118
println!("\n{}", info(texts::no_prompts_available()));
116119
pause();
@@ -151,6 +154,7 @@ fn delete_prompt_interactive(
151154
app_type: &AppType,
152155
prompts: &std::collections::HashMap<String, crate::prompt::Prompt>,
153156
) -> Result<(), AppError> {
157+
clear_screen();
154158
let deletable: Vec<_> = prompts
155159
.iter()
156160
.filter(|(_, p)| !p.enabled)
@@ -198,6 +202,7 @@ fn switch_prompt_interactive(
198202
app_type: &AppType,
199203
prompts: &std::collections::HashMap<String, crate::prompt::Prompt>,
200204
) -> Result<(), AppError> {
205+
clear_screen();
201206
if prompts.is_empty() {
202207
println!("\n{}", info(texts::no_prompts_available()));
203208
pause();

0 commit comments

Comments
 (0)