Skip to content

Commit 6eecaa2

Browse files
committed
Fix code formatting to pass CI checks
1 parent 77f104a commit 6eecaa2

File tree

3 files changed

+79
-45
lines changed

3 files changed

+79
-45
lines changed

src/app.rs

Lines changed: 44 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,10 +3,10 @@
33

44
use std::path::PathBuf;
55

6-
use anyhow::{Context, Result, anyhow};
6+
use anyhow::{anyhow, Context, Result};
77
use crossterm::event::{Event, KeyCode, KeyEvent, KeyEventKind, KeyModifiers};
8-
use fuzzy_matcher::FuzzyMatcher;
98
use fuzzy_matcher::skim::SkimMatcherV2;
9+
use fuzzy_matcher::FuzzyMatcher;
1010

1111
use crate::config::ConfigStore;
1212
use crate::model::{Config, Host};
@@ -211,9 +211,13 @@ impl FormState {
211211

212212
pub fn handle_input(&mut self, key: KeyEvent, config: &Config) {
213213
// Check if we're on the bastion field (index 5 in the fields array, or 6 if Add form)
214-
let bastion_field_idx = if matches!(self.kind, FormKind::Add) { 6 } else { 5 };
214+
let bastion_field_idx = if matches!(self.kind, FormKind::Add) {
215+
6
216+
} else {
217+
5
218+
};
215219
let is_bastion_field = self.index == bastion_field_idx;
216-
220+
217221
// Handle bastion dropdown if it's open
218222
if is_bastion_field && self.bastion_dropdown.is_some() {
219223
if let Some(dropdown) = self.bastion_dropdown.as_mut() {
@@ -288,34 +292,50 @@ impl FormState {
288292
}
289293
}
290294
}
291-
295+
292296
match key.code {
293297
KeyCode::Tab => {
294-
let bastion_field_idx = if matches!(self.kind, FormKind::Add) { 6 } else { 5 };
298+
let bastion_field_idx = if matches!(self.kind, FormKind::Add) {
299+
6
300+
} else {
301+
5
302+
};
295303
// Close dropdown when leaving bastion field
296304
if self.index == bastion_field_idx {
297305
self.bastion_dropdown = None;
298306
}
299307
self.next();
300308
}
301309
KeyCode::BackTab => {
302-
let bastion_field_idx = if matches!(self.kind, FormKind::Add) { 6 } else { 5 };
310+
let bastion_field_idx = if matches!(self.kind, FormKind::Add) {
311+
6
312+
} else {
313+
5
314+
};
303315
// Close dropdown when leaving bastion field
304316
if self.index == bastion_field_idx {
305317
self.bastion_dropdown = None;
306318
}
307319
self.prev();
308320
}
309321
KeyCode::Up => {
310-
let bastion_field_idx = if matches!(self.kind, FormKind::Add) { 6 } else { 5 };
322+
let bastion_field_idx = if matches!(self.kind, FormKind::Add) {
323+
6
324+
} else {
325+
5
326+
};
311327
// Close dropdown when leaving bastion field
312328
if self.index == bastion_field_idx {
313329
self.bastion_dropdown = None;
314330
}
315331
self.prev();
316332
}
317333
KeyCode::Down => {
318-
let bastion_field_idx = if matches!(self.kind, FormKind::Add) { 6 } else { 5 };
334+
let bastion_field_idx = if matches!(self.kind, FormKind::Add) {
335+
6
336+
} else {
337+
5
338+
};
319339
// Close dropdown when leaving bastion field
320340
if self.index == bastion_field_idx {
321341
self.bastion_dropdown = None;
@@ -428,7 +448,11 @@ impl FormState {
428448
}
429449

430450
fn open_bastion_dropdown(&mut self, config: &Config) {
431-
let bastion_field_idx = if matches!(self.kind, FormKind::Add) { 6 } else { 5 };
451+
let bastion_field_idx = if matches!(self.kind, FormKind::Add) {
452+
6
453+
} else {
454+
5
455+
};
432456
let mut dropdown = BastionDropdownState::new(config);
433457
// Initialize search filter with current field value
434458
if let Some(f) = self.fields.get(bastion_field_idx) {
@@ -978,7 +1002,11 @@ impl App {
9781002
fn handle_form(&mut self, key: KeyEvent) -> Result<Option<AppAction>> {
9791003
if let Some(form) = self.form.as_mut() {
9801004
// Check if dropdown is open - if so, handle input there first
981-
let bastion_field_idx = if matches!(form.kind, FormKind::Add) { 6 } else { 5 };
1005+
let bastion_field_idx = if matches!(form.kind, FormKind::Add) {
1006+
6
1007+
} else {
1008+
5
1009+
};
9821010
let is_bastion_field = form.index == bastion_field_idx;
9831011
if is_bastion_field && form.bastion_dropdown.is_some() {
9841012
// If Enter is pressed with dropdown open, let handle_input handle it
@@ -988,7 +1016,7 @@ impl App {
9881016
return Ok(None);
9891017
}
9901018
}
991-
1019+
9921020
match key.code {
9931021
KeyCode::Esc => {
9941022
self.mode = Mode::Normal;
@@ -1012,7 +1040,7 @@ impl App {
10121040
}
10131041
}
10141042
}
1015-
},
1043+
}
10161044
_ => {
10171045
form.handle_input(key, &self.config);
10181046
}
@@ -1477,7 +1505,9 @@ mod tests {
14771505
let spec = parse_ssh_spec("host -o StrictHostKeyChecking=no -v").unwrap();
14781506
assert_eq!(spec.address, "host");
14791507
assert!(spec.options.contains(&"-o".to_string()));
1480-
assert!(spec.options.contains(&"StrictHostKeyChecking=no".to_string()));
1508+
assert!(spec
1509+
.options
1510+
.contains(&"StrictHostKeyChecking=no".to_string()));
14811511
assert!(spec.options.contains(&"-v".to_string()));
14821512
assert_eq!(spec.remote_command, None);
14831513

src/main.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,10 +16,10 @@ use config::ConfigStore;
1616
use crossterm::event;
1717
use crossterm::execute;
1818
use crossterm::terminal::{
19-
EnterAlternateScreen, LeaveAlternateScreen, disable_raw_mode, enable_raw_mode,
19+
disable_raw_mode, enable_raw_mode, EnterAlternateScreen, LeaveAlternateScreen,
2020
};
21-
use ratatui::Terminal;
2221
use ratatui::backend::CrosstermBackend;
22+
use ratatui::Terminal;
2323

2424
fn main() {
2525
if let Err(e) = start() {

src/ui.rs

Lines changed: 33 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
// SPDX-License-Identifier: GPL-3.0-or-later
22
// SPDX-FileCopyrightText: 2024 Riccardo Iaconelli <[email protected]>
33

4-
use ratatui::Frame;
54
use ratatui::layout::{Alignment, Constraint, Direction, Layout, Rect};
65
use ratatui::style::{Color, Modifier, Style};
76
use ratatui::text::{Line, Span, Text};
87
use ratatui::widgets::{Block, Borders, Cell, Clear, Paragraph, Row, Table, TableState, Wrap};
8+
use ratatui::Frame;
99

1010
use crate::app::{App, ConfirmKind, FormKind, Mode, StatusKind};
1111
use crate::model::{Config, Host};
@@ -460,10 +460,19 @@ fn render_modal_confirm(frame: &mut Frame, app: &App, confirm: ConfirmKind, them
460460
frame.render_widget(content, area);
461461
}
462462

463-
fn render_modal_form(frame: &mut Frame, form: &crate::app::FormState, config: &Config, theme: Theme) {
463+
fn render_modal_form(
464+
frame: &mut Frame,
465+
form: &crate::app::FormState,
466+
config: &Config,
467+
theme: Theme,
468+
) {
464469
// Increase height if bastion dropdown is open
465470
let base_height = 18;
466-
let dropdown_height = if form.bastion_dropdown.is_some() { 10 } else { 0 };
471+
let dropdown_height = if form.bastion_dropdown.is_some() {
472+
10
473+
} else {
474+
0
475+
};
467476
let area = centered_rect_clamped(75, base_height + dropdown_height, frame.size());
468477
let title = match form.kind {
469478
FormKind::Add => "new host",
@@ -573,20 +582,18 @@ fn render_modal_form(frame: &mut Frame, form: &crate::app::FormState, config: &C
573582
cursor = Some((x, y));
574583
}
575584
line_no += 1;
576-
585+
577586
// Render bastion dropdown if this is the bastion field and dropdown is open
578587
if local_idx == bastion_field_idx && form.bastion_dropdown.is_some() {
579588
if let Some(dropdown) = &form.bastion_dropdown {
580589
rows.push(Line::from(Span::raw("")));
581590
line_no += 1;
582-
rows.push(Line::from(vec![
583-
Span::styled(
584-
" Available hosts:",
585-
Style::default().fg(theme.muted),
586-
),
587-
]));
591+
rows.push(Line::from(vec![Span::styled(
592+
" Available hosts:",
593+
Style::default().fg(theme.muted),
594+
)]));
588595
line_no += 1;
589-
596+
590597
let max_items = 8.min(dropdown.filtered_indices.len());
591598
for i in 0..max_items {
592599
if let Some(host_idx) = dropdown.filtered_indices.get(i) {
@@ -627,32 +634,29 @@ fn render_modal_form(frame: &mut Frame, form: &crate::app::FormState, config: &C
627634
}
628635
}
629636
if dropdown.filtered_indices.len() > max_items {
630-
rows.push(Line::from(vec![
631-
Span::styled(
632-
format!(" ... and {} more", dropdown.filtered_indices.len() - max_items),
633-
Style::default().fg(theme.muted),
637+
rows.push(Line::from(vec![Span::styled(
638+
format!(
639+
" ... and {} more",
640+
dropdown.filtered_indices.len() - max_items
634641
),
635-
]));
642+
Style::default().fg(theme.muted),
643+
)]));
636644
line_no += 1;
637645
}
638-
rows.push(Line::from(vec![
639-
Span::styled(
640-
" (↑↓ to navigate, Enter to select, Esc to close, Space to toggle)",
641-
Style::default().fg(theme.muted),
642-
),
643-
]));
646+
rows.push(Line::from(vec![Span::styled(
647+
" (↑↓ to navigate, Enter to select, Esc to close, Space to toggle)",
648+
Style::default().fg(theme.muted),
649+
)]));
644650
line_no += 1;
645651
}
646652
}
647-
653+
648654
// Show hint when bastion field is active but dropdown is closed
649655
if local_idx == bastion_field_idx && active && form.bastion_dropdown.is_none() {
650-
rows.push(Line::from(vec![
651-
Span::styled(
652-
" (Press Space to browse hosts)",
653-
Style::default().fg(theme.muted),
654-
),
655-
]));
656+
rows.push(Line::from(vec![Span::styled(
657+
" (Press Space to browse hosts)",
658+
Style::default().fg(theme.muted),
659+
)]));
656660
line_no += 1;
657661
}
658662
}

0 commit comments

Comments
 (0)