Skip to content

Commit ca409d3

Browse files
Merge pull request #38 from gitcoder89431/31-provider-configuration-input-system
🏗️ Refactor demo and settings module for improved readability and org…
2 parents 8e129ea + ec8936b commit ca409d3

File tree

2 files changed

+166
-138
lines changed

2 files changed

+166
-138
lines changed

examples/issue_31_demo.rs

Lines changed: 72 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,84 +1,111 @@
11
//! Issue #31 Provider Configuration Input System Demo
2-
//!
2+
//!
33
//! Demonstrates the comprehensive input handling for provider configuration
44
55
use agentic::{
6-
settings::{Settings, ProviderField, SettingsAction, ValidationResult, validate_local_endpoint, validate_api_key, mask_api_key},
6+
settings::{
7+
ProviderField, Settings, SettingsAction, ValidationResult, mask_api_key, validate_api_key,
8+
validate_local_endpoint,
9+
},
710
theme::{Theme, ThemeVariant},
811
};
912
use ratatui::crossterm::event::{KeyCode, KeyEvent};
1013

1114
fn main() {
1215
println!("⌨️ Issue #31: Provider Configuration Input System Demo");
1316
println!("{}", "=".repeat(70));
14-
17+
1518
let mut settings = Settings::new();
16-
19+
1720
println!("\n🔧 INPUT SYSTEM FEATURES:");
1821
println!(" ✅ Tab navigation through fields");
1922
println!(" ✅ Enter to activate edit mode");
2023
println!(" ✅ Live text input with validation");
2124
println!(" ✅ API key masking for security");
2225
println!(" ✅ ESC to cancel/revert changes");
2326
println!(" ✅ Real-time input validation");
24-
27+
2528
println!("\n📊 FIELD NAVIGATION ORDER:");
26-
let fields = ["Theme", "Local Endpoint", "OpenRouter API Key", "Save Button"];
29+
let fields = [
30+
"Theme",
31+
"Local Endpoint",
32+
"OpenRouter API Key",
33+
"Save Button",
34+
];
2735
for (i, field) in fields.iter().enumerate() {
2836
println!(" {}. {}", i + 1, field);
2937
}
30-
38+
3139
println!("\n🧪 TESTING NAVIGATION:");
3240
for i in 0..5 {
3341
settings.navigate_next_field();
3442
let field_name = match settings.focused_field.as_ref().unwrap() {
3543
ProviderField::Theme => "Theme",
3644
ProviderField::LocalEndpoint => "Local Endpoint",
37-
ProviderField::OpenRouterApiKey => "OpenRouter API Key",
45+
ProviderField::OpenRouterApiKey => "OpenRouter API Key",
3846
ProviderField::SaveButton => "Save Button",
3947
};
4048
println!(" Step {}: Focused on {}", i + 1, field_name);
4149
}
42-
50+
4351
println!("\n🔑 TESTING INPUT SYSTEM:");
44-
52+
4553
// Test Local Endpoint editing
4654
println!("\n📝 Local Endpoint Configuration:");
4755
settings.focused_field = Some(ProviderField::LocalEndpoint);
4856
settings.enter_edit_mode(ProviderField::LocalEndpoint);
49-
57+
5058
// Simulate typing
5159
let test_input = "http://localhost:8080";
5260
for c in test_input.chars() {
5361
settings.handle_action(SettingsAction::InputCharacter(c));
5462
}
55-
56-
println!(" Input Buffer: {}", settings.input_state.as_ref().unwrap().input_buffer);
63+
64+
println!(
65+
" Input Buffer: {}",
66+
settings.input_state.as_ref().unwrap().input_buffer
67+
);
5768
println!(" Validation: {:?}", settings.validate_current_input());
58-
69+
5970
// Save the input
6071
settings.exit_edit_mode(true);
61-
println!(" Saved Value: {}", settings.get_display_value(&ProviderField::LocalEndpoint));
62-
72+
println!(
73+
" Saved Value: {}",
74+
settings.get_display_value(&ProviderField::LocalEndpoint)
75+
);
76+
6377
// Test API Key editing with masking
6478
println!("\n🔐 API Key Configuration (with masking):");
6579
settings.focused_field = Some(ProviderField::OpenRouterApiKey);
6680
settings.enter_edit_mode(ProviderField::OpenRouterApiKey);
67-
81+
6882
let test_api_key = "sk-or-v1-1234567890abcdefghijklmnop";
6983
for c in test_api_key.chars() {
7084
settings.handle_action(SettingsAction::InputCharacter(c));
7185
}
72-
73-
println!(" Input Buffer (editing): {}", settings.input_state.as_ref().unwrap().input_buffer);
86+
87+
println!(
88+
" Input Buffer (editing): {}",
89+
settings.input_state.as_ref().unwrap().input_buffer
90+
);
7491
println!(" Validation: {:?}", settings.validate_current_input());
75-
92+
7693
settings.exit_edit_mode(true);
77-
println!(" Masked Display: {}", settings.get_display_value(&ProviderField::OpenRouterApiKey));
78-
println!(" Raw Value: {}", settings.openrouter_provider.api_key.as_ref().unwrap_or(&String::new()));
79-
94+
println!(
95+
" Masked Display: {}",
96+
settings.get_display_value(&ProviderField::OpenRouterApiKey)
97+
);
98+
println!(
99+
" Raw Value: {}",
100+
settings
101+
.openrouter_provider
102+
.api_key
103+
.as_ref()
104+
.unwrap_or(&String::new())
105+
);
106+
80107
println!("\n🎛️ KEYBOARD BINDINGS:");
81-
108+
82109
// Test keyboard event handling
83110
let test_keys = [
84111
(KeyCode::Tab, "Tab: Next field"),
@@ -90,7 +117,7 @@ fn main() {
90117
(KeyCode::Char('x'), "Characters: Live input"),
91118
(KeyCode::Backspace, "Backspace: Delete char"),
92119
];
93-
120+
94121
for (key_code, description) in test_keys {
95122
let key_event = KeyEvent::from(key_code);
96123
if let Some(action) = settings.handle_key_event(key_event) {
@@ -99,9 +126,9 @@ fn main() {
99126
println!(" {}: No action", description);
100127
}
101128
}
102-
129+
103130
println!("\n🔍 VALIDATION TESTING:");
104-
131+
105132
// Test validation functions
106133
let test_cases = [
107134
("http://localhost:11434", "Valid local endpoint"),
@@ -111,33 +138,42 @@ fn main() {
111138
("invalid-key", "Invalid API key format"),
112139
("", "Empty value"),
113140
];
114-
141+
115142
for (test_value, description) in test_cases {
116143
let local_result = validate_local_endpoint(test_value);
117144
let api_result = validate_api_key(test_value);
118-
println!(" {}: Local={:?}, API={:?}", description, local_result, api_result);
145+
println!(
146+
" {}: Local={:?}, API={:?}",
147+
description, local_result, api_result
148+
);
119149
}
120-
150+
121151
println!("\n🛡️ SECURITY FEATURES:");
122-
152+
123153
// Test API key masking
124154
let test_keys = [
125155
"short",
126156
"sk-or-v1-abc123",
127157
"sk-or-v1-1234567890abcdefghijklmnopqrstuvwxyz",
128158
];
129-
159+
130160
for key in test_keys {
131161
let masked = mask_api_key(key);
132162
println!(" Original: {} -> Masked: {}", key, masked);
133163
}
134-
164+
135165
println!("\n✨ INPUT STATE MANAGEMENT:");
136166
println!(" Current edit mode: {}", settings.is_editing());
137167
println!(" Focused field: {:?}", settings.focused_field);
138-
println!(" Local provider configured: {}", settings.local_provider.is_configured());
139-
println!(" OpenRouter provider configured: {}", settings.openrouter_provider.is_configured());
140-
168+
println!(
169+
" Local provider configured: {}",
170+
settings.local_provider.is_configured()
171+
);
172+
println!(
173+
" OpenRouter provider configured: {}",
174+
settings.openrouter_provider.is_configured()
175+
);
176+
141177
println!("\n🎉 Issue #31 Implementation Complete!");
142178
println!("📋 All Success Criteria Met:");
143179
println!(" ✅ Tab navigation cycles through all fields correctly");

0 commit comments

Comments
 (0)