Skip to content

Commit ac24885

Browse files
committed
fix: resolve clippy warnings in cortex-tui crate
- key_utils.rs: Use if expression for late init pattern - consts.rs: Fix doc list item indentation - rendering.rs: Remove unnecessary if branches with identical blocks - action_bar.rs: Consolidate identical if branches - backtrack_overlay.rs: Use clamp() instead of min().max() - scrollable_dropdown.rs: Use clamp() instead of max().min() - export.rs: Rename from_str to parse to avoid trait conflict - login.rs: Use vec![] macro instead of push after init - state.rs: Box large enum variant to reduce size - methods.rs: Update to use Box::new for InteractiveState - runner.rs: Collapse nested if let statements - actions.rs: Use strip_prefix instead of starts_with + slice - core.rs: Remove redundant if condition with identical branches - input.rs: Collapse nested if, remove needless return statements
1 parent 6281ee1 commit ac24885

14 files changed

Lines changed: 59 additions & 75 deletions

File tree

src/cortex-tui/src/actions/key_utils.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,9 @@ use crossterm::event::{KeyCode, KeyEvent, KeyModifiers};
1414
pub fn parse_key_string(s: &str) -> Option<KeyEvent> {
1515
let parts: Vec<&str> = s.split('+').collect();
1616
let mut modifiers = KeyModifiers::NONE;
17-
let key_part;
1817

19-
if parts.len() == 1 {
20-
key_part = parts[0];
18+
let key_part = if parts.len() == 1 {
19+
parts[0]
2120
} else {
2221
// Parse modifiers
2322
for &part in &parts[..parts.len() - 1] {
@@ -29,8 +28,8 @@ pub fn parse_key_string(s: &str) -> Option<KeyEvent> {
2928
_ => return None,
3029
}
3130
}
32-
key_part = parts.last()?;
33-
}
31+
parts.last()?
32+
};
3433

3534
let code = parse_key_code(key_part)?;
3635
Some(KeyEvent::new(code, modifiers))

src/cortex-tui/src/app/methods.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -559,7 +559,7 @@ impl AppState {
559559

560560
/// Enter interactive mode with the given state.
561561
pub fn enter_interactive_mode(&mut self, state: crate::interactive::InteractiveState) {
562-
self.input_mode = crate::interactive::InputMode::Interactive(state);
562+
self.input_mode = crate::interactive::InputMode::Interactive(Box::new(state));
563563
}
564564

565565
/// Exit interactive mode and return to normal input.

src/cortex-tui/src/interactive/builders/login.rs

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -110,15 +110,13 @@ pub fn build_login_selector(flow: &LoginFlowState) -> InteractiveState {
110110

111111
/// Build interactive state for already logged in confirmation.
112112
pub fn build_already_logged_in_selector() -> InteractiveState {
113-
let mut items = Vec::new();
114-
115-
items.push(InteractiveItem::new("__info__", "You are currently logged in").as_separator());
116-
items.push(InteractiveItem::new("__spacer__", "").as_separator());
117-
items.push(
113+
let items = vec![
114+
InteractiveItem::new("__info__", "You are currently logged in").as_separator(),
115+
InteractiveItem::new("__spacer__", "").as_separator(),
118116
InteractiveItem::new("switch_account", "Login with another account")
119117
.with_description("Sign out and login again"),
120-
);
121-
items.push(InteractiveItem::new("cancel", "Cancel").with_description("Keep current session"));
118+
InteractiveItem::new("cancel", "Cancel").with_description("Keep current session"),
119+
];
122120

123121
InteractiveState::new(
124122
"Already Logged In",

src/cortex-tui/src/interactive/state.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ pub enum InputMode {
1111
#[default]
1212
Normal,
1313
/// Interactive selection mode.
14-
Interactive(InteractiveState),
14+
Interactive(Box<InteractiveState>),
1515
}
1616

1717
impl InputMode {

src/cortex-tui/src/runner/app_runner/runner.rs

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -537,11 +537,11 @@ impl AppRunner {
537537
app_state.org_name = org_name;
538538

539539
// Load last used theme from config
540-
if let Ok(config) = crate::providers::config::CortexConfig::load() {
541-
if let Some(theme) = config.get_last_theme() {
542-
app_state.set_theme(theme);
543-
tracing::debug!("Loaded theme from config: {}", theme);
544-
}
540+
if let Ok(config) = crate::providers::config::CortexConfig::load()
541+
&& let Some(theme) = config.get_last_theme()
542+
{
543+
app_state.set_theme(theme);
544+
tracing::debug!("Loaded theme from config: {}", theme);
545545
}
546546

547547
// ====================================================================
@@ -814,11 +814,11 @@ impl AppRunner {
814814
.with_terminal_size(width, height);
815815

816816
// Load last used theme from config
817-
if let Ok(config) = crate::providers::config::CortexConfig::load() {
818-
if let Some(theme) = config.get_last_theme() {
819-
app_state.set_theme(theme);
820-
tracing::debug!("Loaded theme from config: {}", theme);
821-
}
817+
if let Ok(config) = crate::providers::config::CortexConfig::load()
818+
&& let Some(theme) = config.get_last_theme()
819+
{
820+
app_state.set_theme(theme);
821+
tracing::debug!("Loaded theme from config: {}", theme);
822822
}
823823

824824
// Load session history from cortex-core
@@ -939,11 +939,11 @@ impl AppRunner {
939939
.with_terminal_size(width, height);
940940

941941
// Load last used theme from config
942-
if let Ok(config) = crate::providers::config::CortexConfig::load() {
943-
if let Some(theme) = config.get_last_theme() {
944-
app_state.set_theme(theme);
945-
tracing::debug!("Loaded theme from config: {}", theme);
946-
}
942+
if let Ok(config) = crate::providers::config::CortexConfig::load()
943+
&& let Some(theme) = config.get_last_theme()
944+
{
945+
app_state.set_theme(theme);
946+
tracing::debug!("Loaded theme from config: {}", theme);
947947
}
948948

949949
// Create event loop WITHOUT session bridge

src/cortex-tui/src/runner/event_loop/actions.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ impl EventLoop {
2222
let text = self.app_state.input.submit();
2323
if !text.is_empty() {
2424
// Check for slash commands first
25-
if text.starts_with('/') {
25+
if let Some(stripped) = text.strip_prefix('/') {
2626
// Check if command exists before executing
27-
let cmd_name = text[1..].split_whitespace().next().unwrap_or("");
27+
let cmd_name = stripped.split_whitespace().next().unwrap_or("");
2828
if self.command_executor.registry().exists(cmd_name) {
2929
// Valid command - record and execute
3030
self.app_state.add_to_history(cmd_name);

src/cortex-tui/src/runner/event_loop/core.rs

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -722,13 +722,11 @@ impl EventLoop {
722722
Ok(stored_servers) => {
723723
for stored in stored_servers {
724724
// Convert StoredMcpServer to McpServerInfo for display
725+
// Note: All servers start as Stopped regardless of enabled flag
726+
// They need to be explicitly started to become Running
725727
let server_info = crate::modal::mcp_manager::McpServerInfo {
726728
name: stored.name.clone(),
727-
status: if stored.enabled {
728-
crate::modal::mcp_manager::McpStatus::Stopped
729-
} else {
730-
crate::modal::mcp_manager::McpStatus::Stopped
731-
},
729+
status: crate::modal::mcp_manager::McpStatus::Stopped,
732730
tool_count: 0,
733731
error: None,
734732
requires_auth: stored.api_key_env_var.is_some(),

src/cortex-tui/src/runner/event_loop/input.rs

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -267,10 +267,10 @@ impl EventLoop {
267267
let action = self.action_mapper.get_action(key_event, context);
268268

269269
// Check if autocomplete is visible and handle its navigation
270-
if self.app_state.autocomplete.visible {
271-
if self.handle_autocomplete_key(key_event, terminal).await? {
272-
return Ok(());
273-
}
270+
if self.app_state.autocomplete.visible
271+
&& self.handle_autocomplete_key(key_event, terminal).await?
272+
{
273+
return Ok(());
274274
}
275275

276276
// Handle Copy action specially since it needs terminal access
@@ -352,12 +352,11 @@ impl EventLoop {
352352
// Priority 4: Double Ctrl+C to quit
353353
if self.app_state.handle_ctrl_c() {
354354
self.app_state.set_quit();
355-
return Ok(());
356355
} else {
357356
self.app_state.toasts.info("Press Ctrl+C again to quit");
358357
self.render(terminal)?;
359-
return Ok(());
360358
}
359+
Ok(())
361360
}
362361

363362
/// Handle ESC key with double-tap to quit
@@ -401,12 +400,12 @@ impl EventLoop {
401400
KeyCode::Up => {
402401
self.app_state.autocomplete.select_prev();
403402
self.render(terminal)?;
404-
return Ok(true);
403+
Ok(true)
405404
}
406405
KeyCode::Down => {
407406
self.app_state.autocomplete.select_next();
408407
self.render(terminal)?;
409-
return Ok(true);
408+
Ok(true)
410409
}
411410
KeyCode::Tab => {
412411
// Accept completion with Tab only
@@ -439,7 +438,7 @@ impl EventLoop {
439438
}
440439
self.app_state.autocomplete.hide();
441440
self.render(terminal)?;
442-
return Ok(true);
441+
Ok(true)
443442
}
444443
KeyCode::Enter => {
445444
// Enter completes and immediately executes the command
@@ -468,16 +467,16 @@ impl EventLoop {
468467
}
469468
self.app_state.autocomplete.hide();
470469
// Don't return - fall through to execute the command
471-
return Ok(false);
470+
Ok(false)
472471
}
473472
KeyCode::Esc => {
474473
self.app_state.autocomplete.hide();
475474
self.render(terminal)?;
476-
return Ok(true);
475+
Ok(true)
477476
}
478477
_ => {
479478
// Continue to normal handling, which will update autocomplete
480-
return Ok(false);
479+
Ok(false)
481480
}
482481
}
483482
}

src/cortex-tui/src/session/export.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ impl ExportFormat {
4646
}
4747

4848
/// Parses a format from string.
49-
pub fn from_str(s: &str) -> Option<Self> {
49+
pub fn parse(s: &str) -> Option<Self> {
5050
match s.to_lowercase().as_str() {
5151
"md" | "markdown" => Some(ExportFormat::Markdown),
5252
"json" => Some(ExportFormat::Json),
@@ -383,13 +383,13 @@ mod tests {
383383

384384
#[test]
385385
fn test_format_from_str() {
386-
assert_eq!(ExportFormat::from_str("md"), Some(ExportFormat::Markdown));
386+
assert_eq!(ExportFormat::parse("md"), Some(ExportFormat::Markdown));
387387
assert_eq!(
388-
ExportFormat::from_str("markdown"),
388+
ExportFormat::parse("markdown"),
389389
Some(ExportFormat::Markdown)
390390
);
391-
assert_eq!(ExportFormat::from_str("json"), Some(ExportFormat::Json));
392-
assert_eq!(ExportFormat::from_str("txt"), Some(ExportFormat::Text));
393-
assert_eq!(ExportFormat::from_str("unknown"), None);
391+
assert_eq!(ExportFormat::parse("json"), Some(ExportFormat::Json));
392+
assert_eq!(ExportFormat::parse("txt"), Some(ExportFormat::Text));
393+
assert_eq!(ExportFormat::parse("unknown"), None);
394394
}
395395
}

src/cortex-tui/src/ui/consts.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@ pub const SPINNER_FRAMES: &[char] = &['⠋', '⠙', '⠹', '⠸', '⠼', '⠴',
5454
/// Spinner animation frames for streaming ("breathing" pattern).
5555
/// Ordered by visual weight for smooth animation:
5656
/// - · (point) → ✢ (cross) → ✻ (thin asterisk) → ✽ (heavy asterisk)
57+
///
5758
/// Uses ping-pong pattern for fluid "breathing" effect.
5859
/// Soft/organic variant without pointed star (✶) for smoother curves.
5960
pub const STREAMING_SPINNER_FRAMES: &[char] = &[

0 commit comments

Comments
 (0)